public IssueDetailVM SaveIssue(CreateIssue issue, List<HttpPostedFileBase> files) { issue.TeamID = userSessionHelper.TeamId; issue.CreatedByID = userSessionHelper.UserId; issue.ProjectID = GetDefaultProjectId(); var issueId = issueRepository.SaveIssue(issue); return issueRepository.GetIssue(issueId); //Activity entry // return SaveActivity(issue, previousVersion, newVersion); }
public ActivityDto SaveActivity(CreateIssue model, IssueDetailVM previousVersion, IssueDetailVM newVersion) { bool isStateChanged = false; var activity = new ActivityDto() { ObjectId = newVersion.Id, ObjectType = "Issue" }; if (previousVersion == null) { activity.ObjectUrl = "issue/" + newVersion.Id; //activity.CreatedBy = activity.Description = "Created"; activity.ObjectTite = model.Title; isStateChanged = true; } else { if (previousVersion.Status.Id != newVersion.Status.Id) { // status of issue updated activity.Description = "Changed status"; activity.NewState = newVersion.Status.Name; activity.OldState = previousVersion.Status.Name; activity.ObjectTite = newVersion.Title; isStateChanged = true; } else if (previousVersion.Category.Id != newVersion.Category.Id) { activity.Description = "Changed category"; activity.NewState = newVersion.Category.Name; activity.OldState = previousVersion.Category.Name; activity.ObjectTite = newVersion.Title; isStateChanged = true; } } activity.TeamId = userSessionHelper.TeamId; activity.Actor = new UserDto { Id = userSessionHelper.UserId }; if (isStateChanged) { var newId = activityRepository.Save(activity); return activityRepository.GetActivityItem(newId); } return null; }
private Activity SaveActivity(CreateIssue model, Issue existingIssue, Issue issuePreviousVersion, Status currentIssueStatus, int issueId, bool isNewIssue = false) { bool isStateChanged = false; var activity = new Activity() { CreatedByID = UserID, ObjectID = issueId, ObjectType = "Issue" }; if (isNewIssue) { activity.ActivityDesc = "Created"; activity.NewState = model.Title; isStateChanged = true; } else { if (issuePreviousVersion.StatusID != existingIssue.StatusID) { // status of issue updated activity.OldState = model.Title; activity.ActivityDesc = "Changed status"; activity.NewState = currentIssueStatus.Name; isStateChanged = true; } } activity.TeamID = TeamID; if (isStateChanged) { var result = repo.SaveActivity(activity); if (!result.Status) { log.Error(result); } return repo.GetActivity(activity.ID); } return null; }
private void LoadDefaultIssueValues(Issue issue, CreateIssue model) { issue.PriorityID = model.SelectedPriority; if (issue.PriorityID == 0) issue.PriorityID = 1; issue.ProjectID = model.SelectedProject; if (issue.ProjectID == 0) { var teamMember = repo.GetTeamMember(UserID, TeamID); if (teamMember.DefaultProjectID == null) throw new MissingSettingsException("Default Project not set", "Default Project"); //get from team member issue.ProjectID = teamMember.DefaultProjectID.Value; } issue.StatusID = model.SelectedStatus; if ((model.Id == 0) && (model.SelectedStatus == 0)) { issue.StatusID = 1; } issue.CategoryID = model.SelectedCategory; if (issue.CategoryID == 0) issue.CategoryID = 1; issue.Location = (string.IsNullOrEmpty(model.SelectedIteration) ? "SPRNT" : model.SelectedIteration); }
private int SaveAttachedDocument(CreateIssue model, OperationStatus result, int fileCounter, HttpPostedFileBase file) { if (file != null) { fileCounter++; string fileName = Path.GetFileName(file.FileName).ToLower(); string fileKey = fileName; fileKey = fileKey.Replace(" ", "-").Replace("%", "-"); fileKey = String.Format("{0}-{1}-{2:n}-{3}", result.OperationID, fileCounter, Guid.NewGuid(), fileName); if (fileKey.Length > 99) fileKey = fileKey.Substring(0, 99); string path = Path.Combine(Server.MapPath("~/uploads"), fileKey); file.SaveAs(path); Document img = new Document { FileName = fileName, ParentID = model.Id }; img.FileAlias = fileKey; img.CreatedByID = UserID; img.ParentID = result.OperationID; var resultForImg = repo.SaveDocument(img); if (!resultForImg.Status) log.Debug(resultForImg); } return fileCounter; }
private void LoadDropDownsForCreate(CreateIssue viewModel) { viewModel.Projects = projectManager.GetProjects().Select(s=>new SelectListItem { Value = s.Id.ToString(), Text =s.Name}).ToList(); viewModel.Priorities = ProjectService.GetPriorities(repo); viewModel.Categories = ProjectService.GetCategories(repo); viewModel.Statuses = ProjectService.GetStatuses(repo); viewModel.Iterations = ProjectService.GetIterations(); }
public ActionResult Edit(int id) { var bug = repo.GetIssue(id); if (bug != null) { var editVM = new CreateIssue(); editVM.Title = bug.Title; editVM.Description = bug.Description; LoadDropDownsForCreate(editVM); editVM.SelectedCategory = bug.Category.ID; editVM.SelectedPriority = bug.Priority.ID; editVM.SelectedProject = bug.Project.ID; editVM.SelectedStatus = bug.Status.ID; editVM.SelectedIteration = bug.Location; editVM.CreatedDate = bug.CreatedDate; //var allDocuments = repo.GetDocuments(id, "Bug"); /* var images = allDocuments.Where(x => x.Extension.ToUpper() == ".JPG" || x.Extension.ToUpper() == ".PNG"); foreach (var img in images) { var imgVM = new DocumentVM { FileName = img.DocName }; imgVM.FileKey = img.DocKey; editVM.Images.Add(imgVM); }*/ if (Request.IsAjaxRequest()) { editVM.IsFromModalWindow = true; return PartialView("~/Views/Issues/Partial/Edit.cshtml", editVM); } return View(editVM); } return View("NotFound"); }
public ActionResult Add(CreateIssue model, List<HttpPostedFileBase> files) { try { if (ModelState.IsValid) { var previousVersion = issueManager.GetIssue(model.Id); var newVersion = issueManager.SaveIssue(model, files); var issueActivity = issueManager.SaveActivity(model, previousVersion, newVersion); var context = GlobalHost.ConnectionManager.GetHubContext<IssuesHub>(); if (issueActivity != null) { context.Clients.Group(TeamID.ToString()).addNewTeamActivity(issueActivity); context.Clients.Group(TeamID.ToString()).addIssueToIssueList(newVersion); //update the dashboard var dashboardSummary = issueManager.GetDashboardSummaryVM(issueActivity.TeamId); context.Clients.Group(TeamID.ToString()).updateDashboardSummary(dashboardSummary); } if (Request.IsAjaxRequest()) { if (model.Id == 0) { // var issueVM = issueService.GetIssueVM(issue); // context.Clients.Group(TeamID.ToString()).addIssueToIssueList(issueVM); //issueService.SendEmailNotificationsToSubscribers(issue, TeamID, UserID, SiteBaseURL); } return Json(new { Status = "Success" }); } if ((files != null) && (files.Any())) { int fileCounter = 0; foreach (var file in files) { // fileCounter = SaveAttachedDocument(model, result, fileCounter, file); } } if (model.IsFromModalWindow) { if (Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.AbsoluteUri); } return RedirectToAction("Index"); } } catch (MissingSettingsException mex) { log.Debug(mex); return Json(new { Status = "Error", Message = String.Format("You need to set a value for {0} first.", mex.MissingSettingName) }); } catch (Exception ex) { log.Error(ex); if (Request.IsAjaxRequest()) { return Json(new { Status = "Error", Message = "Error saving issue" }); } } LoadDropDownsForCreate(model); return View(model); }
public int SaveIssue(CreateIssue issue) { Issue issueEntity = null; using (var db = new TeamEntitiesConn()) { if (issue.Id > 0) { issueEntity = db.Issues.FirstOrDefault(s => s.ID == issue.Id); if (issueEntity == null) { return 0; } } else { issueEntity = new Issue(); } issueEntity.Title = issue.Title; issueEntity.Description = issue.Description; issueEntity.ProjectID = issue.ProjectID; issueEntity.TeamID = issue.TeamID; issueEntity.CategoryID = issue.SelectedCategory; issueEntity.CreatedByID = issue.CreatedByID; issueEntity.Location = issue.Iteration; issueEntity.StatusID = issue.SelectedStatus; issueEntity.PriorityID = issue.SelectedPriority; if (issueEntity.CategoryID == 0) { issueEntity.CategoryID = db.Categories.FirstOrDefault().ID; } if (issueEntity.StatusID == 0) { var status = db.Status.FirstOrDefault(s => s.Code == "New"); issueEntity.StatusID = status.ID; } if (issueEntity.PriorityID == null || issueEntity.PriorityID.Value == 0) { var priority = db.Priorities.FirstOrDefault(s => s.Code == "Normal"); issueEntity.PriorityID = priority.ID; } if (issue.Id == 0) { issueEntity.CreatedDate = DateTime.UtcNow; issueEntity.Active = true; db.Issues.Add(issueEntity); } else { issueEntity.ModifiedDate = DateTime.Now; issueEntity.ModifiedByID = issue.CreatedByID; db.Entry(issueEntity).State = EntityState.Modified; } db.SaveChanges(); return issueEntity.ID; } }
public int SaveIssue(CreateIssue issue) { using (var con = new SqlConnection(ConnectionString)) { con.Open(); if (issue.Id == 0) { issue.CreatedDate = DateTime.Now; var q = con.Query<int>( @"INSERT INTO Issue(Title,Description,DueDate,CategoryId,StatusID,PriorityID,ProjectID,TeamId,Active,CreatedDate,CreatedByID) VALUES(@title,@description,@IssueDueDate,@categoryId,@statusId,@priorityId,@projectId,@teamId,1,@createdDate,@createdById);SELECT CAST(SCOPE_IDENTITY() as int)", issue); return q.First(); } else { con.Execute( "UPDATE Issue SET Title=@title,Description=@description,CategoryId=@CategoryId,ProjectId=@ProjectId,StatusId=@statusId,PriorityId=@priorityId WHERE Id=@id", issue); return issue.Id; } } }
public async Task<IssueDetailVM> SaveIssue(CreateIssue issue, List<IFormFile> files) { bool isNewIssue = issue.Id == 0; if (issue.ProjectId == 0) { var defaultProject = await iProjectRepository.GetDefaultProjectForTeamMember(this.userSessionHelper.TeamId, this.userSessionHelper.UserId); if (defaultProject == null) { throw new MissingSettingsException("Missing data", "Default project"); } issue.ProjectId = defaultProject.Id; } if (issue.CategoryId == 0) { var categories =await this.issueRepository.GetCategories(); issue.CategoryId = categories.First().Id; } if (issue.PriorityId == 0) { var categories = await this.issueRepository.GetPriorities(); issue.PriorityId = categories.First().Id; } if (issue.StatusId == 0) { var statuses = await this.issueRepository.GetStatuses(); issue.StatusId = statuses.First().Id; } issue.CreatedById = this.userSessionHelper.UserId; issue.TeamID = this.userSessionHelper.TeamId; var issueId = this.issueRepository.SaveIssue(issue); var issueDetail = this.issueRepository.GetIssue(issueId, this.userSessionHelper.UserId); if (isNewIssue) { await emailManager.SendIssueCreatedEmail(issueDetail, this.userSessionHelper.TeamId); //.QueueBackgroundWorkItem(ct => SendMailAsync(user.Email)); } return issueDetail; }
public async Task LoadDropdownData(CreateIssue issue) { issue.Projects =this.iProjectRepository.GetProjects(this.userSessionHelper.TeamId) .Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Name }) .ToList(); var statuses = await this.cache.Get(CacheKey.Statuses, () => this.issueRepository.GetStatuses(),360); var priorities = await this.cache.Get(CacheKey.Priorities, () => this.issueRepository.GetPriorities(), 360); var catagories = await this.cache.Get(CacheKey.Categories, () => this.issueRepository.GetCategories(), 360); issue.Statuses = statuses.Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Name }).ToList(); issue.Priorities = priorities.Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Name }).ToList(); issue.Categories = catagories.Select(s => new SelectListItem { Value = s.Id.ToString(), Text = s.Name }).ToList(); }
public async Task<IActionResult> Add(CreateIssue model) { try { if (ModelState.IsValid) { var previousVersion = await _issueManager.GetIssue(model.Id); var newVersion = await _issueManager.SaveIssue(model, null); var issueActivity = _issueManager.SaveActivity(model, previousVersion, newVersion); //ConnectionManager c = new ConnectionManager(new DefaultDependencyResolver()); // var context = c.GetHubContext<IssuesHub>(); // context.Clients.All.addNewTeamActivity(issueActivity); if ((model.Files != null) && (model.Files.Any())) { foreach (var file in model.Files) { var fileName = Path.GetFileName(file.FileName); using (var s = file.OpenReadStream()) { var uploadResult = await _uploadHandler.UploadFile(fileName, MimeMapping.GetMimeMapping(fileName), s); if (!String.IsNullOrEmpty(uploadResult.Url)) { uploadResult.ParentId = model.Id; uploadResult.CreatedById = this._userSessionHelper.UserId; uploadResult.Type = "Issue"; await this._uploadManager.SaveUpload(uploadResult); } } } } if (previousVersion != null) { } if (model.IncludeIssueInResponse) { var newIssue = _issueManager.GetIssue(newVersion.Id); return Json(new { Status = "Success", Data = newIssue }); } var newIssueUrl = this._urlHelper.Action("Details", new { id = newVersion.Id }); return Json(new { Status = "Success", Url = newIssueUrl }); } else { var validationErrors = new List<string>(); foreach (var modelStateVal in ViewData.ModelState.Values) { validationErrors.AddRange(modelStateVal.Errors.Select(error => error.ErrorMessage)); } return Json(new { Status = "Error", Message = "Validation failed", Errors = validationErrors }); } } catch (MissingSettingsException mex) { return Json(new { Status = "Error", Message = String.Format("You need to set a value for {0} first.", mex.MissingSettingName) }); } catch (Exception ex) { // bErrorStore.LogException(ex, Request.HttpContext); return Json(new { Status = "Error", Message = "Error saving issue" }); } return View(model); }
public async Task<IActionResult> Edit(int id) { var issue = await this._issueManager.GetIssue(id); if (issue != null && issue.Active) { var vm = new CreateIssue(issue); this._issueManager.LoadDropdownData(vm); vm.IsEditableForCurrentUser = this._teamManager.DoesCurrentUserBelongsToTeam(this._userSessionHelper.UserId, this._userSessionHelper.TeamId); return PartialView("~/Views/Issues/Partial/Edit.cshtml", vm); } return PartialView("NotFound"); }
public async Task<IActionResult> Add() { var vm = new CreateIssue(); this._issueManager.LoadDropdownData(vm); return PartialView("~/Views/Issues/Partial/Edit.cshtml", vm); }
private void LoadDropDownsForCreate(CreateIssue viewModel) { viewModel.Projects = ProjectService.GetProjects(repo, TeamID); viewModel.Priorities = ProjectService.GetPriorities(repo); viewModel.Categories = ProjectService.GetCategories(repo); viewModel.Statuses = ProjectService.GetStatuses(repo); viewModel.Iterations = ProjectService.GetIterations(); }