public Step UpdateStep(Step _s, List <int> _workerIds) { try { var numberOfUpdated = 0; using (var context = new ProjectManagementEntities()) { var step = context.Step.FirstOrDefault(x => x.Id == _s.Id); if (step != null) { step.AssigneeUser = _s.AssigneeUser; step.Description = _s.Description; step.EndDate = _s.EndDate; step.MilestoneId = _s.MilestoneId; step.Name = _s.Name; step.SprintId = _s.SprintId; step.StartDate = _s.StartDate; numberOfUpdated = context.SaveChanges(); var stepPerson = context.StepPerson.Where(x => x.StepId == _s.Id).ToList(); if (stepPerson.Count() > 0) { foreach (var stepPersonItem in stepPerson) { var stepPersonDetail = context.StepPersonDetail.Where(x => x.StepPersonId == stepPersonItem.Id).ToList(); if (stepPersonDetail.Count() > 0) { foreach (var stepPersonDetailItem in stepPersonDetail) { context.Entry(stepPersonDetailItem).State = EntityState.Deleted; context.SaveChanges(); } } context.Entry(stepPersonItem).State = EntityState.Deleted; context.SaveChanges(); } } foreach (var item in _workerIds) { var newStepPerson = new StepPerson() { PersonId = item, StepId = _s.Id }; context.StepPerson.Add(newStepPerson); context.SaveChanges(); } return(numberOfUpdated > 0 ? _s : null); } return(null); } } catch (System.Exception exc) { throw exc; } }
public Step SaveWhatsappTaskAsStep(int _redirectId, int _milestoneId, int _sprintId, int _headOfDepartmentPersonId, int _personId, string _title, string _desc) { try { using (var context = new ProjectManagementEntities()) { var redirect = context.WhatsappMessageRedirect.FirstOrDefault(x => x.Id == _redirectId); var message = context.WhatsappMessage.FirstOrDefault(x => x.Id == redirect.MessageId); var step = new Step() { AssigneeUser = _headOfDepartmentPersonId, Description = _desc, MilestoneId = _milestoneId, Name = _title, SprintId = _sprintId, Status = 1 }; context.Step.Add(step); int numberOfInserted = context.SaveChanges(); if (numberOfInserted > 0) { var stepPerson = new StepPerson() { Description = "", PersonId = _personId, StepId = step.Id }; context.StepPerson.Add(stepPerson); context.SaveChanges(); var sprint = context.Sprint.FirstOrDefault(x => x.Id == _sprintId); if (sprint.Status == 2) { var boardStep = new BoardStep() { Date = DateTime.Now, Description = "Whatsapp üzerinden yönlendirilmiştir.", PersonId = _headOfDepartmentPersonId, BoardId = context.Board.Where(x => x.ProjectId == sprint.ProjectId && x.Status > 0).ToList().FirstOrDefault().Id, StepId = step.Id }; context.BoardStep.Add(boardStep); context.SaveChanges(); } redirect.Status = 0; context.SaveChanges(); return(step); } return(null); } } catch (Exception exc) { throw exc; } }
public Step SaveStep(Step _s, List <int> _workerIds) { try { using (var context = new ProjectManagementEntities()) { context.Step.Add(_s); int numberOfInserted = context.SaveChanges(); if (numberOfInserted > 0) { foreach (var item in _workerIds) { var stepPerson = new StepPerson() { PersonId = item, StepId = _s.Id }; context.StepPerson.Add(stepPerson); context.SaveChanges(); } var sprint = context.Sprint.FirstOrDefault(x => x.Id == _s.SprintId); if (sprint.Status == 2) { var boardstep = new BoardStep() { BoardId = context.Board.Where(x => x.ProjectId == sprint.ProjectId).ToList().OrderBy(x => x.Id).ToList().FirstOrDefault().Id, Date = DateTime.Now, Description = "", PersonId = 0, StepId = _s.Id }; context.BoardStep.Add(boardstep); context.SaveChanges(); //foreach (var item in _workerIds) //{ // var boardstep = new BoardStep() // { // BoardId = context.Board.Where(x => x.ProjectId == sprint.ProjectId).ToList().OrderBy(x => x.Id).ToList().FirstOrDefault().Id, // Date = DateTime.Now, // Description = "", // PersonId = item, // StepId = _s.Id // }; // context.BoardStep.Add(boardstep); // context.SaveChanges(); //} } } return(numberOfInserted > 0 ? _s : null); } } catch (System.Exception exc) { throw exc; } }