예제 #1
0
        public TaskPropertyChange InsertOrUpdate(Task task)
        {
            TaskPropertyChange change = new TaskPropertyChange();
           //bool isStatusChanged = false;
            if (task.TaskID == default(long))
            {
                // New entity
                context.Tasks.Add(task);

            }
            else
            {
                // Existing entity
                var existingTask = context.Tasks.Include("Users")
                   .Where(t => t.TaskID == task.TaskID).FirstOrDefault<Task>();

                if (task.ProjectStatusID != existingTask.ProjectStatusID)
                {
                    change.IsSatausChanged = true;
                    if (existingTask.ProjectStatusID == null)
                    {
                        change.FromSataus = "undefined";
                    }
                    else
                    {
                        ProjectStatus stat = context.ProjectStatuses.Where(s => s.ProjectStatusID == existingTask.ProjectStatusID).FirstOrDefault();
                        change.FromSataus = stat.Name;
                    }
                    if (task.ProjectStatusID == null)
                    {
                        change.ToStatus = "undefined";
                    }
                    else
                    {
                        ProjectStatus stat = context.ProjectStatuses.Where(s => s.ProjectStatusID == task.ProjectStatusID).FirstOrDefault();
                        change.ToStatus = stat.Name;
                    }
                }
                if (task.StartDate != existingTask.StartDate)
                {
                    change.IsStartDateChanged = true;
                    
                    change.FromSatrtDate = existingTask.StartDate;
                    
                    change.ToSatrtDate = task.StartDate;
                    
                }
                if (task.EndDate != existingTask.EndDate)
                {
                    change.IsEndtDateChanged = true;

                    change.FromEndDate = existingTask.EndDate;

                    change.ToEndDate = task.EndDate;
                }
                UpdateAssignedUsers(task, existingTask);

                UpdateFollowers(task, existingTask);

                UpdateLabels(task, existingTask);
                context.Entry(existingTask).CurrentValues.SetValues(task);

                ImplementDragDropRules(task);

            }
            return change;
        }
