示例#1
0
        public IActionResult PostStatus(int id, [FromBody] CreateProjectStatusOptions options)
        {
            var result = projectService.CreateStatusUpdate(options, id);

            if (!result.Success)
            {
                return(StatusCode((int)result.ErrorCode, result.ErrorText));
            }

            return(Ok());
        }
示例#2
0
        public Result <bool> CreateStatusUpdate(CreateProjectStatusOptions options, int id)
        {
            var result = new Result <bool>();

            if (options == null)
            {
                result.ErrorCode = StatusCode.BadRequest;
                result.ErrorText = "Null options";
                return(result);
            }

            var project = dbContext
                          .Set <Project>()
                          .Where(p => p.ProjectId == id)
                          .Include(p => p.StatusUpdates)
                          .SingleOrDefault();

            if (project == null)
            {
                result.ErrorCode = StatusCode.NotFound;
                result.ErrorText = $"Project with id {id} was not found";
                return(result);
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(options.StatusDescription))
                {
                    project.StatusUpdates.Add(new ProjectStatusUpdate()
                    {
                        Status = options.StatusDescription
                    });
                }
                if (dbContext.SaveChanges() > 0)
                {
                    result.ErrorCode = StatusCode.OK;
                    result.Data      = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ErrorCode = StatusCode.InternalServerError;
                result.ErrorText = ex.ToString();
                return(result);
            }

            result.ErrorCode = StatusCode.InternalServerError;
            result.ErrorText = $"Status update could not be created";
            return(result);
        }
示例#3
0
 public IActionResult PostStatus([FromBody] CreateProjectStatusOptions options)
 {
     return(View());
 }