コード例 #1
0
        public bool TryApplyAnUpdate(int sellerId, int productTypeId, out ICollection <string> errors)
        {
            errors = new List <string>();

            //check product type existence
            ProductType productType = productTypeRepository.GetBy(productTypeId);

            if (productType == null)
            {
                errors.Add("Could not found product type");
            }
            else if (productType.Status != ProductTypeStatus.Active)            //check product type status
            {
                errors.Add("Product type is unavailable at the moment");
            }

            ProductTypeUpdateRequest updateRequest
                = productTypeRepository.GetUpdateRequest(sellerId, productTypeId);

            if (!errors.Any())
            {
                productType.ApplyUpdate(updateRequest);
                productType.UpdateRequests.Remove(updateRequest);
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public IActionResult Edit(ProductTypeUpdateRequest request)
        {
            HttpClient httpclient = new HttpClient();
            var        result     = httpclient.PutAsJsonAsync(uri, request).Result;

            return(RedirectToAction("Edit", new { categoryId = request.Id }));
        }
コード例 #3
0
        public bool TryRequestAnUpdate(int sellerId, ProductTypeUpdateRequest updateRequest, out ICollection <string> errors)
        {
            errors = new List <string>();

            //check seller existence
            Seller seller = sellerRepository.GetBy(sellerId);

            if (seller == null)
            {
                errors.Add("Could not found seller");
            }
            else if (seller.Status != SellerStatus.Active)            //check seller status
            {
                errors.Add("Seller is unactive");
            }

            //check product type existence
            ProductType productType = productTypeRepository.GetBy(updateRequest.ProductTypeId);

            if (productType == null)
            {
                errors.Add("Could not found product type");
            }
            else if (productType.Status != ProductTypeStatus.Active)            //check product type status
            {
                errors.Add("Product type is unavailable at the moment");
            }

            //check category existence
            if (updateRequest.CategoryId != null)
            {
                Category category = categoryRepository.GetBy((int)updateRequest.CategoryId);
                if (category == null)
                {
                    errors.Add("Could not found category");
                }
                else if (category.ChildCategories.Any())                //check category have any childs or not
                {
                    errors.Add("Category must have no childs");
                }
            }

            if (string.IsNullOrWhiteSpace(updateRequest.Name))
            {
                errors.Add("Product type name is required");
            }

            if (string.IsNullOrWhiteSpace(updateRequest.Descriptions))
            {
                errors.Add("Update descriptions is required");
            }

            if (!errors.Any())
            {
                seller.RequestUpdateForProductType(updateRequest);
                return(true);
            }
            return(false);
        }
コード例 #4
0
 public static ProductTypeUpdateRequestAddModel ConvertToAddModel(this ProductTypeUpdateRequest updateRequest)
 => new ProductTypeUpdateRequestAddModel
 {
     CategoryId    = updateRequest.CategoryId,
     Descriptions  = updateRequest.Descriptions,
     Name          = updateRequest.Name,
     ProductTypeId = updateRequest.ProductTypeId
 };
コード例 #5
0
        public void RequestUpdateForProductType(ProductTypeUpdateRequest updateRequest)
        {
            ProductTypeUpdateRequest oldUpdateRequest = ProductTypeUpdateRequests.FirstOrDefault(p => p.ProductTypeId == updateRequest.ProductTypeId);

            if (oldUpdateRequest != null)
            {
                ProductTypeUpdateRequests.Remove(oldUpdateRequest);
            }
            ProductTypeUpdateRequests.Add(updateRequest);
        }
コード例 #6
0
        public async Task <int> Update(ProductTypeUpdateRequest request)
        {
            var temp = await _context.ProductTypes.FindAsync(request.Id);

            if (temp == null)
            {
                return(-1);
            }
            temp.Name = request.Name;
            return(await _context.SaveChangesAsync());
        }
コード例 #7
0
 public static ProductTypeUpdateRequestView ConvertToView(this ProductTypeUpdateRequest updateRequest)
 => new ProductTypeUpdateRequestView
 {
     Descriptions    = updateRequest.Descriptions,
     CategoryId      = updateRequest.CategoryId?.ToString(),
     CategoryName    = updateRequest.Category?.Name,
     Name            = updateRequest.Name,
     ProductTypeId   = updateRequest.ProductTypeId.ToString(),
     ProductTypeName = updateRequest.ProductType.Name,
     SellerId        = updateRequest.SellerId.ToString(),
     SellerName      = updateRequest.Seller.Name
 };
コード例 #8
0
        public virtual IHttpActionResult Update(ProductTypeUpdateRequest request)
        {
            var entity = new ProductType
            {
                Id = request.Id,
            };
            var result = _productTypeService.Update(entity);

            if (result > 0)
            {
                return(Succeed(new ProductTypeUpdateResponse
                {
                    Id = entity.Id
                }, "新增成功"));
            }
            else
            {
                return(Fail("新增失败"));
            }
        }
コード例 #9
0
 public void CancelProductTypeUpdateRequest(ProductTypeUpdateRequest updateRequest) => ProductTypeUpdateRequests.Remove(updateRequest);
コード例 #10
0
        public async Task <IActionResult> UpdateProductType(ProductTypeUpdateRequest request)
        {
            var result = await _productTypeService.Update(request);

            return(Ok(result));
        }