/// <summary> /// Update the feedback/response on Task. /// </summary> /// <returns>Details Page.</returns> /// <param name="s">Form values</param> public async Task <ActionResult> Comment(IFormCollection s) { if (!AuthenticationHelper.isAuthorizedUser(HttpContext.Session.GetString("Username"))) { Response.Redirect("/Login"); } //Fetch required data to create the feedback object int tid = Convert.ToInt32(s.Where(ky => ky.Key == "TaskId").FirstOrDefault().Value); var task = _context.Tasks.Where(tsk => tsk.TaskId == tid).FirstOrDefault(); var user = _context.Users.Where(usr => usr.Username == HttpContext.Session.GetString("Username")).FirstOrDefault(); //Create Feedback object Feedback feedback = new Feedback(); feedback.Response = s.Where(ky => ky.Key == "Response").FirstOrDefault().Value; feedback.TaskId = task.TaskId; feedback.User = user; feedback.Created = DateTime.Now; _context.Feedbacks.Add(feedback); await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { id = tid })); }
/// <summary> /// Adds the admin if database is newly created and no user is present. /// </summary> private void addAdmin() { if (_context.Users.Count() == 0) { _context.Users.Add(new User() { Username = "******", Password = "******", IsDevTeam = 1 }); _context.SaveChangesAsync(); } }