コード例 #1
0
        private bool IsDuplicate(BranchGoal branchGoal)
        {
            var dbBranchBenefit = unitOfWork.BranchGoalDataService.GetQuery()
                                  .AsNoTracking()
                                  .Where(
                x => x.Deleted == false &&
                x.BranchId == branchGoal.BranchId &&
                x.Percent == branchGoal.Percent)
                                  .Include(x => x.Goal)
                                  .AsEnumerable()
                                  .FirstOrDefault();

            if (dbBranchBenefit == null)
            {
                return(false);
            }
            return(!(dbBranchBenefit.Id == branchGoal.Id));
        }
コード例 #2
0
ファイル: BranchGoalBS.cs プロジェクト: toorani/Neutrino
        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);
        }