예제 #1
0
        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));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Id,State,DateOfPreviousEvent,Note,Name,DateCreated")] Cow cow)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cow).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cow));
 }
예제 #3
0
 public ActionResult Edit([Bind(Include = "Id,DateOfBirth,CowId,Name,Note")] Calf calf)
 {
     if (ModelState.IsValid)
     {
         db.Entry(calf).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CowId = new SelectList(db.Cows, "Id", "Name", calf.CowId);
     return(View(calf));
 }