public ActionResult Edit(EditIssueViewModel model) { if (!ModelState.IsValid) { var types = Enum.GetNames(typeof(IssueType)); model.Types = new SelectList(types); return(View(model)); } IssueType type; if (!Enum.TryParse(model.Type, out type)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var issue = db.Issues.Find(model.Id); var currentUserId = User.Identity.GetUserId(); if (issue.AuthorId != currentUserId) { return(RedirectToAction("Index", new { projectId = issue.ProjectId })); } issue.Title = model.Title; issue.Description = model.Description; issue.Type = type; db.SaveChanges(); return(RedirectToAction("Details", new { id = issue.Id })); }
public async Task <IActionResult> Create(string projectKey, EditIssueViewModel model) { try { var project = await _dbContext.Projects.SingleOrDefaultAsync(x => x.Key == projectKey); var issue = new Issue { Project = project, CreatedUser = await GetCurrentUserAsync(), CreatedOnUtc = DateTime.UtcNow, Type = model.Type, Severity = model.Severity, Status = model.Status, Title = model.Title, Description = model.Description }; _dbContext.Issues.Add(issue); await _dbContext.SaveChangesAsync(); this.SuccessNotice("The issue has been created"); return(RedirectToAction("Details", "Projects", new { key = projectKey })); } catch (Exception ex) { _logger.LogError(302, ex, ex.Message); this.ErrorNotice("There was an error creating the issue. Try again."); return(View(model)); } }
public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var issue = db.Issues.Find(id); if (issue == null) { return(HttpNotFound()); } var currentUserId = User.Identity.GetUserId(); if (issue.AuthorId != currentUserId) { return(RedirectToAction("Index", new { projectId = issue.ProjectId })); } var types = Enum.GetNames(typeof(IssueType)); var model = new EditIssueViewModel { Id = issue.Id, Title = issue.Title, Description = issue.Description, ProjectId = issue.ProjectId, Type = issue.Type.ToString(), Types = new SelectList(types) }; return(View(model)); }
public IActionResult <EditIssueViewModel> Edit(HttpSession session, HttpResponse response, int id) { var user = this.service.FindUserBySession(session); if (user.Issues.All(i => i.Id != id) && user.Role != Role.Administrator) { this.Redirect(response, "/issues/all"); return(null); } var loggedUserViewModel = this.service.CheckedForLoggedInUser(session); var editIssueViewModel = new EditIssueViewModel() { Id = id, LoggedInUserViewModel = loggedUserViewModel }; return(this.View(editIssueViewModel)); }
public async Task <IActionResult> Create(string projectKey) { var project = await _dbContext.Projects.SingleOrDefaultAsync(x => x.Key == projectKey); if (project == null) { this.ErrorNotice("Project could not be found"); return(RedirectToAction("Details", "Projects", new { key = projectKey })); } var model = new EditIssueViewModel { ProjectId = project.Id, Project = project.ToModel() }; return(View(model)); }