using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.Validation; using MMDAL.CustomCode.ItemBrand; using MMDAL.DTO.ItemBrand; using MMBLL.ItemBrand; namespace MMBLL.ItemBrand { public class ItemBrandBLL : IItemBrandBLL { private readonly IItemBrandDAL _ItemBrandDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public ItemBrandBLL(IItemBrandDAL IItemBrandDAL, AutoNumber AutoNumber, IValidation validation) { _ItemBrandDAL = IItemBrandDAL; _AutoNumber = AutoNumber; _Validation = validation; } public async Task GetSelectListItemBrand(CriteriaDTO criteriaDTO, LoginDTO LoginDTO) { try { return await _ItemBrandDAL.GetSelectListItemBrand(criteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task SaveItemBrand(ItemBrandDTO itemBrandDTOs, LoginDTO loginDTO) { if(itemBrandDTOs== null) throw new ArgumentNullException(nameof(itemBrandDTOs)); AutoNumberDTO? autoNumberDTOs = null; itemBrandDTOs.ItemBrandModifiedById = loginDTO.UserId; itemBrandDTOs.ItemBrandModifiedOn = DateTime.Now; int count = 1; if(itemBrandDTOs.ItemBrandId == 0) { autoNumberDTOs = await _AutoNumber.GetAutoNumber(count, "ACTIVITYTYPE", loginDTO); itemBrandDTOs.ItemBrandId = autoNumberDTOs.StartNumber; itemBrandDTOs.ItemBrandCreatedById = loginDTO.UserId; itemBrandDTOs.ItemBrandCreatedOn = DateTime.UtcNow; await _ItemBrandDAL.SaveItemBrand(itemBrandDTOs, loginDTO); return $"{SuccessResponse.SaveSuccessMessage} {itemBrandDTOs.ItemBrandName}"; } else { await _ItemBrandDAL.UpdateItemBrand(itemBrandDTOs, loginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {itemBrandDTOs.ItemBrandName}"; } } public async Task GetItemBrand(int itemBrandId, LoginDTO loginDTO) { try { return await _ItemBrandDAL.GetItemBrand(itemBrandId, loginDTO); } catch (Exception) { throw; } } public async Task DeleteItemBrand(int itemBrandId, LoginDTO loginDTO) { try { return await _ItemBrandDAL.DeleteItemBrand(itemBrandId, loginDTO); } catch (Exception) { throw; } } } }