Exemplo n.º 1
0
        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"));
        }