public async Task <ActionResult> DeleteConfirmed(Guid id) { IssueManager.Delete(id); if (Request.IsAjaxRequest()) { return(PartialView("_DeleteMsg", "Đã xóa")); } return(RedirectToAction("Index")); }
public void TestDeleteIssue() { bool result = IssueManager.Delete(IssueId); Assert.IsTrue(result, "No changes were made to the issue"); Issue issue = IssueManager.GetById(IssueId); Assert.IsTrue(issue.Disabled); }
public void TestCreateRandomNewIssueVerifyThenDelete() { // Davin, please advise if I have gone overboard with the asserts int StartIssueCount = -1; List <Issue> TestIssues = new List <Issue>(); List <Project> ps = ProjectManager.GetAllProjects(); // Sub test // Check if the system is ocnfigured Assert.IsTrue(ps.Count > 0, "ProjectManager.GetAllProjects() returned nothing"); // Now get the number of issues in the first project so we can test this later // asset passed so we dont need an "if (ps.count > 0)" Project p = ps[0]; StartIssueCount = IssueManager.GetByProjectId(p.Id).Count; // Now generate CNST_NumIssues random issues and return them TestIssues = RandomIssueCreator.CreateRandomIssues("From Unit Test ", DateTime.Now.ToString() + " Unit Test TestCreateRandomNewIssueVerifyThenDelete() Random Data=", CNST_NumIssues); // Sub test // Ok verify that we created at least one issue Assert.IsTrue(TestIssues.Count > 0, "No Issues were randomly created "); // There is now one or more issue present. // Since all issues were created in the same project, we use the first // projectID int pid = TestIssues[0].ProjectId; // Get the number of issues in the first project now. int EndIssueCount = IssueManager.GetByProjectId(pid).Count; // Sub Test // Did we create only CNST_SmallIssues issues? string strAssert = string.Format("The test did not create {0} Issues. StartCount={1} EndCount={2}", CNST_NumIssues.ToString(), StartIssueCount.ToString(), EndIssueCount.ToString()); Assert.IsTrue(EndIssueCount == StartIssueCount + CNST_NumIssues, strAssert); // Verify the same issues are in the database Issue tstIssue; foreach (Issue iss in TestIssues) { // Retrieve the same Issue.ID from the database tstIssue = IssueManager.GetById(iss.Id); // Sub Tests // Now check it // // Cant i use reflection? Assert.IsTrue(tstIssue.Title == iss.Title); Assert.IsTrue(tstIssue.Description == iss.Description); Assert.IsTrue(tstIssue.Id == iss.Id); Assert.IsTrue(tstIssue.IsClosed == iss.IsClosed); Assert.IsTrue(tstIssue.IssueTypeId == iss.IssueTypeId); Assert.IsTrue(tstIssue.IssueTypeImageUrl == iss.IssueTypeImageUrl); Assert.IsTrue(tstIssue.IssueTypeName == iss.IssueTypeName); Assert.IsTrue(tstIssue.LastUpdate == iss.LastUpdate); Assert.IsTrue(tstIssue.LastUpdateDisplayName == iss.LastUpdateDisplayName); Assert.IsTrue(tstIssue.LastUpdateUserName == iss.LastUpdateUserName); Assert.IsTrue(tstIssue.MilestoneDueDate == iss.MilestoneDueDate); Assert.IsTrue(tstIssue.MilestoneId == iss.MilestoneId); Assert.IsTrue(tstIssue.AffectedMilestoneId == iss.AffectedMilestoneId); Assert.IsTrue(tstIssue.AffectedMilestoneImageUrl == iss.AffectedMilestoneImageUrl); Assert.IsTrue(tstIssue.AffectedMilestoneName == iss.AffectedMilestoneName); } // Delete Issues foreach (Issue iss in TestIssues) { IssueManager.Delete(iss.Id); } // Get the number of issues in the first project now. int AfterDeleteIssueCount = IssueManager.GetByProjectId(pid).Count; // Sub Test // Are they gone? strAssert = string.Format("The test did not delete {0} Issues. StartCount={1} AfterDeleteIssueCount={2}", CNST_NumIssues.ToString(), StartIssueCount.ToString(), AfterDeleteIssueCount.ToString()); Assert.IsTrue(EndIssueCount - CNST_NumIssues == AfterDeleteIssueCount, strAssert); // we can now test each one to see if it gone if we like ... not implemented yet }
public ActionResult Create(string startDate, string endDate, int itemId) { DateTime?startDateTime = ParseDateString.GetDateForString(startDate); DateTime?endDateTime = ParseDateString.GetDateForString(endDate); if (startDateTime == null || endDateTime == null || endDateTime < startDateTime) { return(JsonError("Make sure Start Date and End Date are valid dates")); } //If selection range is bigger than 3 years set the last date to max 3 years if (((endDateTime.Value - DateTime.Today).TotalDays / 365) > 3) { endDateTime = DateTime.Today.AddYears(3); if (startDateTime > endDateTime) { startDateTime = endDateTime; } } var closedStatuses = MetaManager.StatusGetClosed(); List <IssueLinkType> linkTypes = IssueManager.GeminiContext.Meta.LinkTypeGet(); IssueLinkType repeatedLinkType = linkTypes.Find(t => string.Compare(t.Label, "Repeated", true) == 0); if (repeatedLinkType == null && linkTypes.Count > 0) { repeatedLinkType = linkTypes[0]; } var issue = IssueManager.Get(itemId); RepeatParser repeat = new RepeatParser(issue.Repeated); List <IssueDto> repeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString()); if (repeatedIssues.Count > 0) { var previousItemsToDelete = repeatedIssues.FindAll(c => c.Created.Date() >= startDateTime.Value && c.Created.Date() <= endDateTime.Value && !closedStatuses.Contains(c.Entity.StatusId)); foreach (var item in previousItemsToDelete) { IssueManager.Delete(item.Entity.Id); } } for (DateTime date = startDateTime.Value; date <= endDateTime.Value; date = date.AddDays(1)) { repeat.CurrentDateTime = date.Date(); IssueDto lastRepeated = IssueManager.GetLastCreatedIssueForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString()); DateTime lastRepeatedDate = issue.Created; if (lastRepeated != null && lastRepeated.Entity.IsExisting) { lastRepeatedDate = lastRepeated.Created; } if (repeat.MaximumRepeats > 0) { repeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString()); if (repeatedIssues != null && repeatedIssues.Count >= repeat.MaximumRepeats) { continue; } } //If last item was created into the future do this if (lastRepeatedDate > date.Date()) { List <IssueDto> tmpRepeatedIssues = IssueManager.GetItemsForOriginator(IssueOriginatorType.Repeat, issue.Id.ToString()); List <IssueDto> ItemsBeforeStartDate = tmpRepeatedIssues.FindAll(i => i.Created < date.Date()); if (ItemsBeforeStartDate.Count == 0) { lastRepeatedDate = issue.Created; } else { lastRepeatedDate = ItemsBeforeStartDate.OrderBy("Created").Last().Created; } } if (repeat.NeedsToRepeat(lastRepeatedDate)) { var customFields = issue.CustomFields; issue.Attachments = new List <IssueAttachmentDto>(); issue.Entity.Repeated = string.Empty; issue.Entity.OriginatorData = issue.Entity.Id.ToString(); issue.Entity.OriginatorType = IssueOriginatorType.Repeat; issue.Entity.ParentIssueId = null; issue.Entity.IsParent = false; issue.Entity.StatusId = 0; issue.Entity.ResolutionId = 0; if (issue.Entity.StartDate.HasValue && issue.Entity.DueDate.HasValue && issue.Entity.StartDate != new DateTime() && issue.Entity.DueDate != new DateTime()) { TimeSpan tsDates = issue.Entity.DueDate.Value - issue.Entity.StartDate.Value; issue.Entity.DueDate = date.AddDays(tsDates.TotalDays); issue.Entity.StartDate = date.Date(); } else { issue.Entity.StartDate = null; issue.Entity.DueDate = null; } int issueId = issue.Id; issue.Entity.Created = date; IssueDto repeated = IssueManager.Create(issue.Entity); if (repeated.Entity.Id > 0) { string statment = "update gemini_issues set created = @created where issueid = @issueid"; SQLService.Instance.ExecuteQuery(statment, new { created = new DateTime(date.Year, date.Month, date.Day, 8, 0, 0).ToUtc(UserContext.User.TimeZone), issueid = repeated.Entity.Id }); } if (customFields != null && customFields.Count > 0) { foreach (var field in customFields) { try { //Find the existing ID to 'replace', if exists. var existingCF = repeated.CustomFields .SingleOrDefault(s => s.Entity.CustomFieldId == field.Entity.CustomFieldId); field.Entity.Id = existingCF == null ? 0 : existingCF.Entity.Id; field.Entity.IssueId = repeated.Entity.Id; field.Entity.ProjectId = repeated.Entity.ProjectId; CustomFieldManager.Update(new CustomFieldData(field.Entity)); } catch (Exception ex) { LogException(ex); } } } if (repeatedLinkType != null) { IssueManager.IssueLinkCreate(repeated.Entity.Id, issueId, repeatedLinkType.Id); } } } return(JsonSuccess()); }
/// <summary> /// Handles the Click event of the lnkDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void LnkDeleteClick(object sender, EventArgs e) { IssueManager.Delete(IssueId); ReturnToPreviousPage(); }