public async Task <PartialViewResult> Create(UserEditViewModel model) { if (model?.User == null || !ModelState.IsValid) { throw new Exception(BusinessErrors.UserInvalid); } _db.Users.Add(model.User); await _db.SaveAsync(); var users = await _db.Users.GetAllAsync(); return(PartialView("_UserAdminListPartial", users)); }
public async Task <Issue> Transition(Issue issue, IssueTransition transition, string userId, string comment) { //if transition not in possible transitions if (!GetTransitions(issue).Contains(transition)) { throw new BusinessException(BusinessErrors.TransitionIsImpossible); } issue.IssueStatusCode = _stateMachine.Transition(issue.IssueStatusCode, transition); await TransferOwnerShip(issue, transition, userId); _db.Issues.Update(issue); var history = new IssueHistory { IssueId = issue.Id, CreatedOn = DateTime.Now, Comment = comment, Status = issue.IssueStatusCode, UserId = HttpContext.Current.User.Identity.GetUserId() }; _db.Histories.Add(history); await _db.SaveAsync(); return(issue); }
public async Task <ActionResult> Edit(Issue issue) { if (issue != null && ModelState.IsValid) { _db.Issues.Update(issue); await _db.SaveAsync(); return(RedirectToAction("Index")); } var transitions = _transitionService.GetTransitions(issue); var model = new IssueEditViewModel { Issue = issue, Transitions = transitions }; return(View(model)); }
public async Task <ActionResult> ManageProfile(ApplicationUser applicationUser) { if (applicationUser == null || !ModelState.IsValid) { return(View(applicationUser)); } var dbUser = await _db.Users.GetAsync(User.Identity.GetUserId()); dbUser.Surname = applicationUser.Surname; dbUser.GivenName = applicationUser.GivenName; dbUser.MobilePhone = applicationUser.MobilePhone; dbUser.Email = applicationUser.Email; dbUser.PhoneNumber = applicationUser.PhoneNumber; dbUser.UserName = applicationUser.UserName; _db.Users.Update(dbUser); await _db.SaveAsync(); return(RedirectToAction("Index")); }
/// <summary> /// Generates dummy issues for our dummy admin. /// </summary> /// <returns></returns> public async Task GenerateDummyIssues() { //if dummy method was not called before if (await _db.Issues.SingleOrDefaultAsync(i => i.Subject.ToLower().Equals("epicTestIssue1")) == null) { var ted = await _db.Users.SingleOrDefaultAsync(u => u.UserName.Equals("Ted")); var bob = await _db.Users.SingleOrDefaultAsync(u => u.UserName.Equals("Bob")); var jan = await _db.Users.SingleOrDefaultAsync(u => u.UserName.Equals("Jan")); var louis = await _db.Users.SingleOrDefaultAsync(u => u.UserName.Equals("Louis")); var issueList = new List <Issue> { new Issue { Creator = ted, Subject = "epicTestIssue1", Description = "Issue1", IssueStatusCode = IssueStatusCode.New, PriorityCode = PriorityCode.immediate, Occurrence = DateTime.Now.AddDays(-10), Registered = DateTime.Now }, new Issue { Creator = bob, Subject = "Issue2", Description = "Issue2", IssueStatusCode = IssueStatusCode.New, PriorityCode = PriorityCode.low, Occurrence = DateTime.Now.AddDays(-5), Registered = DateTime.Now }, new Issue { Creator = louis, Subject = "Issue3", Description = "Issue3", IssueStatusCode = IssueStatusCode.New, PriorityCode = PriorityCode.low, Occurrence = DateTime.Now.AddDays(-5), Registered = DateTime.Now, ResponsibleUser = louis } }; var issueWithHistory = new Issue { Creator = louis, Subject = "Issue4", Description = "Issue4", IssueStatusCode = IssueStatusCode.Solved, PriorityCode = PriorityCode.low, Occurrence = DateTime.Now.AddDays(-15), Registered = DateTime.Now.AddDays(-10), ResponsibleUser = jan }; foreach (var issue in issueList) { _db.Issues.Add(issue); } var histories = new List <IssueHistory> { new IssueHistory { Comment = "Issue created in database", CreatedOn = DateTime.Now.AddDays(-9), Issue = issueWithHistory, Status = IssueStatusCode.New, User = louis }, new IssueHistory { Comment = "Issue assigned to user", CreatedOn = DateTime.Now.AddDays(-8), Issue = issueWithHistory, Status = IssueStatusCode.Processing, User = bob }, new IssueHistory { Comment = "Issue solved by solver", CreatedOn = DateTime.Now.AddDays(-5), Issue = issueWithHistory, Status = IssueStatusCode.Solved, User = jan } }; foreach (var history in histories) { _db.Histories.Add(history); } await _db.SaveAsync(); } }