//function to update events in Database public void UpdatingCalenderInDB(int pstrEventId, DateTime pstrNewEventStart, DateTime pstrNewEventEnd) { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DBCalendar calenderObj = new DBCalendar(); calenderObj = (from calenderEvent in contextObj.DBCalendars where calenderEvent.DBEventId == pstrEventId select calenderEvent).FirstOrDefault(); if (calenderObj.DBEventStatus == "Active") { calenderObj.DBEventStartTime = pstrNewEventStart; calenderObj.DBEventEndTime = pstrNewEventEnd; contextObj.SaveChanges(); DBCompany companyObj = new DBCompany(); companyObj = (from company in contextObj.DBCompanies where company.DBCompanyId == calenderObj.DBCompanyId select company).FirstOrDefault(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in contextObj.DBSubscriptions where subObj.DBCompanyId == calenderObj.DBCompanyId select subObj).ToList(); DBCalendar calEvent = new DBCalendar(); calEvent = (from calObj in contextObj.DBCalendars where calObj.DBEventId == pstrEventId select calObj).FirstOrDefault(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in contextObj.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", calEvent.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", calEvent.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", calEvent.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", calEvent.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "Event Schedule Updated", stringHtml); } } }
//Delete Event in Event Click public string mDeleteEvent(int pstrgetId) { try { WinMonitorEntityModelContext mDBContextObj = new WinMonitorEntityModelContext(); DBCalendar CalObj = new DBCalendar(); CalObj = (from calObj in mDBContextObj.DBCalendars where calObj.DBEventId == pstrgetId select calObj).FirstOrDefault(); mDBContextObj.DBCalendars.Remove(CalObj); mDBContextObj.SaveChanges(); return("Event Sucessfully Deleted!!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
public Calendar() { this.dbCalendar_ = new DBCalendar(); this.calendarName_ = "EmptyCalendar"; }
//Admin Maintenance Calendar //AddEVent In Calendar public string mSaveCalendarEvent(string pstrTitle, string pstrDetails, string pstrStartTime, string pstrEndTime, string pstrEventFor, string pstrMaintenance, int pstrCompanyId) { try { WinMonitorEntityModelContext mDBContext = new WinMonitorEntityModelContext(); if (pstrEventFor == "all") { List <DBCompany> companyList = new List <DBCompany>(); companyList = (from company in mDBContext.DBCompanies select company).ToList(); foreach (DBCompany companyObj in companyList) { DBCalendar CalObj = new DBCalendar(); CalObj.DBEventId = getseqDBCalEventId(); CalObj.DBEventTitle = pstrTitle; CalObj.DBEventDetails = pstrDetails; DateTime mdateStartTime = DateTime.Parse(pstrStartTime); CalObj.DBEventStartTime = mdateStartTime; DateTime mdateEndTime = DateTime.Parse(pstrEndTime); CalObj.DBEventEndTime = mdateEndTime; CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString(); CalObj.DBEventMaintenance = pstrMaintenance; CalObj.DBCompanyId = companyObj.DBCompanyId; TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow); if (mstrRecordState.TotalMinutes > 0) { CalObj.DBEventStatus = "Active"; } else { CalObj.DBEventStatus = "Inactive"; } mDBContext.DBCalendars.Add(CalObj); mDBContext.SaveChanges(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in mDBContext.DBSubscriptions where subObj.DBCompanyId == companyObj.DBCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in mDBContext.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", CalObj.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml); } } } else { DBCalendar CalObj = new DBCalendar(); CalObj.DBEventId = getseqDBCalEventId(); CalObj.DBEventTitle = pstrTitle; CalObj.DBEventDetails = pstrDetails; DateTime mdateStartTime = DateTime.Parse(pstrStartTime); CalObj.DBEventStartTime = mdateStartTime; DateTime mdateEndTime = DateTime.Parse(pstrEndTime); CalObj.DBEventEndTime = mdateEndTime; CalObj.DBEventDifferenceTime = mdateEndTime.Subtract(mdateStartTime).ToString(); //CalObj.DBEventRepetition = pstrEventFor; CalObj.DBEventMaintenance = pstrMaintenance; CalObj.DBCompanyId = pstrCompanyId; TimeSpan mstrRecordState = mdateEndTime.Subtract(DateTime.UtcNow); if (mstrRecordState.TotalMinutes > 0) { CalObj.DBEventStatus = "Active"; } else { CalObj.DBEventStatus = "Inactive"; } mDBContext.DBCalendars.Add(CalObj); mDBContext.SaveChanges(); DBCompany companyObj = new DBCompany(); companyObj = (from company in mDBContext.DBCompanies where company.DBCompanyId == pstrCompanyId select company).FirstOrDefault(); List <DBSubscription> subscriptionObjList = new List <DBSubscription>(); subscriptionObjList = (from subObj in mDBContext.DBSubscriptions where subObj.DBCompanyId == pstrCompanyId select subObj).ToList(); DBEmailPage emailPageObj = new DBEmailPage(); emailPageObj = (from emailPage in mDBContext.DBEmailPages where emailPage.DBEmailPageId == 1 select emailPage).FirstOrDefault(); foreach (DBSubscription subscriptionObj in subscriptionObjList) { PerformSubscription performSubscriptionObj = new PerformSubscription(); WebClient clientObj = new WebClient(); int endIndex, startIndex; string stringHtml = emailPageObj.DBEmailContent.ToString(); endIndex = stringHtml.IndexOf("<!--end of componentUpdateDiv-->"); startIndex = stringHtml.IndexOf("<div id=\"divForComponentUpdates\">"); string stringToBeReplaced = stringHtml.Substring(startIndex, endIndex - startIndex); stringHtml = stringHtml.Replace(stringToBeReplaced, ""); string link = "http://cha-en-pdp2:2108/?pUserCompanyName=CompanyNameVariable"; //change url to direct to user page stringHtml = stringHtml.Replace("linkToBeChanged", link); stringHtml = stringHtml.Replace("CompanyNameVariable", companyObj.DBCompanyName); stringHtml = stringHtml.Replace("customerNameVariable", subscriptionObj.DBName); stringHtml = stringHtml.Replace("EventNameVariable", CalObj.DBEventTitle); stringHtml = stringHtml.Replace("EventDetailsVariable", CalObj.DBEventDetails); stringHtml = stringHtml.Replace("EventStartTimeVariable", CalObj.DBEventStartTime.ToString()); stringHtml = stringHtml.Replace("EventEndTimeVariable", CalObj.DBEventEndTime.ToString()); performSubscriptionObj.sendEmail(subscriptionObj.DBEmail, null, "New Event Scheduled", stringHtml); } } return("Event Saved Sucessfully!!"); } catch (DbUpdateException exUpdateDB) { Console.Write(exUpdateDB); return("DbUpdateException"); } catch (DbEntityValidationException exEntityValidateDB) { Console.Write(exEntityValidateDB); return("DbEntityValidationException"); } catch (NotSupportedException exNotSupportedDB) { Console.Write(exNotSupportedDB); return("NotSupportedException"); } catch (ObjectDisposedException exObjectDisposedDB) { Console.Write(exObjectDisposedDB); return("ObjectDisposedException"); } catch (InvalidOperationException exInvalidOperationDB) { Console.Write(exInvalidOperationDB); return("InvalidOperationException"); } catch (Exception ex) { Console.Write(ex); return("Misllaneous Exception"); } }
public static void DeclineResource(int todoId) { UserLight cu = Security.CurrentUser; int UserId = cu.UserID; DateTime utc_now = DateTime.UtcNow; int CompletionTypeId; bool IsManagerConfirmed; bool IsCompleted; int ReasonId; int IncidentId = -1; int DocumentId = -1; int TaskId = -1; bool CompleteIncident = false; bool CompleteTask = false; bool CompleteDocument = false; int oldPercentCompleted = 0; string title = ""; using (IDataReader reader = DBToDo.GetToDo(todoId, cu.TimeZoneId, cu.LanguageId)) { reader.Read(); CompletionTypeId = (int)reader["CompletionTypeId"]; IsManagerConfirmed = (bool)reader["MustBeConfirmed"]; IsCompleted = (bool)reader["IsCompleted"]; ReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { IncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { DocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { TaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { CompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { CompleteDocument = (bool)reader["CompleteDocument"]; } oldPercentCompleted = (int)reader["PercentCompleted"]; title = reader["Title"].ToString(); } using (DbTransaction tran = DbTransaction.Begin()) { DbTodo2.ResourceReply(todoId, UserId, false); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, todoId, UserId); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestDenied, todoId, UserId); if (CompletionTypeId == (int)CompletionType.All) { int OverallPercent = ToDo.RecalculateOverallPercent(todoId); if (oldPercentCompleted != OverallPercent) { DBToDo.UpdatePercent(todoId, OverallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, todoId); } if (!IsCompleted && !IsManagerConfirmed && OverallPercent == 100) { DBToDo.UpdateCompletion(todoId, true, (int)CompletionReason.CompletedAutomatically); if (TaskId > 0 && CompleteTask) { ToDo.UpdateTaskCompletion(TaskId); } if (DocumentId > 0 && CompleteDocument) { ToDo.UpdateDocumentCompletion(DocumentId); } if (IncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(IncidentId); } ToDo.RecalculateState(todoId); } } tran.Commit(); } }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(objectId); } int todoCompletionTypeId; bool todoManagerConfirmed; bool todoIsCompleted; int todoReasonId; int todoIncidentId = -1; int todoDocumentId = -1; int todoTaskId = -1; int todoPercentCompleted = 0; bool CompleteIncident = false; bool todoCompleteTask = false; bool todoCompleteDocument = false; string todoTitle = ""; using (IDataReader reader = DBToDo.GetToDo(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); todoCompletionTypeId = (int)reader["CompletionTypeId"]; todoManagerConfirmed = (bool)reader["MustBeConfirmed"]; todoIsCompleted = (bool)reader["IsCompleted"]; todoReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { todoIncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { todoDocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { todoTaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { todoCompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { todoCompleteDocument = (bool)reader["CompleteDocument"]; } todoPercentCompleted = (int)reader["PercentCompleted"]; todoTitle = reader["Title"].ToString(); } ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBToDo.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBToDo.DeleteResource(objectId, id); // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.DeleteIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.DeleteDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.DeleteTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.DeleteTodoResourceRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool updated = true; if (add.Contains(id)) { DbTodo2.AddResource(objectId, id, mustBeConfirmed); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.AddIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.AddDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.AddTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.AddTodoResourceRole(objectId, id); } // } else { updated = (0 < DbTodo2.UpdateResource(objectId, id, mustBeConfirmed)); } if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (todoCompletionTypeId == (int)CompletionType.All) { int overallPercent = ToDo.RecalculateOverallPercent(objectId); if (todoPercentCompleted != overallPercent) { DBToDo.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, objectId); } // Если поручение было незавершённым, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение todo if (!todoIsCompleted && !todoManagerConfirmed && overallPercent == 100) { DBToDo.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); if (todoTaskId > 0 && todoCompleteTask) { ToDo.UpdateTaskCompletion(todoTaskId); } if (todoDocumentId > 0 && todoCompleteDocument) { ToDo.UpdateDocumentCompletion(todoDocumentId); } if (todoIncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(todoIncidentId); } ToDo.RecalculateState(objectId); } } tran.Commit(); } }
//function to send email for calender event subscription public void sendEmailForCalenderEvent(DBCalendar calObj, string pstrRecipientsEmailId, string pstrCCRecipientsEmailId, string pstrSubject, string pstrMessageBody, string pstrMessage, DateTime startTime, DateTime endTime, string actionToBeTaken) { ExchangeService objExchangeService = new ExchangeService(ExchangeVersion.Exchange2013); objExchangeService.Credentials = new WebCredentials("wse\\centraluser", "$abcd1234"); objExchangeService.UseDefaultCredentials = false; objExchangeService.Url = new Uri("https://mail.winshuttle.in/EWS/Exchange.asmx"); EmailMessage objMessage = new EmailMessage(objExchangeService); objMessage.ToRecipients.Add(pstrRecipientsEmailId); if (pstrCCRecipientsEmailId != null) { objMessage.CcRecipients.Add(pstrCCRecipientsEmailId); } objMessage.Subject = pstrSubject; objMessage.ReplyTo.Add(new EmailAddress("*****@*****.**")); objMessage.Body = new MessageBody(pstrMessageBody); objMessage.Body.BodyType = BodyType.HTML; Appointment appObj; if (actionToBeTaken == "Update") { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DateTime endDateLimit = contextObj.Database.SqlQuery <DateTime>("select DBEventEndTime from DBCalendar").Last(); CalendarFolder folder = CalendarFolder.Bind(objExchangeService, WellKnownFolderName.Calendar); CalendarView view = new CalendarView(DateTime.UtcNow, endDateLimit); FindItemsResults <Appointment> results = folder.FindAppointments(view); foreach (Appointment appointment in results) { if ((appointment.Subject == calObj.DBEventTitle) || (appointment.Start == calObj.DBEventStartTime) || (appointment.End == calObj.DBEventEndTime)) { appObj = Appointment.Bind(objExchangeService, appointment.Id, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Body, AppointmentSchema.Start, AppointmentSchema.End)); appObj.Subject = pstrSubject; appObj.Body = pstrMessage; appObj.Start = startTime; appObj.End = endTime; appObj.RequiredAttendees.Add(pstrRecipientsEmailId); appObj.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy); } } } else if (actionToBeTaken == "CreateNew") { appObj = new Appointment(objExchangeService); appObj.Subject = calObj.DBEventTitle; appObj.Body = calObj.DBEventDetails; appObj.Start = calObj.DBEventStartTime; appObj.End = calObj.DBEventEndTime; appObj.RequiredAttendees.Add(pstrRecipientsEmailId); appObj.Save(SendInvitationsMode.SendToAllAndSaveCopy); } else { WinMonitorEntityModelContext contextObj = new WinMonitorEntityModelContext(); DateTime endDateLimit = DateTime.Parse(contextObj.Database.SqlQuery <string>("select DBEventEndTime from DBCalendar").Last()); CalendarFolder folder = CalendarFolder.Bind(objExchangeService, WellKnownFolderName.Calendar); CalendarView view = new CalendarView(DateTime.UtcNow, endDateLimit); FindItemsResults <Appointment> results = folder.FindAppointments(view); foreach (Appointment appointment in results) { if ((appointment.Subject == calObj.DBEventTitle) || (appointment.Start == calObj.DBEventStartTime) || (appointment.End == calObj.DBEventEndTime)) { appObj = Appointment.Bind(objExchangeService, appointment.Id, new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Body, AppointmentSchema.Start, AppointmentSchema.End)); appObj.Delete(DeleteMode.HardDelete); } } } objMessage.Send(); }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanModifyResources(objectId); } int taskCompletionTypeId; bool taskMustBeConfirmed; bool taskIsCompleted; int taskReasonId; int taskProjectId; int taskPercentCompleted; using (IDataReader reader = DBTask.GetTask(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); taskCompletionTypeId = (int)reader["CompletionTypeId"]; taskMustBeConfirmed = (bool)reader["MustBeConfirmed"]; taskIsCompleted = (bool)reader["IsCompleted"]; taskReasonId = (int)reader["ReasonId"]; taskProjectId = (int)reader["ProjectId"]; taskPercentCompleted = (int)reader["PercentCompleted"]; } int managerId = DBProject.GetProjectManager(taskProjectId); ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBTask.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBTask.DeleteResource(objectId, id); // OZ: User Role Addon UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool canManage = (bool)row["CanManage"]; if (id == managerId) { canManage = true; } bool updated = true; if (add.Contains(id)) { DbTask2.AddResource(objectId, id, mustBeConfirmed, canManage); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } } else { updated = (0 < DbTask2.UpdateResource(objectId, id, mustBeConfirmed, canManage)); } // OZ: User Role Addon if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (canManage) { if (id != managerId) { UserRoleHelper.AddTaskManagerRole(objectId, id); } } else { UserRoleHelper.AddTaskResourceRole(objectId, id); } // if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (taskCompletionTypeId == (int)CompletionType.All) { int overallPercent = Task.RecalculateOverallPercent(objectId); if (taskPercentCompleted != overallPercent) { DBTask.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_Percent, objectId); } // Если задача была незавершённой, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение задачи if (!taskIsCompleted && !taskMustBeConfirmed && overallPercent == 100) { DBTask.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); Task.CompleteToDo(objectId); Task.RecalculateAllStates(taskProjectId); } DBTask.RecalculateSummaryPercent(objectId); } tran.Commit(); } }