// GET: Activities/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var activity = await _context.Activity.Include(m => m.Module).FirstOrDefaultAsync(a => a.Id == id); if (activity == null) { return(NotFound()); } ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Name", activity.ActivityTypeId); ViewData["ModuleId"] = new SelectList(_context.Module, "Id", "Name", activity.ModuleId); var viewModel = new LmsViewModel { Name = activity.Name, Description = activity.Description, StartDateTime = activity.StartDateTime, EndDateTime = activity.EndDateTime, ActivityTypeId = activity.ActivityTypeId, ModuleId = activity.ModuleId, ModuleStart = activity.Module.StartDateTime, ModuleEnd = activity.Module.EndDateTime, }; return(View(viewModel)); }
public IActionResult Create(int?id) { var module = _context.Module.FirstOrDefault(m => m.Id == id); var model = new LmsViewModel { ModuleStart = module.StartDateTime, ModuleEnd = module.EndDateTime, StartDateTime = module.StartDateTime, EndDateTime = module.EndDateTime, ModuleId = module.Id }; ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Name"); ViewData["ModuleId"] = new SelectList(_context.Module, "Id", "Name"); return(View(model)); }
public ActionResult Index(string userLogin = "") { if (User.IsInRole("lector") || User.IsInRole("student")) { var model = new LmsViewModel(WebSecurity.CurrentUserId, User.IsInRole("lector")); model.UserActivity = new UserActivityViewModel(); ViewBag.ShowDpSectionForUser = DpManagementService.ShowDpSectionForUser(WebSecurity.CurrentUserId); bool isMyProfile = string.IsNullOrEmpty(userLogin) || WebSecurity.CurrentUserName == userLogin; ViewData["isMyProfile"] = isMyProfile; ViewData["userLogin"] = string.IsNullOrEmpty(userLogin) || WebSecurity.CurrentUserName == userLogin ? WebSecurity.CurrentUserName : userLogin; return(View(model)); } return(RedirectToAction("Login", "Account")); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,StartDateTime,EndDateTime,ModuleId,ActivityTypeId,ModuleStart,ModuleEnd")] LmsViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var activity = await _context.Activity.FirstOrDefaultAsync(m => m.Id == id); activity.Name = viewModel.Name; activity.Description = viewModel.Description; activity.StartDateTime = viewModel.StartDateTime; activity.EndDateTime = viewModel.EndDateTime; activity.ActivityTypeId = viewModel.ActivityTypeId; activity.ModuleId = viewModel.ModuleId; _context.Update(activity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActivityExists(viewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("MainIndex", "Courses")); } ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Name", viewModel.Id); ViewData["ModuleId"] = new SelectList(_context.Module, "Id", "Name", viewModel.ModuleId); return(View(viewModel)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,StartDateTime,EndDateTime,ModuleId,ActivityTypeId,ModuleStart,ModuleEnd")] LmsViewModel viewModel) { var activity = new Activity { Name = viewModel.Name, Description = viewModel.Description, StartDateTime = viewModel.StartDateTime, EndDateTime = viewModel.EndDateTime, ModuleId = viewModel.ModuleId, ActivityTypeId = viewModel.ActivityTypeId, }; if (ModelState.IsValid) { _context.Add(activity); await _context.SaveChangesAsync(); return(RedirectToAction("MainIndex", "Courses")); } ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Name", activity.ActivityTypeId); ViewData["ModuleId"] = new SelectList(_context.Module, "Id", "Name", activity.ModuleId); return(View(viewModel)); }