public void FindItemPriceByItemCodeTest() { //Arrange string test = "C001"; //Act var result = itemPriceService.FindItemPriceByItemCode(test); //Assert CollectionAssert.AllItemsAreInstancesOfType(result, typeof(ItemPrice)); foreach (ItemPrice element in result) { Assert.AreEqual("C001", element.ItemCode); } }
public List <SupplierViewModel> GetItemSupplier([FromBody] string itemCode) { List <SupplierViewModel> suppliers = new List <SupplierViewModel>(); List <ItemPrice> itemPriceList = itemPriceService.FindItemPriceByItemCode(itemCode); foreach (ItemPrice i in itemPriceList) { suppliers.Add(new SupplierViewModel { Name = i.Supplier.Name, Priority = i.PrioritySequence }); } return(suppliers); }
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 } }); }
public ActionResult Save(EditItemFinalViewModel model) { Console.WriteLine(model); SaveImage(model); string error = ""; Item newItem = new Item(); ItemPrice newItemPrice = new ItemPrice(); if (model.ItemCode != null) { if (itemService.FindItemByItemCode(model.ItemCode) == null) { //for inventory int quantity = 0; //new item newItem.ItemCode = model.ItemCode; newItem.CreatedDateTime = DateTime.Now; newItem.CreatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName()); newItem.Name = model.ItemName; newItem.Description = model.Description; newItem.Uom = model.Uom; newItem.ItemCategory = categoryService.FindItemCategoryByItemCategoryId(model.CategoryId); newItem.Bin = model.Bin; newItem.ReorderLevel = model.ReorderLevel; newItem.ReorderQuantity = model.ReorderQuantity; newItem.Status = new StatusService(context).FindStatusByStatusId(1); try { itemService.Save(newItem, quantity); ProcessItemPrice(model); } catch (Exception e) { error = "Error in item save"; Console.WriteLine("An error occurred in Item Save: '{0}'", e); } } else { //update exiting item Item current = itemService.FindItemByItemCode(model.ItemCode); List <ItemPrice> k = itemPriceService.FindItemPriceByItemCode(current.ItemCode); foreach (ItemPrice i in k) { itemPriceService.DeleteItemPrice(i); } current.Description = model.Description; current.ReorderLevel = model.ReorderLevel; current.ReorderQuantity = model.ReorderQuantity; current.Bin = model.Bin; current.Uom = model.Uom; current.Status = new StatusService(context).FindStatusByStatusId(1); current.UpdatedBy = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName()); current.UpdatedDateTime = DateTime.Now; int quantity = current.Inventory.Quantity; try { itemService.Save(current, quantity); if (!ProcessItemPrice(model)) { //write error case } } catch (Exception e) { error = "Error in item update"; Console.WriteLine("An error occurred in Item Update: '{0}'", e); } } } else { //show erro bcuz no item code error = "Item code comes as null"; } return(RedirectToAction("Index", "Inventory")); //return new JsonResult { }; }