public ActionResult Edit(int id) { ScheduleManager sessMgr = new ScheduleManager(); Session sessionDTO = sessMgr.GetSession(id); if (sessionDTO == null) { return(HttpNotFound("Invalid Id provided")); } //Convert to View Model SessionManager_CreateEditViewModel sessionViewModel = new SessionManager_CreateEditViewModel(sessionDTO); return(View(sessionViewModel)); }
public ActionResult Create(SessionManager_CreateEditViewModel newSessionVM) { //Validate password and username are defined if (string.IsNullOrWhiteSpace(newSessionVM.Title) == true) { ModelState.AddModelError("", "Title is required"); return(View(newSessionVM)); } //Create a user dto template Session userTemplate = new wsad_app.Models.DataAccess.Session() { Title = newSessionVM.Title, Description = newSessionVM.Description, Building = newSessionVM.Building, Room = newSessionVM.Room, TotalSeats = newSessionVM.TotalSeats, AvailableSeats = newSessionVM.AvailableSeats, DateAndTime = newSessionVM.DateAndTime }; //Create a user manager ScheduleManager sessMngr = new ScheduleManager(); //Send new user into manager try { sessMngr.AddSession(userTemplate); } catch (Exception ex) { ModelState.AddModelError("", "Error occured while saving user to database. " + ex.Message); Debug.WriteLine(ex.Message); return(View(newSessionVM)); } //Redirect to Index return(RedirectToAction("Index")); }