public void SaveItemPriceTest() { //Arrange Item it = new Item { ItemCode = "BBB", CreatedDateTime = DateTime.Now }; new ItemRepository(context).Save(it); ItemPrice i = new ItemPrice { ItemCode = it.ItemCode, SupplierCode = "ALPA", PrioritySequence = 3, Price = 20.30M, CreatedDateTime = DateTime.Now }; //Act var result = itemPriceService.Save(i); //Arrange Assert.AreEqual("BBB", result.ItemCode); Assert.AreEqual("ALPA", result.SupplierCode); Assert.AreEqual(3, result.PrioritySequence); Assert.AreEqual(20.30M, result.Price); //clean itemPriceRepository.Delete(i); itemRepository.Delete(it); }
public Boolean ProcessItemPrice(EditItemFinalViewModel model) { try { if (model.SupplierName1 != null && model.SupplierName1 != "0" && model.SupplierUnitPrice1 != 0) { ItemPrice p = new ItemPrice(); p.ItemCode = itemService.FindItemByItemCode(model.ItemCode).ItemCode; p.SupplierCode = model.SupplierName1; p.PrioritySequence = 1; p.Price = model.SupplierUnitPrice1; p.CreatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName()); p.CreatedDateTime = DateTime.Now; itemPriceService.Save(p); } if (model.SupplierName2 != null && model.SupplierName2 != "0" && model.SupplierUnitPrice2 != 0) { ItemPrice p = new ItemPrice(); p.ItemCode = itemService.FindItemByItemCode(model.ItemCode).ItemCode; p.SupplierCode = model.SupplierName2; p.PrioritySequence = 2; p.Price = model.SupplierUnitPrice2; p.CreatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName()); p.CreatedDateTime = DateTime.Now; itemPriceService.Save(p); } if (model.SupplierName3 != null && model.SupplierName3 != "0" && model.SupplierUnitPrice3 != 0) { ItemPrice p = new ItemPrice(); p.ItemCode = itemService.FindItemByItemCode(model.ItemCode).ItemCode; p.SupplierCode = model.SupplierName3; p.PrioritySequence = 3; p.Price = model.SupplierUnitPrice3; p.CreatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName()); p.CreatedDateTime = DateTime.Now; itemPriceService.Save(p); } } catch (Exception e) { string error = "error in item price save"; Console.WriteLine("An error occurred in Item Price Save: '{0}'", e); return(false); } return(true); }
public ActionResult UpdateItemPrice(ItemPriceViewModel model) { itempriceService = new ItemPriceService(context); userService = new UserService(context); bool status = false; //find item price object and assign new price ItemPrice itemPrice = itempriceService.FindItemPriceByItemCode(model.ItemCode).Where(x => x.SupplierCode == model.SupplierCode).First(); itemPrice.Price = model.Price; //assign user info into update fields itemPrice.UpdatedDateTime = DateTime.Now; itemPrice.UpdatedBy = userService.FindUserByEmail(CurrentUserName); if (itempriceService.Save(itemPrice) != null) { status = true; } return(new JsonResult { Data = new { status = status } }); }