Пример #1
0
        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);
        }
Пример #2
0
        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 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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        public async Task <IBusinessResultValue <GoalNonFulfillmentPercent> > CreateOrUpdateAsync(GoalNonFulfillmentPercent entity)
        {
            var result = new BusinessResultValue <GoalNonFulfillmentPercent>();

            try
            {
                if (validator != null)
                {
                    var result_validate = validator.Validate(entity);
                    if (result_validate.IsValid == false)
                    {
                        result.PopulateValidationErrors(result_validate.Errors);
                        return(result);
                    }
                }

                if (entity.Id == 0) // insert
                {
                    unitOfWork.GoalNonFulfillmentPercentDataService.Insert(entity);
                }
                else
                {
                    var existBranches = await unitOfWork.GoalNonFulfillmentBranchDataService
                                        .GetQuery()
                                        .AsNoTracking()
                                        .Where(x => x.GoalNonFulfillmentPercentId == entity.Id && x.Deleted == false)
                                        .ToListAsync();

                    var deleteBranches = existBranches.Except(entity.GoalNonFulfillmentBranches, x => x.BranchId);
                    foreach (var delBranch in deleteBranches)
                    {
                        delBranch.Deleted = true;
                        entity.GoalNonFulfillmentBranches.Add(delBranch);
                    }
                    unitOfWork.GoalNonFulfillmentPercentDataService.Update(entity);
                }

                await unitOfWork.CommitAsync();

                result.ReturnMessage.Add(MESSAGE_ADD_ENTITY);
                result.ResultValue = entity;
            }
            catch (Exception ex)
            {
                CatchException(ex, result, "");
            }
            return(result);
        }
Пример #11
0
        public async Task <IBusinessResultValue <BranchGoalDTO> > BatchUpdateAsync(BranchGoalDTO batchData)
        {
            var result = new BusinessResultValue <BranchGoalDTO>();

            try
            {
                ValidationResult validationResult = validator.Validate(batchData);
                if (validationResult.IsValid == false)
                {
                    result.PopulateValidationErrors(validationResult.Errors);
                    return(result);
                }
                BranchGoal entity;
                var        lstEntities = new List <BranchGoal>();
                batchData.Items
                .Where(x => (x.Percent != null && x.Percent != 0) || x.Amount != null)
                .ToList()
                .ForEach((item) =>
                {
                    entity = new BranchGoal();

                    if (item.Percent.HasValue)
                    {
                        entity.Percent = item.Percent.Value;
                    }
                    if (item.Amount.HasValue)
                    {
                        entity.Amount = item.Amount.Value;
                    }

                    entity.BranchId = item.BranchId;
                    entity.GoalId   = item.GoalId;

                    if (item.BranchGoalId.HasValue)     // edit
                    {
                        entity.Id = item.BranchGoalId.Value;
                        unitOfWork.BranchGoalDataService.Update(entity);
                    }
                    else
                    {
                        unitOfWork.BranchGoalDataService.Insert(entity);
                    }
                    lstEntities.Add(entity);
                });

                await unitOfWork.CommitAsync();

                batchData.Items.Where(x => (x.Percent != null && x.Percent != 0) || x.Amount != null)
                .ToList()
                .ForEach(vm =>
                {
                    vm.BranchGoalId = lstEntities.FirstOrDefault(x => x.BranchId == vm.BranchId).Id;
                });
                result.ResultValue  = batchData;
                result.ReturnStatus = true;
                result.ReturnMessage.Add(" اطلاعات با موفقیت ثبت گردید");
            }
            catch (Exception ex)
            {
                CatchException(ex, result, "");
            }
            return(result);
        }
Пример #12
0
        public async Task <IBusinessResultValue <Goal> > CreateGoalAsync(Goal goalEntity)
        {
            var result = new BusinessResultValue <Goal>();

            try
            {
                if (goalEntity.GoalTypeId == GoalTypeEnum.Supplier)
                {
                    goalEntity.GoalGoodsCategoryTypeId = GoalGoodsCategoryTypeEnum.Group;
                    goalEntity.GoalGoodsCategory       = new GoalGoodsCategory();
                    goalEntity.GoalGoodsCategory.GoalGoodsCategoryTypeId = GoalGoodsCategoryTypeEnum.Group;
                    goalEntity.GoalGoodsCategory.GoalTypeId = GoalTypeEnum.Supplier;
                    //TODO : it should be reviewed at supplier goal developing time
                    //goalEntity.GoalGoodsCategory.GoodsCollection = goalEntity.GoodsSelectionList;
                    if (goalEntity.Company != null)
                    {
                        goalEntity.GoalGoodsCategory.Name = goalEntity.Company.FaName;
                    }
                }
                else if (goalEntity.GoalGoodsCategoryTypeId >= GoalGoodsCategoryTypeEnum.TotalSalesGoal &&
                         goalEntity.GoalGoodsCategoryTypeId <= GoalGoodsCategoryTypeEnum.AggregationGoal)
                {
                    if (goalEntity.StartDate == DateTime.MinValue)
                    {
                        goalEntity.StartDate = Utilities.ToDateTime(goalEntity.Year, goalEntity.Month).Value;
                        goalEntity.EndDate   = Utilities.ToDateTime(goalEntity.Year, goalEntity.Month, ToDateTimeOptions.EndMonth).Value;
                    }

                    var goalGoodsCategory = await unitOfWork.GoalGoodsCategoryDataService.FirstOrDefaultAsync(where : x => x.GoalGoodsCategoryTypeId == goalEntity.GoalGoodsCategoryTypeId);

                    if (goalGoodsCategory == null)
                    {
                        goalEntity.GoalGoodsCategory = new GoalGoodsCategory();
                        goalEntity.GoalGoodsCategory.GoalGoodsCategoryTypeId = goalEntity.GoalGoodsCategoryTypeId;
                        goalEntity.GoalGoodsCategory.GoalTypeId = GoalTypeEnum.Distributor;
                        goalEntity.GoalGoodsCategory.Name       = goalEntity.GoalGoodsCategoryTypeId.GetEnumDescription <GoalGoodsCategoryTypeEnum>();
                    }
                    else
                    {
                        goalEntity.GoalGoodsCategoryId = goalGoodsCategory.Id;
                    }

                    goalEntity.GoalSteps.Add(new GoalStep()
                    {
                        ComputingTypeId = ComputingTypeEnum.Amount,
                        ComputingValue  = goalEntity.Amount.Value,
                        GoalTypeId      = GoalTypeEnum.Distributor,
                    });
                }

                if (validator != null)
                {
                    ValidationResult results = await validator.ValidateAsync(goalEntity);

                    if (results.IsValid == false)
                    {
                        result.PopulateValidationErrors(results.Errors);
                        return(result);
                    }
                }
                unitOfWork.GoalDataService.Insert(goalEntity);
                await unitOfWork.CommitAsync();

                result.ReturnStatus = true;
                result.ResultValue  = goalEntity;
                result.ReturnMessage.Add(MESSAGE_ADD_ENTITY);
            }
            catch (Exception ex)
            {
                CatchException(ex, result, "");
            }
            return(result);
        }