Пример #1
0
        public IActionResult AddLine(Guid id, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = repository.Find(id);

            if (timecard != null)
            {
                if (timecard.Status != TimecardStatus.Draft)
                {
                    return(StatusCode(409, new InvalidStateError()
                    {
                    }));
                }

                var annotatedLine = timecard.AddLine(documentLine);

                repository.Update(timecard);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }
        public IActionResult ReplaceLine(Guid id, Guid lineID, [FromBody] DocumentLine replacement)
        {
            logger.LogInformation($"Looking for timesheet ID {id}");
            Timecard tc = repository.Find(id);

            if (tc == null)
            {
                return(NotFound());
            }
            if (tc.Status != TimecardStatus.Draft)
            {
                return(StatusCode(409, new InvalidStateError()
                {
                }));
            }

            logger.LogInformation($"Looking for timecard line ID {lineID}");

            if (tc.HasLine(lineID))
            {
                tc.DeleteLine(lineID);
                repository.Update(tc);
                return(AddLine(id, replacement));
            }
            else
            {
                return(NotFound());
            }
        }
Пример #3
0
        public IActionResult Submit(Guid id, [FromBody] Submittal submittal)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = repository.Find(id);

            if (timecard != null)
            {
                if (timecard.Status != TimecardStatus.Draft)
                {
                    return(StatusCode(409, new InvalidStateError()
                    {
                    }));
                }

                if (timecard.Lines.Count < 1)
                {
                    return(StatusCode(409, new EmptyTimecardError()
                    {
                    }));
                }

                var transition = new Transition(submittal, TimecardStatus.Submitted);

                logger.LogInformation($"Adding submittal {transition}");

                timecard.Transitions.Add(transition);

                repository.Update(timecard);

                return(Ok(transition));
            }
            else
            {
                return(NotFound());
            }
        }
        //Path a entry in the line for the given line id from the specified timesheet
        public IActionResult PatchLine(Guid id, Guid lineId, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {id}");
            logger.LogInformation($"Looking for Line {lineId}");
            logger.LogInformation($"Looking for Doc Line {documentLine}");


            Timecard timecard = repository.Find(id);

            if (timecard != null)
            {
                if (timecard.Status != TimecardStatus.Draft)
                {
                    return(StatusCode(409, new InvalidStateError()
                    {
                    }));
                }

                TimecardLine line = timecard.Lines
                                    .FirstOrDefault(l => l.UniqueIdentifier == lineId);

                if (line == null)
                {
                    return(NotFound());
                }

                if (documentLine.Week != 0)
                {
                    line.Week = documentLine.Week;
                }
                if (documentLine.Year != 0)
                {
                    line.Year = documentLine.Year;
                }
                if (documentLine.Hours != 0.0)
                {
                    line.Hours = documentLine.Hours;
                }
                if (documentLine.Day != DayOfWeek.Sunday)
                {
                    line.Day = documentLine.Day;
                }
                if (documentLine.Project.Length != 0)
                {
                    line.Project = documentLine.Project;
                }

                repository.Update(timecard);

                return(Ok(line));
            }
            else
            {
                return(NotFound());
            }
        }
Пример #5
0
        //[ProducesResponseType(typeof(InvalidStateError), 409)]
        public IActionResult UpdateLine(Guid id, Guid lineid, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for lineid {lineid}");

            Timecard     timecard      = repository.Find(id);
            TimecardLine annotatedLine = null;

            if (timecard != null)
            {
                // TBD: Need to handle the case when the lineid is invalid
                foreach (var line in timecard.Lines)
                {
                    if (line.UniqueIdentifier == lineid)
                    {
                        annotatedLine = line.Update(documentLine);
                    }
                }

                // Invalid lineid
                if (annotatedLine != null)
                {
                    repository.Update(timecard);

                    return(Ok(annotatedLine));
                }
                else
                {
                    return(NotFound(string.Format("Timecard line {0}.", lineid)));
                }
            }
            else
            {
                // Timecard not found
                return(NotFound());
            }
        }