Пример #1
0
 private List <GoodsViewModel> GetGoodsSelectedList(GoalGoodsCategory entity)
 {
     if (entity != null)
     {
         //TODO : will be back it
         //var config = new MapperConfiguration(cfg => { cfg.AddProfile(new GoalGoodsCategoryMapperProfile()); });
         //var mapper = config.CreateMapper();
         //GoalGoodsCategoryViewModel viewModel = mapper.Map<GoalGoodsCategoryViewModel>(entity);
         //return viewModel.GoodsCollection;
     }
     return(new List <GoodsViewModel>());
 }
        public virtual async Task <HttpResponseMessage> Add(GoalGoodsCategoryViewModel postedViewModel)
        {
            var mapper = GetMapper();
            GoalGoodsCategory entityCreating = mapper.Map <GoalGoodsCategory>(postedViewModel);
            IBusinessResultValue <GoalGoodsCategory> entityCreated = await businessService.CreateGoalGoodsCategoryAsync(entityCreating, postedViewModel.GoalCategorySimilarId);

            if (entityCreated.ReturnStatus == false)
            {
                return(CreateErrorResponse(entityCreated));
            }

            postedViewModel = mapper.Map <GoalGoodsCategoryViewModel>(entityCreated.ResultValue);
            return(CreateViewModelResponse(postedViewModel, entityCreated));
        }
Пример #3
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);
        }