예제 #2
0
        private void SaveNotification(Task task, bool isTaskInsert, bool isSubTask, TaskPropertyChange change)
        {
            #region Old
            //string phrase = "";
            //if (task.Users.Count >0)
            //{
            //    foreach (User user in task.Users)
            //    {

            //        Notification notification = new Notification();
            //        if (isTaskInsert)
            //        {
            //            if (!isSubTask)
            //            {
            //                phrase = " Has assigned " + user.FirstName + " " + user.LastName + " on the Task --";
            //            }
            //            else
            //            {
            //                phrase = " Has assigned  " + user.FirstName + " " + user.LastName + "  on the Subtask --";
            //            }

            //            User createdUser = unitOfWork.UserRepository.GetUserByUserID(task.CreatedBy);
            //            notification.Title = createdUser.FirstName + " " + createdUser.LastName + phrase +" "+ task.Title;


            //        }
            //        else
            //        {
            //            User modifiedUser = unitOfWork.UserRepository.GetUserByUserID((int)Membership.GetUser(WebSecurity.CurrentUserName).ProviderUserKey);
            //            phrase = phrase + modifiedUser.FirstName + " " + modifiedUser.LastName + " ";
            //            if (!change.IsSatausChanged)
            //            {
            //                if (!isSubTask)
            //                {
            //                    phrase = phrase + " Has modify the Task --";
            //                }
            //                else
            //                {
            //                    phrase = phrase + " Has modify the Subtask --";
            //                }
            //            }
            //            else
            //            {
            //                string status = "";
            //                if (!isSubTask)
            //                {
            //                    if (task.ProjectStatusID != null)
            //                    {
            //                        ProjectStatus col = unitOfWork.ProjectStatusRepository.Find(Convert.ToInt64(task.ProjectStatusID));
            //                        status = col.Name;
            //                    }
            //                    phrase = phrase + string.Format(" Has changed the task status to {0} --", status);
            //                }
            //                else
            //                {
            //                    phrase = phrase + string.Format(" Has changed the subtask status to {0} --", status);
            //                }
            //            }

            //            if (!change.IsStartDateChanged)
            //            {
            //                string date = "";
            //                if (task.StartDate != null)
            //                {
            //                    date = task.StartDate.Value.ToShortDateString();
            //                }
            //                else
            //                {
            //                    date = "not defined";
            //                }
            //                if (!isSubTask)
            //                {

            //                    phrase = phrase + string.Format(" Has changed the task Start Date to {0} --", date);
            //                }
            //                else
            //                {
            //                    phrase = phrase + string.Format(" Has changed the subtask Start Date to {0} --", date);
            //                }
            //            }

            //            if (!change.IsEndtDateChanged)
            //            {
            //                string date = "";
            //                if (task.EndDate != null)
            //                {
            //                    date = task.EndDate.Value.ToShortDateString();
            //                }
            //                else
            //                {
            //                    date = "not defined";
            //                }
            //                if (!isSubTask)
            //                {

            //                    phrase = phrase + string.Format(" Has changed the task End Date to {0} --", date);
            //                }
            //                else
            //                {
            //                    phrase = phrase + string.Format(" Has changed the subtask End Date to {0} --", date);
            //                }
            //            }

            //            //User modifiedUser = unitOfWork.UserRepository.GetUserByUserID(task.ModifiedBy);
            //            notification.Title = phrase + task.Title;
            //        }
            //        notification.UserID = user.UserId;
            //        notification.Description = notification.Title;
            //        notification.ProjectID = task.ProjectID;
            //        notification.TaskID = task.TaskID;
            //        unitOfWork.NotificationRepository.InsertOrUpdate(notification);

            //        try
            //        {
            //            string logComment = phrase;
            //            logComment = logComment + "on " + DateTime.Now.ToShortDateString();
            //            TaskActivityLog log = unitOfWork.TaskActivityLogRepository.FindByTaskID(task.TaskID);
            //            if (log == null)
            //            {
            //                TaskActivityLog logNew = new TaskActivityLog();
            //                logNew.TaskID = task.TaskID;
            //                logNew.Comment = phrase;
            //                logNew.CreateDate = DateTime.Now;
            //                logNew.ModificationDate = DateTime.Now;
            //                unitOfWork.TaskActivityLogRepository.InsertOrUpdate(logNew);
            //                unitOfWork.Save();
            //            }
            //            else
            //            {
            //                log.Comment = log.Comment + " ; " + logComment;
            //                unitOfWork.Save();
            //            }
            //        }
            //        catch
            //        {
            //        }

            //        unitOfWork.Save();
            //    }
            //}
            //if (task.Followers.Count>0)
            //{
            //    foreach (User user in task.Followers)
            //    {
            //        Notification notification = new Notification();
            //        if (isTaskInsert)
            //        {
            //            if (!isSubTask)
            //            {
            //                phrase = " Has added  " + user.FirstName + " " + user.LastName + "  as a follower on the Task --";
            //            }
            //            else
            //            {
            //                phrase = " Has added  " + user.FirstName + " " + user.LastName + "  as a follower on the Subtask --";
            //            }
            //            User createdUser = unitOfWork.UserRepository.GetUserByUserID(task.CreatedBy);
            //            notification.Title = createdUser.FirstName + " " + createdUser.LastName + " " + phrase + task.Title;
            //        }
            //        else
            //        {
            //            if (!isSubTask)
            //            {
            //                phrase = " Has modify the Task --";
            //            }
            //            else
            //            {
            //                phrase = " Has modify the Subtask --";
            //            }
            //            User modifiedUser = unitOfWork.UserRepository.GetUserByUserID(task.ModifiedBy);
            //            notification.Title = modifiedUser.FirstName + " " + modifiedUser.LastName +" "+ phrase + task.Title;
            //        }

            //        if (!change.IsSatausChanged)
            //        {
            //            if (!isSubTask)
            //            {
            //                phrase = phrase + " Has modify the Task --";
            //            }
            //            else
            //            {
            //                phrase = phrase + " Has modify the Subtask --";
            //            }
            //        }
            //        else
            //        {
            //            string status = "";
            //            if (!isSubTask)
            //            {
            //                if (task.ProjectStatusID != null)
            //                {
            //                    ProjectStatus col = unitOfWork.ProjectStatusRepository.Find(Convert.ToInt64(task.ProjectStatusID));
            //                    status = col.Name;
            //                }
            //                phrase = phrase + string.Format(" Has changed the task status to {0} --", status);
            //            }
            //            else
            //            {
            //                phrase = phrase + string.Format(" Has changed the subtask status to {0} --", status);
            //            }
            //        }

            //        if (!change.IsStartDateChanged)
            //        {
            //            string date = "";
            //            if (task.StartDate != null)
            //            {
            //                date = task.StartDate.Value.ToShortDateString();
            //            }
            //            else
            //            {
            //                date = "not defined";
            //            }
            //            if (!isSubTask)
            //            {

            //                phrase = phrase + string.Format(" Has changed the task Start Date to {0} --", date);
            //            }
            //            else
            //            {
            //                phrase = phrase + string.Format(" Has changed the subtask Start Date to {0} --", date);
            //            }
            //        }

            //        if (!change.IsEndtDateChanged)
            //        {
            //            string date = "";
            //            if (task.EndDate != null)
            //            {
            //                date = task.EndDate.Value.ToShortDateString();
            //            }
            //            else
            //            {
            //                date = "not defined";
            //            }
            //            if (!isSubTask)
            //            {

            //                phrase = phrase + string.Format(" Has changed the task End Date to {0} --", date);
            //            }
            //            else
            //            {
            //                phrase = phrase + string.Format(" Has changed the subtask End Date to {0} --", date);
            //            }
            //        }

            //        notification.UserID = user.UserId;
            //        notification.Description = notification.Title;
            //        notification.ProjectID = task.ProjectID;
            //        notification.TaskID = task.TaskID;
            //        unitOfWork.NotificationRepository.InsertOrUpdate(notification);

            //        try
            //        {
            //            string logComment = phrase;
            //            logComment = logComment + "on " + DateTime.Now.ToShortDateString();
            //            TaskActivityLog log = unitOfWork.TaskActivityLogRepository.FindByTaskID(task.TaskID);
            //            if (log == null)
            //            {
            //                TaskActivityLog logNew = new TaskActivityLog();
            //                logNew.TaskID = task.TaskID;
            //                logNew.Comment = phrase;
            //                logNew.CreateDate = DateTime.Now;
            //                logNew.ModificationDate = DateTime.Now;
            //                unitOfWork.TaskActivityLogRepository.InsertOrUpdate(logNew);
            //                unitOfWork.Save();
            //            }
            //            else
            //            {
            //                log.Comment = log.Comment + " ; " + logComment;
            //                unitOfWork.Save();
            //            }
            //        }
            //        catch
            //        {
            //        }

            //        unitOfWork.Save();
            //    }
            //}
            //if (task.Users.Count == 0 && task.Followers.Count == 0)
            //{
            //    try
            //    {
            //        if (phrase != "")
            //        {
            //            User modifiedUser = unitOfWork.UserRepository.GetUserByUserID((int)Membership.GetUser(WebSecurity.CurrentUserName).ProviderUserKey);
            //            string logComment = phrase;
            //            logComment = logComment + "on " + DateTime.Now.ToShortDateString();
            //            TaskActivityLog log = unitOfWork.TaskActivityLogRepository.FindByTaskID(task.TaskID);
            //            if (log == null)
            //            {
            //                TaskActivityLog logNew = new TaskActivityLog();
            //                logNew.TaskID = task.TaskID;
            //                logNew.Comment = modifiedUser.FirstName + " " + modifiedUser.LastName + " Created the task " + task.Title + " on " + DateTime.Now.ToShortDateString();
            //                logNew.CreateDate = DateTime.Now;
            //                logNew.ModificationDate = DateTime.Now;
            //                unitOfWork.TaskActivityLogRepository.InsertOrUpdate(logNew);
            //                unitOfWork.Save();
            //            }
            //            else
            //            {
            //                log.Comment = log.Comment + " ; " + logComment;
            //                unitOfWork.Save();
            //            }
            //        }
            //    }
            //    catch
            //    {
            //    }
            //}
            #endregion

            # region if Insert