public ActionResult Create([Bind(Include = "Name,Quantity,ExpiryDate,Calories")] FoodProducts foodProducts) { ViewBag.Exception = null; string msg = null; if (ModelState.IsValid) { db.FoodProducts.Add(foodProducts); try { db.SaveChanges(); } catch (Exception e) { if (e.InnerException == null) { msg = e.Message; } else { msg = e.InnerException.InnerException.Message; } ViewBag.Exception = msg; return(View(foodProducts)); } return(RedirectToAction("Index")); } return(View(foodProducts)); }
public ActionResult Create([Bind(Include = "AnimalGroupId,EmployeeId,FoodProductsId,TimeForFeeding,FeedingDate,Quantity")] Feedings feedings) { ViewBag.Exception = null; string msg = null; FeedingReminderAccess feedingReminderAccess = new FeedingReminderAccess(); if (ModelState.IsValid) { db.Feedings.Add(feedings); try { FoodProducts foodProducts = db.FoodProducts.Single(c => c.FoodProductsId == feedings.FoodProductsId); foodProducts.Quantity = foodProducts.Quantity - feedings.Quantity ?? default(int); feedingReminderAccess.Create(new FeedingReminder(feedings.FeedingId, feedings.FeedingDate.ToString(), 0)); db.SaveChanges(); } catch (Exception e) { msg = "Unable to create such feeding, we have no more such food products"; ViewBag.Exception = msg; ViewBag.AnimalGroupId = new SelectList(db.AnimalGroups, "AnimalGroupId", "Name"); ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "FirstName"); ViewBag.FoodProductsId = new SelectList(db.FoodProducts, "FoodProductsId", "Name"); return(View(feedings)); } return(RedirectToAction("Index")); } ViewBag.AnimalGroupId = new SelectList(db.AnimalGroups, "AnimalGroupId", "Name", feedings.AnimalGroupId); ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "FirstName", feedings.EmployeeId); ViewBag.FoodProductsId = new SelectList(db.FoodProducts, "FoodProductsId", "Name", feedings.FoodProductsId); return(View(feedings)); }
public ActionResult DeleteConfirmed(int id) { FoodProducts foodProducts = db.FoodProducts.Find(id); db.FoodProducts.Remove(foodProducts); db.SaveChanges(); return(RedirectToAction("Index")); }
static void Main(string[] args) { FoodProducts FoodProd1 = new FoodProducts("FP001", "Meat", 15.99, 200, 100, "Australia"); FoodProducts FoodProd2 = new FoodProducts("FP002", "Bread", 2.99, 150, 50, "Italy"); FoodProd1.Print(); FoodProd2.Print(); Console.ReadLine(); }
// Start is called before the first frame update void Start() { //logic to load game later this.infected = false; this.initialStates(); //Debug.Log(background); this.dayCounter = GetComponent <DayCounter>(); this.foodManager = this.FoodIcon.GetComponent <FoodProducts>(); this.hygieneManager = this.HygieneIcon.GetComponent <HygieneProducts>(); this.preventiveManager = this.PreventiveIcon.GetComponent <PreventiveProducts>(); }
// GET: FoodProducts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FoodProducts foodProducts = db.FoodProducts.Find(id); if (foodProducts == null) { return(HttpNotFound()); } return(View(foodProducts)); }
public ActionResult Edit([Bind(Include = "FoodProductsId,Name,Quantity,ExpiryDate,Calories,RowVersion")] FoodProducts foodProducts) { ViewBag.Exception = null; string msg = null; if (ModelState.IsValid) { var entity = db.FoodProducts.Single(p => p.FoodProductsId == foodProducts.FoodProductsId); if (entity.RowVersion != foodProducts.RowVersion) { TempData["Exception"] = "Entity was modified by another user. Check values and perform edit action again"; return(RedirectToAction("Edit")); } entity.RowVersion++; entity.Name = foodProducts.Name; entity.Quantity = foodProducts.Quantity; entity.ExpiryDate = foodProducts.ExpiryDate; entity.Calories = foodProducts.Calories; db.Entry(entity).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception e) { if (e.InnerException == null) { msg = e.Message; } else { msg = e.InnerException.InnerException.Message; } ViewBag.Exception = msg; return(View(foodProducts)); } return(RedirectToAction("Index")); } return(View(foodProducts)); }
public ActionResult Create([Bind(Include = "SupplierId,FoodProductsId,DeliveryDate,Quantity")] Delivery delivery) { ViewBag.Exception = null; string msg = null; if (ModelState.IsValid) { db.Delivery.Add(delivery); FoodProducts foodProducts = db.FoodProducts.Single(c => c.FoodProductsId == delivery.FoodProductsId); foodProducts.Quantity = foodProducts.Quantity + delivery.Quantity; try { db.SaveChanges(); } catch (Exception e) { if (e.InnerException == null) { msg = e.Message; } else { msg = e.InnerException.InnerException.Message; } ViewBag.Exception = msg; return(View(delivery)); } return(RedirectToAction("Index")); } ViewBag.FoodProductsId = new SelectList(db.FoodProducts, "FoodProductsId", "Name", delivery.FoodProductsId); ViewBag.SupplierId = new SelectList(db.Suppliers, "SupplierId", "CompanyName", delivery.SupplierId); return(View(delivery)); }