public IDelta<ITask> CreateTask()
        {

            TaskObject task = new TaskObject();

            task.Manager = new UserObject(userContext.Logged);

            task.ToEmployee = null;

            task.Priority = new TaskPriority(clsService.GetPriority(PriorityCode.Medium));


            task.StartDateTime = task.CreatedDateTime;
            task.EndDateTime   = task.CreatedDateTime.AddDays(1);


            return new Delta<ITask>(task).AsNewTask();
             
        }
        public IDelta<ITask> AddTask(ITask task)
        {

            TaskObject taskPtr;

            IDelta<ITask> result = new Delta<ITask>(taskPtr = new TaskObject(task));


            if (string.IsNullOrWhiteSpace(task.Objective))
            {
                result.ApplyThrowError(x => x.Objective);
            }

            if (string.IsNullOrWhiteSpace(task.Name))
            {
                result.ApplyThrowError(x => x.Name);
            }

            if (task.StartDateTime > task.EndDateTime || task.StartDateTime ==DateTime.MinValue || task.EndDateTime == DateTime.MinValue)
            {
                result.ApplyThrowError(x => x.StartDateTime)
                      .ApplyThrowError(x => x.EndDateTime  );
            }


            if (result.HasErrors)
            {
                return result.AsNewTask();
            }



            taskPtr.Id = Guid.NewGuid();

            taskPtr.CreatedDateTime = DateTime.Now;
            taskPtr.Author          = new UserObject(userContext.Logged);

            taskPtr.Status = new TaskStatus(clsService.GetStatus(StatusCode.Pending));


            if (task.ToEmployee == null)
            {
                taskPtr.ToEmployee = taskPtr.Author;
            }

            if (task.Manager==null)
            {
                taskPtr.Manager = taskPtr.Author;
            }



            result
                .AcceptUpdate(x=>x.Id)
                .AcceptUpdate(x=>x.Status)
                .AcceptUpdate(x=>x.Priority)
                .AcceptUpdate(x => x.Name)
                .AcceptUpdate(x=>x.Objective)
                .AcceptUpdate(x=>x.Author)
                .AcceptUpdate(x=>x.Manager)
                .AcceptUpdate(x=>x.ToEmployee)
                .AcceptUpdate(x=>x.CreatedDateTime)
                .AcceptUpdate(x=>x.StartDateTime)
                .AcceptUpdate(x => x.EndDateTime);

            return repositoryContext
                   .InsertTask(result)
                   .ToDelta   ();
        }
Ejemplo n.º 3
0
        public TaskObject(ITask outer)
        {
            CreatedDateTime = outer.CreatedDateTime;
            Name = outer.Name; 
            Objective = outer.Objective;


            if (outer.Author != null)
            {
                Author = new UserObject(outer.Author);
            }

            if (outer.Manager != null)
            {
                Manager = new UserObject(outer.Manager);
            }


            if (outer.Status != null)
            {
                Status = new TaskStatus(outer.Status);
            }

            if (outer.Priority != null)
            {
                Priority = new TaskPriority(outer.Priority);
            }


            if (outer.ToEmployee != null)
            {
                ToEmployee = new UserObject(outer.ToEmployee);
            }


            StartDateTime = outer.StartDateTime;
            EndDateTime = outer.EndDateTime;

            Description = outer.Description;
            Result = outer.Result;

            if (outer.RootTask != null)
            {
                RootTask = new TaskObject(outer.RootTask);
            }

            if (outer.SubTasks != null)
            {
                SubTasks = outer.SubTasks.Select(x => new TaskObject(x)).ToArray();
            }
        }