Ejemplo n.º 1
0
        public HttpResponseMessage Create(HttpRequestMessage request, ProductQuantityViewModel productQuantityVm)
        {
            if (ModelState.IsValid)
            {
                var newQuantity            = new ProductQuantity();
                var identity               = (ClaimsIdentity)User.Identity;
                IEnumerable <Claim> claims = identity.Claims;
                try
                {
                    if (_productQuantityService.CheckExist(productQuantityVm.ProductId, productQuantityVm.SizeId, productQuantityVm.ColorId))
                    {
                        return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Màu sắc kích thước cho sản phẩm này đã tồn tại"));
                    }
                    else
                    {
                        newQuantity.UpdateProductQuantity(productQuantityVm);

                        _productQuantityService.Add(newQuantity);
                        _productQuantityService.Save();
                        Log log = new Log()
                        {
                            AppUserId = claims.FirstOrDefault().Value,
                            Content   = Notification.CREATE_PRODUCTQUANTITY,
                            Created   = DateTime.Now
                        };
                        _logService.Create(log);
                        _logService.Save();
                        return(request.CreateResponse(HttpStatusCode.OK, productQuantityVm));
                    }
                }
                catch (Exception dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }