Пример #1
0
        /// <summary>
        /// SaveUserTask
        /// </summary>
        /// <param name="userTask"></param>
        public void SaveUserTask(UserTask userTask)
        {
            if (userTask.TaskId.Equals(0)) // New Task
            {
                userTask.CreatedById = UserContextDetails.UserId;
                userTask.CreatedOn   = DateTime.UtcNow;
                eCollabroDbContext.Repository <UserTask>().Insert(userTask);
                eCollabroDbContext.Save();
            }
            else
            {
                UserTask oldUserTask = eCollabroDbContext.Repository <UserTask>().Find(userTask.TaskId);
                if (oldUserTask != null)
                {
                    UserTask beforeUpdate = Mapper.Map <UserTask, UserTask>(oldUserTask);
                    if (userTask.AssignedUserId.HasValue && oldUserTask.AssignedUserId != userTask.AssignedUserId)
                    {
                        UserRole userRole = eCollabroDbContext.Repository <UserRole>().Query().Filter(qry => qry.UserId.Equals(userTask.AssignedUserId.Value) && qry.SiteId.Equals(UserContextDetails.SiteId)).Get().FirstOrDefault();
                        if (userRole == null) // assigned user not exist on site
                        {
                            throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UserNotAssignedToSite), CoreValidationMessagesConstants.UserNotAssignedToSite);
                        }
                        else
                        {
                            oldUserTask.AssignedUserId   = userTask.AssignedUserId;
                            oldUserTask.AssignedByUserId = UserContextDetails.UserId;
                            oldUserTask.AssignedDate     = DateTime.UtcNow;
                        }
                    }

                    oldUserTask.CompletionPercentage = userTask.CompletionPercentage;
                    if (userTask.TaskStatus.Equals("Complete") || userTask.TaskStatus.Equals("Approved") || userTask.TaskStatus.Equals("Rejected"))
                    {
                        oldUserTask.CompletionDate       = DateTime.UtcNow;
                        oldUserTask.CompletionPercentage = 100;
                        oldUserTask.IsActive             = false;
                    }
                    else
                    {
                        oldUserTask.IsActive = true;
                    }
                    oldUserTask.TaskStatus = userTask.TaskStatus;
                    userTask.ModifiedById  = UserContextDetails.UserId;
                    userTask.ModifiedOn    = DateTime.UtcNow;
                    eCollabroDbContext.Save();
                    // raise event to Context for handling task updated
                    IWorkflowEventHandler workflowEventHandler = WorkFlowEventHandler((ContextEnum)userTask.ContextId);
                    workflowEventHandler.TaskUpdated(beforeUpdate, oldUserTask);
                }
                else
                {
                    throw new DBConcurrencyException();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// WorkFlowEventHandler
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public IWorkflowEventHandler WorkFlowEventHandler(ContextEnum context)
        {
            IWorkflowEventHandler workflowEventHandler = null;

            if (context.Equals(ContextEnum.Blog) || context.Equals(ContextEnum.Document) || context.Equals(ContextEnum.Image) || context.Equals(ContextEnum.ContentPage))
            {
                workflowEventHandler = new ContentManager();
            }
            else
            {
                return(null);
            }
            return(workflowEventHandler);
        }