public ActionResult Edit(int id) { var activity = _unitOfWork.Activities.GetActivities(id); if (activity == null) { return(HttpNotFound()); } if (activity.TeacherId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } var viewModel = new ActivityFormViewModel { Id = activity.Id, Heading = "Edit an Activity", Categories = _unitOfWork.Categories.GetCategories(), Date = activity.DateTime.ToString("d MMM yyyy"), Time = activity.DateTime.ToString("HH:mm"), Category = activity.CategoryId, Location = activity.Location, Description = activity.Description }; return(View("ActivityForm", viewModel)); }
public ActionResult Update(ActivityFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Categories = _unitOfWork.Categories.GetCategories(); return(View("ActivityForm", viewModel)); } var activity = _unitOfWork.Activities.GetActivityWithAttendees(viewModel.Id); if (activity == null) { return(HttpNotFound()); } if (activity.TeacherId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } activity.Modify(viewModel.GetDateTime(), viewModel.Description, viewModel.Category, viewModel.Location); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Activities")); }
public ActionResult Create() { var viewModel = new ActivityFormViewModel { Categories = _repository.GetAllCategories() }; return(View(viewModel)); }
public ActivityFormViewModel ActivityFormVM() { var viewModel = new ActivityFormViewModel() { Categories = _context.Categories.ToList() }; return viewModel; }
public ActionResult Create() { var viewModel = new ActivityFormViewModel { Categories = _unitOfWork.Categories.GetCategories(), Heading = "Add an Activity" }; return(View("ActivityForm", viewModel)); }
public ActivityFormViewModel ActivityFormVM(int? id) { var activity = GetById(id); if (activity == null) return null; var viewModel = new ActivityFormViewModel(activity) { Categories = _context.Categories.ToList() }; return viewModel; }
public async Task <IActionResult> CreateActivity(ActivityFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Categories = _repository.GetAllCategories(); return(View("Create", viewModel)); } var activity = new Activity { CategoryId = viewModel.CategoryId, Name = viewModel.Name, User = await _userManager.GetUserAsync(User) }; _repository.AddActivity(activity); _repository.SaveAll(); return(RedirectToAction("Index", "Activity")); }
public ActionResult Create(ActivityFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Categories = _unitOfWork.Categories.GetCategories(); return(View("ActivityForm", viewModel)); } var activity = new Activity { TeacherId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), CategoryId = viewModel.Category, Description = viewModel.Description, Location = viewModel.Location }; _unitOfWork.Activities.Add(activity); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Activities")); }