示例#1
0
        public async Task <IBusinessResult> BatchDeleteAsync(BranchGoalDTO batchData)
        {
            var result = new BusinessResult();

            try
            {
                var branchBenefitIds = batchData.Items
                                       .Where(x => x.BranchGoalId != null)
                                       .Select(x => x.BranchGoalId.Value)
                                       .ToList();

                var branchBenefits = await unitOfWork.BranchGoalDataService.GetAsync(where : x => branchBenefitIds.Contains(x.Id));

                branchBenefits.ForEach(x => { x.Deleted = true; });

                await unitOfWork.CommitAsync();

                result.ReturnStatus = true;
                result.ReturnMessage.Add(" اطلاعات با موفقیت حذف شد");
            }
            catch (Exception ex)
            {
                CatchException(ex, result, "");
            }
            return(result);
        }
        public async Task <HttpResponseMessage> BatchUpdate(BranchGoalViewModel postedViewModel)
        {
            var           mapper         = GetMapper();
            BranchGoalDTO batchData      = mapper.Map <BranchGoalViewModel, BranchGoalDTO>(postedViewModel);
            var           businessAction = await businessService.BatchUpdateAsync(batchData);

            if (!businessAction.ReturnStatus)
            {
                return(CreateErrorResponse(businessAction));
            }
            postedViewModel.Items.Where(x => (x.Percent != null && x.Percent != 0) || x.Amount != null)
            .ToList()
            .ForEach(vm =>
            {
                vm.BranchGoalId = businessAction.ResultValue.Items.FirstOrDefault(x => x.BranchId == vm.BranchId).BranchGoalId.Value;
            });
            return(Request.CreateResponse(HttpStatusCode.OK, businessAction));
        }
示例#3
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);
        }