public async Task <IBusinessResultValue <PromotionReviewStatusEnum> > ReleaseCEOPromotion(List <MemberPenalty> entities) { var result = new BusinessResultValue <PromotionReviewStatusEnum>(); try { var result_validation = validationRules.Validate(entities); if (result_validation.IsValid == false) { result.PopulateValidationErrors(result_validation.Errors); return(result); } var branchPromotionId = entities.FirstOrDefault().BranchPromotionId; var branchPromotion = await unitOfWork.BranchPromotionDataService.GetQuery() .IncludeFilter(x => x.MemberPromotions.Where(c => c.Deleted == false)) .IncludeFilter(x => x.MemberPromotions.Select(c => c.Details.Where(cf => cf.Deleted == false))) .SingleOrDefaultAsync(x => x.Id == branchPromotionId); if (branchPromotion != null) { foreach (var item in branchPromotion.MemberPromotions) { var penalty = entities.SingleOrDefault(x => x.MemberId == item.MemberId); item.Promotion = penalty?.CEOPromotion ?? 0; } branchPromotion.PromotionReviewStatusId = PromotionReviewStatusEnum.ReleasedByCEO; unitOfWork.BranchPromotionDataService.Update(branchPromotion); entities.ForEach(x => { if (x.Id == 0) { unitOfWork.MemberPenaltyDataService.Insert(x); } else { unitOfWork.MemberPenaltyDataService.Update(x); } }); await unitOfWork.CommitAsync(); result.ResultValue = PromotionReviewStatusEnum.ReleasedByCEO; result.ReturnMessage.Add("اطلاعات تایید و جهت تایید نهایی به رییس مرکز ارسال شد"); } else { result.ReturnStatus = false; result.ReturnMessage.Add("اطلاعات معتبر نمی باشد"); } } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <FulfillmentPercent> > > SubmitDataAsync(List <FulfillmentPercent> lstGoalFulfillment) { var result = new BusinessResultValue <List <FulfillmentPercent> >(); try { lstGoalFulfillment = lstGoalFulfillment .Where(x => x.ManagerFulfillmentPercent != 0 || x.SellerFulfillmentPercent != 0) .ToList(); ValidationResult validatorResult = validator.Validate(lstGoalFulfillment); if (validatorResult.IsValid == false) { result.PopulateValidationErrors(validatorResult.Errors); return(result); } unitOfWork.FulfillmentPercentDataService.InsertFulfillment(lstGoalFulfillment); await unitOfWork.CommitAsync(); result.ReturnStatus = true; result.ResultValue = lstGoalFulfillment; result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <MemberPenalty> > > CreateOrModifyAsync(List <MemberPenalty> entities) { var result = new BusinessResultValue <List <MemberPenalty> >(); try { var result_validation = validationRules.Validate(entities); if (result_validation.IsValid == false) { result.PopulateValidationErrors(result_validation.Errors); return(result); } entities.ForEach(x => { if (x.Id == 0) { unitOfWork.MemberPenaltyDataService.Insert(x); } else { unitOfWork.MemberPenaltyDataService.Update(x); } }); await unitOfWork.CommitAsync(); result.ResultValue = entities; result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <AppMenu> > > LoadApplicationMenu(List <string> lstUrlPermission, bool checkAccess) { var result = new BusinessResultValue <List <AppMenu> >(); try { if (checkAccess) { result.ResultValue = await unitOfWork.AppMenuDataService.GetQuery() .IncludeFilter(x => x.ChildItems.Where(y => lstUrlPermission.Contains(y.Url))) .OrderBy(x => x.OrderId) .Where(x => x.ChildItems.Any(y => lstUrlPermission.Contains(y.Url))) .ToListAsync(); } else { result.ResultValue = await unitOfWork.AppMenuDataService .GetAsync(where : x => x.ParentId == null , includes : x => x.ChildItems , orderBy : x => x.OrderBy(y => y.OrderId)); } result.ReturnStatus = true; } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <PromotionReviewStatusEnum> > DeterminedPromotion(List <MemberPromotion> entities) { var result = new BusinessResultValue <PromotionReviewStatusEnum>(); try { var result_validator = lstValidationRules.Validate(entities); if (!result_validator.IsValid) { result.PopulateValidationErrors(result_validator.Errors); return(result); } entities.ForEach(memshar => { unitOfWork.MemberPromotionDataService.Update(memshar); }); var branchPromotionId = entities.First().BranchPromotionId; var branchPromotion = await unitOfWork.BranchPromotionDataService.GetByIdAsync(branchPromotionId); branchPromotion.PromotionReviewStatusId = PromotionReviewStatusEnum.DeterminedPromotion; unitOfWork.BranchPromotionDataService.Update(branchPromotion); await unitOfWork.CommitAsync(); result.ReturnMessage.Add("پورسانت پرسنل نهایی شد"); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public virtual async Task <IBusinessResultValue <TEntity> > CreateAsync(TEntity entity) { var result = new BusinessResultValue <TEntity>(); try { if (validator != null) { ValidationResult results = await validator.ValidateAsync(entity); if (results.IsValid == false) { result.PopulateValidationErrors(results.Errors); return(await Task <TEntity> .Run(() => result)); } } dataRepository.Insert(entity); await unitOfWork.CommitAsync(); result.ReturnStatus = true; result.ResultValue = entity; result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <QuantityCondition> > AddOrUpdateQuantityConditionAsync(QuantityCondition entity) { var result = new BusinessResultValue <QuantityCondition>(); try { var validatorResult = await validator.ValidateAsync(entity); if (validatorResult.IsValid == false) { result.PopulateValidationErrors(validatorResult.Errors); result.ReturnStatus = false; return(result); } unitOfWork.QuantityConditionDataService.InsertOrUpdate(entity); await unitOfWork.CommitAsync(); result.ResultValue = entity; result.ReturnStatus = true; result.ReturnMessage.Add("ثبت اطلاعات با موفقیت انجام گردید"); } catch (DbEntityValidationException ex) { result.PopulateValidationErrors(ex); result.ReturnStatus = false; Logger.Error(ex, ""); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <BranchReceiptGoalPercentDTO> > CreateOrUpdateAsync(BranchReceiptGoalPercentDTO branchReceiptGoalPercentDTO) { var result = new BusinessResultValue <BranchReceiptGoalPercentDTO>(); try { var result_validator = validator.Validate(branchReceiptGoalPercentDTO); if (result_validator.IsValid == false) { result.PopulateValidationErrors(result_validator.Errors); return(result); } var lst_BranchIds = new List <int>(); lst_BranchIds.AddRange(branchReceiptGoalPercentDTO.Branches); lst_BranchIds.AddRange(branchReceiptGoalPercentDTO.DeselectedBranches); //load exist data var existData = await unitOfWork.BranchReceiptGoalPercentDataService.GetAsync(x => x.GoalId == branchReceiptGoalPercentDTO.GoalId && lst_BranchIds.Contains(x.BranchId)); //delete deselected branches var lst_deselectedBranches = existData.Where(x => branchReceiptGoalPercentDTO.DeselectedBranches.Contains(x.BranchId)).ToList(); lst_deselectedBranches.ForEach(x => { unitOfWork.BranchReceiptGoalPercentDataService.Delete(x); }); //update branches var lst_update_branchePercent = existData.Where(x => branchReceiptGoalPercentDTO.Branches.Contains(x.BranchId)).ToList(); lst_update_branchePercent.ForEach(x => { x.NotReachedPercent = branchReceiptGoalPercentDTO.NotReachedPercent; x.ReachedPercent = branchReceiptGoalPercentDTO.ReachedPercent; unitOfWork.BranchReceiptGoalPercentDataService.Update(x); }); //add new branch percent var lst_insert_branchePercent = branchReceiptGoalPercentDTO.Branches.Where(x => !existData.Any(y => y.BranchId == x)).ToList(); lst_insert_branchePercent.ForEach(x => { BranchReceiptGoalPercent newEntity = new BranchReceiptGoalPercent(); newEntity.BranchId = x; newEntity.GoalId = branchReceiptGoalPercentDTO.GoalId; newEntity.NotReachedPercent = branchReceiptGoalPercentDTO.NotReachedPercent; newEntity.ReachedPercent = branchReceiptGoalPercentDTO.ReachedPercent; unitOfWork.BranchReceiptGoalPercentDataService.Insert(newEntity); }); await unitOfWork.CommitAsync(); result.ResultValue = branchReceiptGoalPercentDTO; result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); result.ReturnStatus = true; } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <OrgStructureShareDTO> > CreateOrgStructureShareDTOAsync(OrgStructureShareDTO personelShareDTO) { var result = new BusinessResultValue <OrgStructureShareDTO>(); try { ValidationResult validationResult = valdiator.Validate(personelShareDTO); if (validationResult.IsValid == false) { result.PopulateValidationErrors(validationResult.Errors); return(result); } personelShareDTO.Items .ForEach(x => { x.BranchId = personelShareDTO.Branch.Id; unitOfWork.OrgStructureShareDataService.InsertOrUpdateOrgStructureShare(x); }); await unitOfWork.CommitAsync(); result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); result.ResultValue = personelShareDTO; } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public virtual async Task <IBusinessResultValue <TEntity> > LoadAsync(Expression <Func <TEntity, bool> > where = null , bool isThrowException = false , params Expression <Func <TEntity, object> >[] includes) { var entity = new BusinessResultValue <TEntity>(); try { entity.ResultValue = await dataRepository.FirstOrDefaultAsync(where, includes : includes); entity.ReturnStatus = true; } catch (Exception ex) { if (!isThrowException) { CatchException(ex, entity, ""); } else { throw ex; } } return(entity); }
public async Task <IBusinessResultValue <PromotionReviewStatusEnum> > ProceedMemberPromotionAsync(PromotionReviewStatusEnum currentStep, PromotionReviewStatusEnum nextStep, int branchId) { var result = new BusinessResultValue <PromotionReviewStatusEnum>(); try { var entity = await unitOfWork.BranchPromotionDataService.GetQuery() .IncludeFilter(x => x.MemberPromotions.Where(y => y.Deleted == false)) .IncludeFilter(x => x.MemberPromotions.Select(y => y.Details.Where(c => c.Deleted == false))) .FirstOrDefaultAsync(x => x.BranchId == branchId && x.PromotionReviewStatusId == currentStep); if (entity != null) { var salesAssigned = entity.MemberPromotions.Sum(x => x.Details.Sum(c => (decimal?)c.SupplierPromotion)) ?? 0; var receiptAssigned = entity.MemberPromotions.Sum(x => x.Details.Sum(c => (decimal?)c.ReceiptPromotion)) ?? 0; var compensatoryAssigned = entity.MemberPromotions.Sum(x => x.Details.Sum(c => (decimal?)c.CompensatoryPromotion)) ?? 0; if (salesAssigned > entity.SupplierPromotion) { result.ReturnMessage.Add("جمع مبلغ پورسانت تامین کننده پرسنل از پورسانت فروش تامین کنندگان مرکز بیشتر میباشد"); result.ReturnStatus = false; } if (receiptAssigned > entity.PrivateReceiptPromotion + entity.TotalReceiptPromotion) { result.ReturnMessage.Add("جمع مبلغ پورسانت وصول پرسنل از پورسانت وصول مرکز بیشتر میباشد"); result.ReturnStatus = false; } if (compensatoryAssigned > entity.CompensatoryPromotion) { result.ReturnMessage.Add("جمع مبلغ پورسانت ترمیمی پرسنل از پورسانت ترمیمی مرکز بیشتر میباشد"); result.ReturnStatus = false; } if (result.ReturnStatus) { entity.PromotionReviewStatusId = nextStep; result.ResultValue = nextStep; unitOfWork.BranchPromotionDataService.Update(entity); await unitOfWork.CommitAsync(); result.ReturnMessage.Add("اطلاعات تایید و ارسال شد"); } } else { result.ReturnStatus = false; result.ReturnMessage.Add("اطلاعات معتبر نمی باشد"); } } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <GoalGoodsCategory> > CreateGoalGoodsCategoryAsync(GoalGoodsCategory goalGoodsCategory, int goalCategorySimilarId) { var result = new BusinessResultValue <GoalGoodsCategory>(); try { if (validator != null) { ValidationResult results = await validator.ValidateAsync(goalGoodsCategory); if (results.IsValid == false) { result.PopulateValidationErrors(results.Errors); return(await Task <GoalGoodsCategory> .Run(() => result)); } } List <Goal> goals = new List <Goal>(); if (goalCategorySimilarId != 0) { var similarEntity = await unitOfWork.GoalGoodsCategoryDataService.GetByIdAsync(goalCategorySimilarId); similarEntity.IsVisible = false; goals = await unitOfWork.GoalDataService .GetQuery() .AsNoTracking() .Where(x => x.IsUsed == false && x.GoalGoodsCategoryId == goalCategorySimilarId) .ToListAsync(); unitOfWork.GoalGoodsCategoryDataService.Update(similarEntity); } unitOfWork.GoalGoodsCategoryDataService.Insert(goalGoodsCategory); foreach (var item in goals) { item.GoalGoodsCategoryId = goalGoodsCategory.Id; unitOfWork.GoalDataService.Update(item); } await unitOfWork.CommitAsync(); result.ReturnStatus = true; result.ResultValue = await unitOfWork.GoalGoodsCategoryDataService.GetGoalGoodsCategoryAsync(goalGoodsCategory.Id); result.ReturnMessage.Add(MESSAGE_ADD_ENTITY); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <int> > AddBatchAsync(List <Invoice> lstData) { var result = new BusinessResultValue <int>(); try { result.ResultValue = await unitOfWork.InvoiceDataService.InsertBulkAsync(lstData); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <int> > > LoadRoleIdsByUserIdAsync(int userId) { var result = new BusinessResultValue <List <int> >(); try { result.ResultValue = await unitOfWork.RoleDataService.GetRoleIdsByUserIdAsync(userId); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <BranchSales> > LoadLatestYearMonthAsync() { var result = new BusinessResultValue <BranchSales>(); try { result.ResultValue = await unitOfWork.BranchSalesDataService.GetLatestYearMonthAsync(); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <BranchSales> > LoadAsync(int branchId, int year, int month) { var result = new BusinessResultValue <BranchSales>(); try { result.ResultValue = await unitOfWork.BranchSalesDataService.FirstOrDefaultAsync(where : x => x.Year == year && x.Month == month && x.BranchId == branchId); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <BranchSales> > > LoadTotalSalesPerBranchAsync(int year, int month) { var result = new BusinessResultValue <List <BranchSales> >(); try { result.ResultValue = await unitOfWork.BranchSalesDataService.GetTotalSalesPerBranchAsync(year, month); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <int> > AddBatchAsync(List <MemberPayroll> lstEntities) { var result = new BusinessResultValue <int>(); try { result.ResultValue = await unitOfWork.MemberPayrollDataService.InsertBulkAsync(lstEntities); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <decimal> > LoadPreviousAggregationValueAync(int month, int year) { var result = new BusinessResultValue <decimal>(); try { result.ResultValue = await unitOfWork.GoalDataService.GetPreviousAggregationValueAsync(month, year); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <BranchReceipt> > > LoadMonthYearListAsync() { var result = new BusinessResultValue <List <BranchReceipt> >(); try { result.ResultValue = await unitOfWork.BranchReceiptDataService.GetMonthYearListAsync(); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <CostCoefficient> > > LoadCoefficientList() { var result = new BusinessResultValue <List <CostCoefficient> >(); try { result.ResultValue = await unitOfWork.CostCoefficientDataService.GetCoefficientList(); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <BranchReceipt> > > LoadBranchReceiptListAsync(int year, int month) { var result = new BusinessResultValue <List <BranchReceipt> >(); try { result.ResultValue = await unitOfWork.BranchReceiptDataService.GetAsync(where : x => x.Year == year && x.Month == month); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <BranchPromotion> > > LoadCompensatoryListAsync(int promotionId) { var result = new BusinessResultValue <List <BranchPromotion> >(); try { result.ResultValue = await unitOfWork.BranchPromotionDataService.GetAsync(c => c.PromotionId == promotionId && c.PromotionReviewStatusId == PromotionReviewStatusEnum.WaitingForCompensatory, includes : c => c.Branch); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public virtual IBusinessResultValue <TEntity> LoadLatestRecord() { var entity = new BusinessResultValue <TEntity>(); try { entity.ResultValue = dataRepository.GetLatestRecord(); entity.ReturnStatus = true; } catch (Exception ex) { CatchException(ex, entity, ""); } return(entity); }
public virtual IBusinessResultValue <TEntity> Load(int entityId, params Expression <Func <TEntity, object> >[] includes) { var entity = new BusinessResultValue <TEntity>(); try { entity.ResultValue = dataRepository.FirstOrDefault(where : ent => ent.Id == entityId); entity.ReturnStatus = true; } catch (Exception ex) { CatchException(ex, entity, ""); } return(entity); }
public async Task <IBusinessResultValue <GoalGoodsCategory> > LoadGoalGoodsCategoryAsync(int goalGoodsCategoryId) { var result = new BusinessResultValue <GoalGoodsCategory>(); try { result.ResultValue = await unitOfWork.GoalGoodsCategoryDataService.GetGoalGoodsCategoryAsync(goalGoodsCategoryId); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <OrgStructureShareDTO> > LoadOrgStructureShareDTOAsync(int branchId) { var result = new BusinessResultValue <OrgStructureShareDTO>(); try { result.ResultValue = await unitOfWork.OrgStructureShareDataService.GetOrgStructureShareDTOAsync(branchId); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public virtual IBusinessResultValue <int> GetCount(Expression <Func <TEntity, bool> > where = null) { IBusinessResultValue <int> resultValue = new BusinessResultValue <int>(); try { resultValue.ResultValue = unitOfWork.GetRepository <TEntity>().GetCount(where); resultValue.ReturnStatus = true; } catch (Exception ex) { CatchException(ex, resultValue, ""); } return(resultValue); }
public async Task <IBusinessResultValue <BranchGoal> > LoadBranchGoalListAsync(params int[] lstGoalIds) { var result = new BusinessResultValue <BranchGoal>(); try { result.ResultValue = await unitOfWork.BranchGoalDataService.FirstOrDefaultAsync(where : x => x.Deleted == false && (lstGoalIds == null || lstGoalIds.Contains(x.GoalId))); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }
public async Task <IBusinessResultValue <List <BranchPromotion> > > LoadListAsync(int promotionId) { var result = new BusinessResultValue <List <BranchPromotion> >(); try { result.ResultValue = await unitOfWork.BranchPromotionDataService.GetAsync(c => c.PromotionId == promotionId, includes : c => c.Branch); } catch (Exception ex) { CatchException(ex, result, ""); } return(result); }