Exemple #1
0
        public TaskWorklogCreate(TaskWorklogCreateRequest request)
        {
            if (request != null)
            {
                if (request.StartDate > request.FinishDate)
                {
                    Response = new TaskWorklogCreateResponse
                    {
                        Type = TaskWorklogCreateResponseType.StartAndFinishPeriodNotValid
                    };
                    return;
                }

                if ((request.FinishDate - request.StartDate).TotalMinutes < 1)
                {
                    Response = new TaskWorklogCreateResponse
                    {
                        Type = TaskWorklogCreateResponseType.StartAndFinishPeriodLessThanOneMinute
                    };
                    return;
                }

                using (var dbContext = new ApplicationDbContext())
                {
                    var task = dbContext.Tasks.SingleOrDefault(aTask => aTask.Identifier == request.TaskIdentifier);

                    if (task == null)
                    {
                        Response = new TaskWorklogCreateResponse
                        {
                            Type = TaskWorklogCreateResponseType.TaskDoesNotExist
                        };
                        return;
                    }

                    var user = dbContext.Users.SingleOrDefault(aUser => aUser.Identifier == request.UserIdentifier);

                    if (user == null)
                    {
                        Response = new TaskWorklogCreateResponse
                        {
                            Type = TaskWorklogCreateResponseType.UserDoesNotExist
                        };
                        return;
                    }

                    var worklog = new TaskWorklog();
                    worklog.Set(request);
                    dbContext.TaskWorklogs.Add(worklog);
                    dbContext.SaveChanges();

                    Response = new TaskWorklogCreateResponse
                    {
                        Type = TaskWorklogCreateResponseType.Success
                    };
                }
            }
        }
Exemple #2
0
        public TaskStart(TaskStartRequest request)
        {
            if (request != null)
            {
                using (var dbContext = new ApplicationDbContext())
                {
                    var task = dbContext.Tasks.SingleOrDefault(aTask => aTask.Identifier == request.TaskIdentifier);

                    if (task == null)
                    {
                        Response = new TaskStartResponse
                        {
                            Type = TaskStartResponseType.TaskDoesNotExist
                        };
                        return;
                    }

                    var user = dbContext.Users.SingleOrDefault(aUser => aUser.Identifier == request.UserIdentifier);

                    if (user == null)
                    {
                        Response = new TaskStartResponse
                        {
                            Type = TaskStartResponseType.UserDoesNotExist
                        };
                        return;
                    }

                    var conflictingTask = task.Worklogs.SingleOrDefault(aWorklog
                                                                        => aWorklog.FinishDate == null && aWorklog.UserIdentifier == request.UserIdentifier);

                    if (conflictingTask != null)
                    {
                        Response = new TaskStartResponse
                        {
                            Type = TaskStartResponseType.ConflictingTaskExists,
                            ConflictingTaskId   = conflictingTask.Task.Identifier,
                            ConflictingTaskName = conflictingTask.Task.Name,
                        };
                        return;
                    }

                    var worklog = new TaskWorklog();
                    worklog.Set(request);
                    dbContext.TaskWorklogs.Add(worklog);
                    dbContext.SaveChanges();

                    //Set task to in progress.
                    task.Set(request);
                    dbContext.SaveChanges();
                }
            }
        }