public bool UpdateVolunteer(VolunteerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Volunteers .Single(e => e.VolunteerId == model.VolunteerId && e.OwnerId == _userId); entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Email = model.Email; entity.Positions = model.Positions; entity.ShirtSize = model.ShirtSize; entity.Dinner = model.Dinner; entity.Modified = DateTimeOffset.Now; var dinnerEntity = ctx .Dinners .Single(e => e.VolunteerId == model.VolunteerId); dinnerEntity.DinnerChosen = model.Dinner; var positionEntity = ctx .Positions .Single(e => e.VolunteerId == model.VolunteerId); positionEntity.Positions = model.Positions; return(ctx.SaveChanges() >= 1); } }
public ActionResult Edit(int id, VolunteerEdit model) { if (!ModelState.IsValid) { return(View()); } if (model.VolunteerId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateVolunteerService(); if (service.UpdateVolunteer(model)) { TempData["SaveResult"] = "Volunteer was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Volunteer could not be updated."); return(View()); }
// GET: Volunteer with pagination // Multiple actions matched. /* public ActionResult List (int pagenum) * { * var volunteer = db.Volunteers.ToList(); * //get total vol. in the db * int volunteercount = volunteer.Count(); * //set number of job on page * int perpage = 3; * //find number of pages * int maxpage = (int)Math.Ceiling((decimal)volunteercount / perpage) - 1; * if (maxpage < 0) maxpage = 0; * if (pagenum < 0) pagenum = 0; * if (pagenum > maxpage) pagenum = maxpage; * int start = perpage * pagenum; * ViewData["pagenum"] = (int)pagenum; * ViewData["PaginationSummary"] = ""; * if (maxpage > 0) * { * ViewData["PaginationSummary"] = * (pagenum + 1).ToString() + " of " + * (maxpage + 1).ToString(); * } * return View(db.Volunteers.Skip(start).Take(perpage).ToList()); * }*/ public ActionResult New() { //need to give a list of the hospitals so that they can select the one they want var voledit = new VolunteerEdit(); voledit.Hospitals = db.Hospitals.ToList(); return(View(voledit)); }
public ActionResult Edit(int id) { VolunteerEdit voleditview = new VolunteerEdit(); voleditview.Hospitals = db.Hospitals.ToList(); voleditview.Volunteer = db.Volunteers.Include(v => v.Hospital).SingleOrDefault(h => h.VolunteerID == id); //finds all volunteer //GOTO: Views/Job/Edit.cshtml return(View(voleditview)); }
public bool UpdateVolunteer(VolunteerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Volunteers .Single(e => e.VolunteerId == model.VolunteerId); entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.OrgId = model.OrgId; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateVolunteerService(); var detail = service.GetVolunteerById(id); var model = new VolunteerEdit { VolunteerId = detail.VolunteerId, FirstName = detail.FirstName, LastName = detail.LastName, Email = detail.Email, Positions = detail.Positions, ShirtSize = detail.ShirtSize, Dinner = detail.Dinner }; return(View(model)); }
//----------------------------------------------------------------------------------------------- // EDIT: VOLUNTEER public ActionResult Edit(int id) { var service = CreateVolunteerService(); var detail = service.GetVolunteerByIdForEdit(id); var model = new VolunteerEdit { VolunteerId = detail.VolunteerId, UserId = detail.UserId, LoginId = detail.LoginId, FirstName = detail.FirstName, LastName = detail.LastName, PhoneNumber = detail.PhoneNumber, EmailAddress = detail.EmailAddress, Day = detail.Day, Location = detail.Location, CreatedUtc = detail.CreatedUtc, }; return(View(model)); }
//----------------------------------------------------------------------------------------------- public bool UpdateVolunteer(VolunteerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Volunteers .Single(e => e.VolunteerId == model.VolunteerId); entity.VolunteerId = entity.VolunteerId; entity.UserId = model.UserId; entity.LoginId = model.LoginId; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.PhoneNumber = model.PhoneNumber; entity.EmailAddress = model.EmailAddress; entity.Day = model.Day; entity.Location = model.Location; entity.CreatedUtc = model.CreatedUtc; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = new VolunteerService(); var detail = service.GetVolunteerById(id); var model = new VolunteerEdit { OrgId = detail.OrgId, FirstName = detail.FirstName, LastName = detail.LastName }; List <OrganizationListItem> Organizations = (new OrganizationService()).GetOrganizations().ToList(); var query = from b in Organizations select new SelectListItem() { Value = b.OrgId.ToString(), Text = b.Name }; ViewBag.OrganizationId = query.ToList(); return(View(model)); }