public ActionResult Create(EditSessionModel model, string btnSubmit)
        {
            PopulateEditSessionModel(model);
            model.Permissions = new SessionPermissionModel { CanEdit = true, CanView = true };

            if (!ModelState.IsValid)
                return View(model);

            var user = _userService.GetByUsername(User.Identity.Name);

            var session = new Session
            {
                UserId = user.Id,
                Title = model.Title,
                Overview = model.Overview,
                CreatedAt = DateTime.Now,
                City = model.City,
                Start = model.CreateStart.Value,
                End = model.CreateEnd.Value,
                RegistrationClosedAt = model.CreateRegistrationClosedAt.Value
            };

            _sessionService.Create(session);

            if(btnSubmit == "Submit")
            {
                _sessionService.UserSubmit(session.Id);
                return RedirectToAction("List", "Session").WithSuccessMessage(string.Format("Session '{0}' has been successfully submitted for Admin approval.", session.Title));
            }

            return RedirectToAction("List", "Session").WithSuccessMessage(string.Format("Session '{0}' has been successfully created.", session.Title));
        }
        public ActionResult Edit(int id)
        {
            var session = _sessionService.GetById(id);

            var model = new EditSessionModel
            {
                Id = session.Id,
                City = session.City,
                CreateEnd = session.End,
                Overview = session.Overview,
                CreateRegistrationClosedAt = session.RegistrationClosedAt,
                SelectedTypeId = (int)session.Type,
                CreateStart = session.Start,
                Title = session.Title,
                Permissions = _sessionService.GetPermissionModel(session, _userService.CurrentUser),
                Users = session.Users.ToList()
            };

            PopulateEditSessionModel(model);

            if (!model.Permissions.CanView)
                return RedirectToAction("List", "Session").WithErrorMessage("You are not authorized to access this page.");

            return View(model);
        }
        public ActionResult Create()
        {
            var model = new EditSessionModel { Permissions = new SessionPermissionModel { CanEdit = true, CanView = true } };

            PopulateEditSessionModel(model);

            return View(model);
        }
        void PopulateEditSessionModel(EditSessionModel model)
        {
            var statuses = from SessionType s in SessionType.GetValues(typeof(SessionType))
                           select new SelectListItem { Text = s.ToString(), Value = ((int)s).ToString() };

            model.Types = statuses;
        }
        public ActionResult Edit(int id, EditSessionModel model, string btnSubmit)
        {
            var session = _sessionService.GetById(id);

            PopulateEditSessionModel(model);
            model.Permissions = _sessionService.GetPermissionModel(session, _userService.CurrentUser);
            model.Users = session.Users.ToList();

            if (!model.Permissions.CanView)
                return RedirectToAction("List", "Session").WithErrorMessage("You are not authorized to access this page.");

            if (!ModelState.IsValid)
                return View(model);

            session.City = model.City;
            session.End = model.CreateEnd.Value;
            session.Overview = model.Overview;
            session.RegistrationClosedAt = model.CreateRegistrationClosedAt.Value;
            session.Start = model.CreateStart.Value;
            session.Title = model.Title;

            _sessionService.Update(session);

            if (btnSubmit == "Submit")
            {
                _sessionService.UserSubmit(session.Id);
                return RedirectToAction("Manage", "Session").WithSuccessMessage(string.Format("Session '{0}' has been successfully submitted for Admin approval.", session.Title));
            }

            return RedirectToAction("Manage", "Session").WithSuccessMessage(string.Format("Session '{0}' has been successfully saved.", session.Title));
        }