public ActionResult Update(FeedingStockView model) { if (ModelState.IsValid) { _feed.UpdateFeedingStock(model); return RedirectToAction("GetAllFeedingStock"); } return View(model); }
public void AddFeedingStock(FeedingStockView model) { using (var feedingStock = new FeedingStockRepository()) { var feed = new FeedingStock { FeedingStockId = model.FeedingStockId, ItemName = model.ItemName, ItemPrice = model.ItemPrice, Mass = model.Mass, DateOfPurchase = model.DateOfPurchase, NumberOfItems = model.NumberOfItems, ExpairyDate = model.ExpairyDate, TotalPrice = model.NumberOfItems * model.ItemPrice, TotalMass = model.NumberOfItems * model.Mass }; feedingStock.Insert(feed); } }
public FeedingStockView GetFeedingStockById(int id) { using (var feedingStock = new FeedingStockRepository()) { FeedingStock feed = feedingStock.GetById(id); var feedView = new FeedingStockView(); if (feed != null) { feedView.FeedingStockId = feed.FeedingStockId; feedView.ItemName = feed.ItemName; feedView.ItemPrice = feed.ItemPrice; feedView.Mass = feed.Mass; feedView.DateOfPurchase = feed.DateOfPurchase; feedView.NumberOfItems = feed.NumberOfItems; feedView.ExpairyDate = feed.ExpairyDate; feedView.TotalPrice = feed.TotalPrice; feedView.TotalMass = feed.TotalMass; } return feedView; } }
public void UpdateFeedingStock(FeedingStockView model) { using (var feedingStock = new FeedingStockRepository()) { FeedingStock feed = feedingStock.GetById(model.FeedingStockId); if (feed != null) { feed.FeedingStockId = model.FeedingStockId; feed.ItemName = model.ItemName; feed.NumberOfItems = model.NumberOfItems; feed.Mass = model.Mass; feed.ItemPrice = model.ItemPrice; feed.DateOfPurchase = model.DateOfPurchase; feed.ExpairyDate = model.ExpairyDate; feed.TotalPrice = model.NumberOfItems*model.ItemPrice; feed.TotalMass = model.NumberOfItems*model.Mass; feedingStock.Update(feed); } } }