コード例 #1
0
        public async Task UpdateAsync(Product product, ProductAddOrUpdateModel updated)
        {
            await product.LoadDataByOptionsAsync(_unitOfWork);

            updated.MapToExisting(product);

            _builder.SetBuildingEntity(product,
                                       _schemes.Query
                                       .Include(x => x.FieldDefenitions)
                                       .Include(x => x.FieldDefenitionGroups)
                                       .Include(x => x.FieldDefenitionGroups.Select(fdg => fdg.FieldDefenitions))
                                       .First(x => x.Id == product.SchemeId),
                                       _productCategories.Query
                                       .Include(x => x.FieldDefenitionGroups)
                                       .Include(x => x.FieldDefenitionGroups.Select(fdg => fdg.FieldDefenitions))
                                       .Include(x => x.FieldDefenitions)
                                       .First(x => x.Id == product.PrimaryCategoryId)
                                       );
            HandleFields(product, updated.Fields);
            product = _builder.GetResult();

            SanitizeAllowedQuantities(product);
            await HandleEshantionsAsync(product, updated.Eshantions.MapToModel());
            await HandleRequiredProductsAsync(product, updated.RequiredProducts.MapToModel());
            await HandleCrossSellingsAsync(product, updated.CrossSellings.MapToModel());
            await HandleUpSellingsAsync(product, updated.UpSellings.MapToModel());
            await HandleAssociatedProductsAsync(product, updated.AssociatedProducts.MapToModel());

            HandleDownLoadFileIfItIs(product);
            HandlePictures(product);
            await _baseBeforeUpdateEntityLogics.ForEachAsync(x =>
                                                             x.ApplyLogicAsync(product, _identityManager.GetCurrentPrincipal()));

            await _products.UpdateAsync(product);
        }
コード例 #2
0
        public async Task <IHttpActionResult> Post(ProductAddOrUpdateModel model)
        {
            var serviceRes = await _productService.Add(new ProductAddRequest()
            {
                RequestOwner = User,
                ProductToAdd = model
            });

            IHttpActionResult res = BadRequest();

            if (serviceRes.Access == ResponseAccess.Granted)
            {
                res = Ok();
            }
            if (serviceRes.Access == ResponseAccess.Deny)
            {
                res = Unauthorized(serviceRes.Message);
            }

            return(res);
        }
コード例 #3
0
        public async Task <IHttpActionResult> Put(Guid id, ProductAddOrUpdateModel model)
        {
            var serviceRes = await _productService.Edit(new ProductEditRequest()
            {
                RequestOwner = User,
                Model        = model,
                Id           = id
            });

            IHttpActionResult res = BadRequest();

            if (serviceRes.Access == ResponseAccess.Granted)
            {
                res = Ok();
            }
            if (serviceRes.Access == ResponseAccess.Deny)
            {
                res = Unauthorized(serviceRes.Message);
            }

            return(res);
        }
コード例 #4
0
 public static Product MapToExisting(this ProductAddOrUpdateModel productVm, Product existing)
 {
     return(Mapper.Map(productVm, existing));
 }
コード例 #5
0
 public static Product MapToModel(this ProductAddOrUpdateModel productVm)
 {
     return(Mapper.Map <Product>(productVm));
 }