コード例 #1
0
        public DataResponse SaveDueDate(DateTime TargetDate, int TaskId, int currentUserID)
        {
            var response = new DataResponse();

            try
            {
                base.DBInit();
                var model = DBEntity.Tasks.FirstOrDefault(a => a.Id == TaskId);
                if (model != null)
                {
                    model.TargetDate = TargetDate;
                    model.UpdatedBy  = currentUserID;
                    model.UpdatedOn  = DateTime.UtcNow;

                    if (base.DBSaveUpdate(model) == 1)
                    {
                        var objTask = new Database.Task
                        {
                            Id                = model.Id,
                            RequestedBy       = model.RequestedBy,
                            Subject           = model.Subject,
                            TaskDescription   = model.TaskDescription,
                            BusinessId        = model.BusinessId,
                            TaskRequestTypeId = model.TaskRequestTypeId,
                            ReferenceNumber   = model.ReferenceNumber,
                            PracticeId        = model.PracticeId,
                            PriorityTypeId    = model.PriorityTypeId,
                            TargetDate        = model.TargetDate,
                            ClosingDate       = model.ClosingDate,
                            IsActive          = model.IsActive,
                            Status            = model.Status,
                            TaskUsers         = model.TaskUsers,
                            TaskUserAlerts    = model.TaskUserAlerts,
                            User              = model.User,
                            CreatedOn         = model.UpdatedOn.Value,
                            CreatedBy         = model.UpdatedBy.Value
                        };
                        SaveLog(objTask);
                        response.Status = DataResponseStatus.OK;
                    }
                    else
                    {
                        response.Status = DataResponseStatus.NotModified;
                    }
                }
                else
                {
                    response.Status = DataResponseStatus.NotModified;
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
コード例 #2
0
        public bool SaveLog(Database.Task taskModel, string action = "Updated")
        {
            base.DBInit();

            if (taskModel != null)
            {
                DateTime?AlertDate = null;
                if (taskModel.TaskUserAlerts != null && taskModel.TaskUserAlerts.Count() > 0)
                {
                    AlertDate = taskModel.TaskUserAlerts.FirstOrDefault().AlertDate;
                }
                var logModel = new Database.TaskLog
                {
                    AlertDate         = AlertDate,
                    TaskId            = taskModel.Id,
                    RequestedBy       = taskModel.RequestedBy,
                    Subject           = taskModel.Subject,
                    TaskDescription   = taskModel.TaskDescription,
                    BusinessId        = taskModel.BusinessId,
                    TaskRequestTypeId = taskModel.TaskRequestTypeId,
                    ReferenceNumber   = taskModel.ReferenceNumber,
                    PracticeId        = taskModel.PracticeId,
                    PriorityTypeId    = taskModel.PriorityTypeId,
                    TargetDate        = taskModel.TargetDate,
                    ClosingDate       = taskModel.ClosingDate,
                    IsActive          = taskModel.IsActive,
                    Status            = taskModel.Status,
                    Action            = action,
                    CreatedOn         = taskModel.CreatedOn,
                    CreatedBy         = taskModel.CreatedBy
                };

                if (taskModel.TaskUsers != null)
                {
                    foreach (var taskUser in taskModel.TaskUsers)
                    {
                        var objUser = DBEntity.Users.FirstOrDefault(a => a.Id == taskUser.UserId);

                        if (taskUser.IsWatcher.HasValue && taskUser.IsWatcher.Value)
                        {
                            logModel.Watchers = string.Format("{0}{1}", string.IsNullOrEmpty(logModel.Watchers) ? string.Empty : logModel.Watchers + ",",
                                                              string.Format("{{\"Name\":\"{0} {1}\",\"Id\":{2}}}", objUser.FirstName, objUser.LastName, objUser.Id));
                        }
                        else
                        {
                            logModel.AssignedTo = string.Format("{{\"Name\":\"{0} {1}\",\"Id\":{2}}}", objUser.FirstName, objUser.LastName, objUser.Id);
                        }
                    }
                }

                logModel.Watchers   = string.Format("[{0}]", logModel.Watchers);
                logModel.AssignedTo = string.Format("[{0}]", logModel.AssignedTo);

                return(base.DBSave(logModel) > 0);
            }

            return(false);
        }
コード例 #3
0
        public DataResponse ToggleStatus(int TaskId, int currentUserID, bool hasDeletePermission)
        {
            var response = new DataResponse <bool?>();

            try
            {
                base.DBInit();
                var model = DBEntity.Tasks.FirstOrDefault(a => a.Id == TaskId);
                model.UpdatedBy = currentUserID;
                model.UpdatedOn = DateTime.UtcNow;
                if (model != null && (hasDeletePermission || currentUserID == model.User.Id))
                {
                    model.IsActive = (model.IsActive == false) ? true : false;
                }
                if (base.DBSaveUpdate(model) == 1)
                {
                    var objTask = new Database.Task
                    {
                        Id                = model.Id,
                        RequestedBy       = model.RequestedBy,
                        Subject           = model.Subject,
                        TaskDescription   = model.TaskDescription,
                        BusinessId        = model.BusinessId,
                        TaskRequestTypeId = model.TaskRequestTypeId,
                        ReferenceNumber   = model.ReferenceNumber,
                        PracticeId        = model.PracticeId,
                        PriorityTypeId    = model.PriorityTypeId,
                        TargetDate        = model.TargetDate,
                        ClosingDate       = model.ClosingDate,
                        IsActive          = model.IsActive,
                        Status            = model.Status,
                        TaskUsers         = model.TaskUsers,
                        TaskUserAlerts    = model.TaskUserAlerts,
                        User              = model.User,
                        CreatedOn         = model.UpdatedOn.Value,
                        CreatedBy         = model.UpdatedBy.Value
                    };
                    SaveLog(objTask);
                    response.Model = model.IsActive;
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
コード例 #4
0
        public DataResponse SetStatus(int Taskid, int StatusId, int currentUserID, string updatedByName)
        {
            var response = new DataResponse <int?>();

            try
            {
                base.DBInit();
                var model = DBEntity.Tasks.FirstOrDefault(a => a.Id == Taskid);

                model.UpdatedBy = currentUserID;
                model.UpdatedOn = DateTime.UtcNow;
                model.Status    = StatusId;

                if (base.DBSaveUpdate(model) > 0)
                {
                    var objTask = new Database.Task
                    {
                        Id                = model.Id,
                        RequestedBy       = model.RequestedBy,
                        Subject           = model.Subject,
                        TaskDescription   = model.TaskDescription,
                        BusinessId        = model.BusinessId,
                        TaskRequestTypeId = model.TaskRequestTypeId,
                        ReferenceNumber   = model.ReferenceNumber,
                        PracticeId        = model.PracticeId,
                        PriorityTypeId    = model.PriorityTypeId,
                        TargetDate        = model.TargetDate,
                        ClosingDate       = model.ClosingDate,
                        IsActive          = model.IsActive,
                        Status            = model.Status,
                        TaskUsers         = model.TaskUsers,
                        TaskUserAlerts    = model.TaskUserAlerts,
                        User              = model.User,
                        CreatedOn         = model.UpdatedOn.Value,
                        CreatedBy         = model.UpdatedBy.Value
                    };
                    SaveLog(objTask);
                    response.Model = model.Status;

                    #region Save Notification Data

                    var notificationlist = new List <EntityNotification>();

                    notificationlist = model.TaskUsers.Select(a => new EntityNotification
                    {
                        UserId  = a.UserId,
                        Message = NotificationMessages.TaskStatusUpdateUserNotification
                    }).ToList();


                    notificationlist.Add(new EntityNotification
                    {
                        UserId  = model.CreatedBy,
                        Message = NotificationMessages.TaskStatusUpdateUserNotification
                    });

                    new RepositoryNotification().Save(notificationlist, currentUserID, model.Id, (int)NotificationTargetType.Task, (int)NotificationType.Normal, model.CreatedBy, updatedByName, model.CreatedOn, model.Subject);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
コード例 #5
0
        public DataResponse Update(EntityTask entity)
        {
            var response = new DataResponse <EntityTask>();

            try
            {
                base.DBInit();

                entity.UpdatedOn = DateTime.UtcNow;

                #region Prepare model
                var model = DBEntity.Tasks.FirstOrDefault(a => a.Id == entity.TaskId);

                model.RequestedBy       = entity.CurrentUserId;
                model.Subject           = entity.Subject;
                model.PracticeId        = entity.PracticeId;
                model.TaskDescription   = entity.TaskDescription;
                model.PriorityTypeId    = entity.PriorityTypeId;
                model.TaskRequestTypeId = entity.TaskRequestTypeId;
                model.TargetDate        = entity.TargetDate;
                model.ClosingDate       = entity.ClosingDate;
                model.UpdatedOn         = entity.UpdatedOn;
                model.UpdatedBy         = entity.UpdatedBy;

                List <EntityNotification> notificationlist = new List <EntityNotification>();
                if (model.Status != entity.StatusId)
                {
                    model.Status = entity.StatusId;
                }
                //    notificationlist = model.TaskUsers.Where(a => a.UserId != entity.CurrentUserId).Select(a => new EntityNotification
                //    {
                //        UserId = a.UserId,
                //        Message = NotificationMessages.TaskStatusUpdateUserNotification
                //    }).ToList();

                //    if (model.CreatedBy != entity.CurrentUserId)
                //        notificationlist.Add(new EntityNotification
                //        {
                //            UserId = model.CreatedBy,
                //            Message = NotificationMessages.TaskStatusUpdateUserNotification
                //        });
                //}
                if (entity.AlertDate.HasValue)
                {
                    var modelItem = model.TaskUserAlerts.FirstOrDefault(a => a.UserId == entity.CurrentUserId);
                    if (modelItem != null)
                    {
                        DBEntity.Entry(modelItem).State = EntityState.Modified;

                        modelItem.AlertDate = entity.AlertDate.Value;
                        modelItem.Message   = entity.AlertMessage;
                        modelItem.UpdatedOn = entity.UpdatedOn;
                        modelItem.UpdatedBy = entity.UpdatedBy;
                    }
                    else
                    {
                        var taskUserAlerts = new Database.TaskUserAlert
                        {
                            TaskId    = model.Id,
                            UserId    = entity.CurrentUserId,
                            AlertDate = entity.AlertDate.Value,
                            Message   = entity.AlertMessage,
                            CreatedOn = entity.UpdatedOn.Value,
                            CreatedBy = entity.UpdatedBy.Value,
                        };
                        model.TaskUserAlerts.Add(taskUserAlerts);
                    }
                }

                //delete all previous assignments
                DBEntity.TaskUsers.Where(a => a.TaskId == model.Id).Delete();

                if (entity.AssignedTo > 0)
                {
                    model.TaskUsers.Add(new Database.TaskUser
                    {
                        UserId    = entity.AssignedTo,
                        IsWatcher = false,
                        CreatedOn = entity.UpdatedOn.Value,
                        CreatedBy = entity.UpdatedBy.Value
                    });

                    //    if (entity.CurrentUserId != entity.AssignedTo)
                    notificationlist.Add(new EntityNotification
                    {
                        UserId  = entity.AssignedTo,
                        Message = NotificationMessages.TaskUpdateUserNotification
                    });
                }

                if (entity.Watchers != null)
                {
                    foreach (var user in entity.Watchers)
                    {
                        model.TaskUsers.Add(new Database.TaskUser
                        {
                            UserId    = int.Parse(user),
                            IsWatcher = true,
                            CreatedOn = entity.UpdatedOn.Value,
                            CreatedBy = entity.UpdatedBy.Value
                        });

                        notificationlist.Add(new EntityNotification
                        {
                            UserId  = int.Parse(user),
                            Message = NotificationMessages.TaskUpdateUserNotification
                        });
                    }
                }

                notificationlist.Add(new EntityNotification
                {
                    UserId  = model.CreatedBy,
                    Message = NotificationMessages.TaskUpdateUserNotification
                });
                #endregion

                #region Delete removed files from db on update

                IEnumerable <int> incomingFileLists = null;
                IEnumerable <Database.TaskAttachment> existingFiles = null;

                if (entity.FilesList != null && entity.FilesList.Count() > 0)
                {
                    incomingFileLists = entity.FilesList.Select(a => a.Id);
                }
                if (incomingFileLists != null && incomingFileLists.Count() > 0)
                {
                    existingFiles = model.TaskAttachments.Where(a => !incomingFileLists.Contains(a.Id));
                }
                else
                {
                    existingFiles = model.TaskAttachments;
                }

                if (existingFiles.Count() > 0)
                {
                    foreach (var item in existingFiles)
                    {
                        item.IsActive = false;
                    }
                }

                #endregion

                if (base.DBSaveUpdate(model) > 0)
                {
                    #region Save Notification Data

                    new RepositoryNotification().Save(notificationlist, entity.CurrentUserId, model.Id, (int)NotificationTargetType.Task, (int)NotificationType.Normal, model.UpdatedBy.Value, entity.CreatedByName, model.UpdatedOn.Value, model.Subject);

                    #endregion

                    #region Save to Log
                    var objTask = new Database.Task
                    {
                        Id                = model.Id,
                        RequestedBy       = entity.CurrentUserId,
                        Subject           = model.Subject,
                        TaskDescription   = model.TaskDescription,
                        BusinessId        = model.BusinessId,
                        TaskRequestTypeId = model.TaskRequestTypeId,
                        ReferenceNumber   = model.ReferenceNumber,
                        PracticeId        = model.PracticeId,
                        PriorityTypeId    = model.PriorityTypeId,
                        TargetDate        = model.TargetDate,
                        ClosingDate       = model.ClosingDate,
                        IsActive          = model.IsActive,
                        Status            = model.Status,
                        TaskUsers         = model.TaskUsers,
                        TaskUserAlerts    = model.TaskUserAlerts,
                        User              = model.User,
                        CreatedOn         = model.UpdatedOn.Value,
                        CreatedBy         = model.UpdatedBy.Value
                    };

                    if (!SaveLog(objTask))
                    {
                        new Exception("Task log failed!  Task:" + entity.TaskId).Log();
                    }
                    #endregion

                    //return GetTaskById(model.Id, entity.CurrentUserId, entity.CurrentBusinessId);
                    return(new DataResponse {
                        Status = DataResponseStatus.OK, Id = model.Id
                    });
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
コード例 #6
0
        public DataResponse <EntityTask> Insert(EntityTask entity)
        {
            var response = new DataResponse <EntityTask>();

            try
            {
                base.DBInit();

                var model = new Database.Task
                {
                    RequestedBy       = entity.CurrentUserId,
                    Subject           = entity.Subject,
                    TaskDescription   = entity.TaskDescription,
                    BusinessId        = entity.CurrentBusinessId,
                    TaskRequestTypeId = entity.TaskRequestTypeId,
                    PracticeId        = entity.PracticeId,
                    PriorityTypeId    = entity.PriorityTypeId,
                    TargetDate        = entity.TargetDate,
                    ClosingDate       = entity.ClosingDate,
                    IsActive          = true,
                    Status            = (int)TaskStatuses.New,
                    CreatedOn         = entity.CreatedOn,
                    CreatedBy         = entity.CreatedBy,
                    UpdatedOn         = entity.UpdatedOn,
                    UpdatedBy         = entity.UpdatedBy
                };

                if (entity.AlertDate.HasValue)
                {
                    var taskUserAlerts = new List <Database.TaskUserAlert> {
                        new Database.TaskUserAlert
                        {
                            UserId    = entity.CurrentUserId,
                            AlertDate = entity.AlertDate.Value,
                            Message   = entity.AlertMessage,
                            CreatedOn = entity.CreatedOn,
                            CreatedBy = entity.CreatedBy,
                        }
                    };
                    model.TaskUserAlerts = taskUserAlerts;
                }
                var notificationlist = new List <EntityNotification>();

                if (entity.AssignedTo > 0)
                {
                    model.TaskUsers.Add(new Database.TaskUser
                    {
                        UserId    = entity.AssignedTo,
                        IsWatcher = false,
                        CreatedOn = entity.CreatedOn,
                        CreatedBy = entity.CreatedBy
                    });

                    notificationlist.Add(new EntityNotification
                    {
                        UserId  = entity.AssignedTo,
                        Message = NotificationMessages.TaskUserNotification
                    });
                }

                if (entity.Watchers != null)
                {
                    foreach (var user in entity.Watchers)
                    {
                        model.TaskUsers.Add(new Database.TaskUser
                        {
                            UserId    = int.Parse(user),
                            IsWatcher = true,
                            CreatedOn = entity.CreatedOn,
                            CreatedBy = entity.CreatedBy
                        });

                        notificationlist.Add(new EntityNotification
                        {
                            UserId  = int.Parse(user),
                            Message = NotificationMessages.TaskUserNotification
                        });
                    }
                }

                if (base.DBSave(model) > 0)
                {
                    #region Save Notification Data

                    new RepositoryNotification().Save(notificationlist, entity.CurrentUserId, model.Id, (int)NotificationTargetType.Task, (int)NotificationType.Normal, model.CreatedBy, entity.CreatedByName, model.CreatedOn, model.Subject);

                    #endregion

                    #region Save to Log

                    var objTask = new Database.Task
                    {
                        Id                = model.Id,
                        RequestedBy       = model.RequestedBy,
                        Subject           = model.Subject,
                        TaskDescription   = model.TaskDescription,
                        BusinessId        = model.BusinessId,
                        TaskRequestTypeId = model.TaskRequestTypeId,
                        ReferenceNumber   = model.ReferenceNumber,
                        PracticeId        = model.PracticeId,
                        PriorityTypeId    = model.PriorityTypeId,
                        TargetDate        = model.TargetDate,
                        ClosingDate       = model.ClosingDate,
                        IsActive          = model.IsActive,
                        Status            = model.Status,
                        TaskUsers         = model.TaskUsers,
                        TaskUserAlerts    = model.TaskUserAlerts,
                        User              = model.User,
                        CreatedOn         = model.CreatedOn,
                        CreatedBy         = model.CreatedBy
                    };

                    if (!SaveLog(objTask, "Created"))
                    {
                        new Exception("Task log failed!  Task:" + entity.TaskId).Log();
                    }

                    #endregion

                    return(GetTaskById(model.Id, entity.CurrentUserId, entity.CurrentBusinessId));
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }