public ActionResult Create([Bind(Include = "Id,State,Note,Name,DateCreated")] Cow cow) { if (ModelState.IsValid) { cow.DateOfPreviousEvent = DateTime.Now; db.Cows.Add(cow); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cow)); }
public ActionResult Create([Bind(Include = "Id,DateOfBirth,CowId,Name,Note")] Calf calf) { if (ModelState.IsValid) { db.Calves.Add(calf); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CowId = new SelectList(db.Cows, "Id", "Name", calf.CowId); return(View(calf)); }
public ActionResult Create([Bind(Include = "Id,EventType,EventDate,CowId,Name,DateCreated,Note")] Event @event) { if (ModelState.IsValid && @event.CowId != Guid.Empty) { var cow = db.Cows.Where(c => c.Id == @event.CowId).First(); cow.State = (cow.State == Enums.CowStateEnum.PREGNANT) ? Enums.CowStateEnum.OPEN : (Enums.CowStateEnum)(++cow.State); cow.DateOfPreviousEvent = @event.EventDate; db.Entry(cow).State = EntityState.Modified; db.Events.Add(@event); db.SaveChanges(); return(RedirectToAction("Index")); } var cows = db.Cows.Where(c => (int)c.State == (int)@event.EventType).ToList(); ViewBag.CowId = new SelectList(cows, "Id", "Name", @event.CowId); return(View(@event)); }