Пример #1
0
        public IActionResult Create([FromForm] PriceList priceList)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }

                _priceContext.Add(priceList);
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Пример #2
0
        public IActionResult Add(Price price)
        {
            var result = _priceService.Add(price);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #3
0
        public HttpResponseMessage Create(HttpRequestMessage request, PriceViewModel priceCategoryVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newprice = new Price();
                    newprice.UpdatePrice(priceCategoryVm);

                    var PriceExists = _priceService.GetPrice(newprice.ProductID, newprice.SizeID, newprice.ColorID);
                    if (PriceExists != null && PriceExists.ID > 0)
                    {
                        response = request.CreateResponse(HttpStatusCode.BadGateway, new { ErrorMesage = "Sản phẩm đã được làm giá." });
                    }
                    else
                    {
                        _priceService.Add(newprice);
                        if (newprice.IsPrimary)
                        {
                            var pricePrimary = new Price();
                            pricePrimary = _priceService.GetByPrimary(newprice.ProductID);
                            if (pricePrimary != null && pricePrimary.ProductID > 0)
                            {
                                pricePrimary.IsPrimary = false;
                                _priceService.Update(pricePrimary);
                            }
                        }
                        else
                        {
                            var priceProduct = _priceService.GetPriceProduct(newprice.ProductID);
                            if (priceProduct == null || priceProduct.Count() == 0)
                            {
                                newprice.IsPrimary = true;
                            }
                        }
                        _priceService.SaveChanges();

                        var responseData = Mapper.Map <Price, PriceViewModel>(newprice);
                        response = request.CreateResponse(HttpStatusCode.Created, responseData);
                    }
                }

                return response;
            }));
        }
Пример #4
0
        public IActionResult Create([FromForm] Tariff tariff)
        {
            try
            {
                tariff.PriceLists = JsonSerializer.Deserialize <ICollection <PriceList> >(tariff.Prices);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }

                _tariffContext.Add(tariff);

                foreach (PriceList item in tariff.PriceLists)
                {
                    item.TariffId = tariff.Id;
                    _priceContext.Add(item);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }