Exemplo n.º 1
0
        public async Task <HttpResponseMessage> PutTaskToPlanAsync(int id, int taskId, string sectionId, string priority)
        {
            try
            {
                int?section;
                int?priorityNew;
                if (string.IsNullOrEmpty(sectionId))
                {
                    section = null;
                }
                else
                {
                    section = int.Parse(sectionId);
                }
                if (string.IsNullOrEmpty(priority))
                {
                    priorityNew = null;
                }
                else
                {
                    priorityNew = int.Parse(priority);
                }
                bool success = await planService.AddTaskToPlanAsync(id, taskId, section, priorityNew);

                if (success)
                {
                    var log = $"Succesfully add task with id {taskId} to plan with id = {id}";
                    tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, log);
                    return(Request.CreateResponse(HttpStatusCode.OK, $"Succesfully added task to plan ({id})."));
                }
                tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on adding task to plan");
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Incorrect request syntax or task or plan does not exist."));
            }
            catch (EntityException e)
            {
                tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
        public async Task <ActionResult> PutTaskToPlanAsync(int id, int taskId, string sectionId, string priority)
        {
            try
            {
                int?section;
                int?priorityNew;
                if (string.IsNullOrEmpty(sectionId))
                {
                    section = null;
                }
                else
                {
                    section = int.Parse(sectionId);
                }
                if (string.IsNullOrEmpty(priority))
                {
                    priorityNew = null;
                }
                else
                {
                    priorityNew = int.Parse(priority);
                }
                bool success = await planService.AddTaskToPlanAsync(id, taskId, section, priorityNew);

                if (success)
                {
                    string okMessage = $"Succesfully added task to plan ({id}).";
                    return(Ok(okMessage));
                }
                string message = "Incorrect request syntax or task or plan does not exist.";
                return(BadRequest(message));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }