public bool UpdateSignUp(SignUpEdit model) { using (var ctx = new ApplicationDbContext()) { var signups = ctx .SignUps .Where(s => s.SignUpId == model.SignUpId) .ToList(); var entity = ctx .Events .Single(e => e.EventId == model.EventId); entity.EventId = model.EventId; entity.UserId = _userId; entity.Day = model.Day; entity.ServiceDate = model.ServiceDate; entity.Location = model.Location; entity.RequiredVolunteers = model.RequiredVolunteers; entity.RemainingNeed = entity.RequiredVolunteers - signups.Count(); return(ctx.SaveChanges() == 1); } }
// EDIT: SIGNUP public ActionResult Edit(int id) { var service = CreateSignUpService(); var detail = service.GetSignUpById(id); var model = new SignUpEdit { EventId = detail.EventId, VolunteerId = detail.VolunteerId, SignUpId = detail.SignUpId, LoginId = detail.LoginId, FirstName = detail.FirstName, LastName = detail.LastName, UserId = detail.UserId, Day = detail.Day, ServiceDate = detail.ServiceDate, Location = detail.Location, }; return(View(model)); }
public ActionResult Edit(int id, SignUpEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SignUpId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateSignUpService(); if (service.UpdateSignUp(model)) { TempData["SaveResult"] = "Your Changes have been saved ."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Changes could not be saved."); return(View(model)); }