public void TestUpdateProductModel() { ContextSeeder.Seed(); var bo = new ProductModelBusinessObject(); var resList = bo.List(); var item = resList.Result.FirstOrDefault(); item.Name = "It's just wine"; var resUpdate = bo.Update(item); var resNotList = bo.ListNotDeleted().Result; Assert.IsTrue(resUpdate.Success && resNotList.First().Name == "It's just wine"); }
public void TestUpdateSameBarCodeProductModel() { ContextSeeder.Seed(); var bo = new ProductModelBusinessObject(); var bra = bo.ListNotDeleted().Result.First(); var catBo = new CategoryBusinessObject(); var cat = catBo.ListNotDeleted().Result.First(); var prodMod = new ProductModel("Vinho Branco", "506-1237-422", "", 4.24, 0.80, Measure.L, bra.Id, cat.Id); prodMod.BarCode = "506-1237-424"; var resUpdate = bo.Update(prodMod); Assert.IsTrue(!resUpdate.Result); }
public ActionResult Update([FromBody] ProductModelViewModel productModel) { var currentRes = _bo.Read(productModel.Id); if (!currentRes.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var current = currentRes.Result; if (current == null) { return(NotFound()); } if (current.Name == productModel.Name && current.BarCode == productModel.BarCode && current.Description == productModel.Description && current.Price.ToString() == productModel.Price && current.Amount.ToString() == productModel.Amount && current.Measure == productModel.Measure && current.BrandId == productModel.BrandId && current.CategoryId == productModel.CategoryId) { return(StatusCode((int)HttpStatusCode.NotModified)); } if (current.Name != productModel.Name) { current.Name = productModel.Name; } if (current.BarCode != productModel.BarCode) { current.BarCode = productModel.BarCode; } if (current.Description != productModel.Description) { current.Description = productModel.Description; } if (current.Price.ToString() != productModel.Price) { current.Price = double.Parse(productModel.Price); } if (current.Amount.ToString() != productModel.Amount) { current.Amount = double.Parse(productModel.Amount); } if (current.Measure != productModel.Measure) { current.Measure = productModel.Measure; } if (current.BrandId != productModel.BrandId) { current.BrandId = productModel.BrandId; } if (current.CategoryId != productModel.CategoryId) { current.CategoryId = productModel.CategoryId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok()); }