コード例 #1
0
        public IActionResult ReplaceLine(Guid id, [FromBody] DocumentLine newLine, Guid lineId)
        {
            logger.LogInformation($"Looking for timesheet {id} , line {lineId} ");

            Timecard timecard = repository.Find(id);

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

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

                timecard.RemoveLine(lineId);

                var replaceLine = timecard.AddLine(newLine);

                repository.Update(timecard);

                return(Ok(replaceLine));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #2
0
        public IActionResult AddLine(Guid id, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = repository.Find(id);

            if (timecard != null)
            {
                //CHECK ROLES
                if (timecard.Employee != documentLine.Employee)
                {
                    return(StatusCode(403, new UnauthorizedAccess()
                    {
                    }));
                }

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

                var annotatedLine = timecard.AddLine(documentLine);

                repository.Update(timecard);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #3
0
        public IActionResult AddLine(string id, [FromBody] TimecardLine timecardLine, [ModelBinder] int resource)
        {
            Timecard timecard = Database.Find(id);

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

                var annotatedLine = timecard.AddLine(timecardLine);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #4
0
        public IActionResult ReplaceLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine, [ModelBinder] int resource)
        {
            Timecard timecard = Database.Find(timecardId);

            if (timecard == null || !timecard.DoesLineExist(Guid.Parse(lineId)))
            {
                return(NotFound());
            }
            if (timecard.Status != TimecardStatus.Draft)
            {
                return(StatusCode(409, new InvalidStateError()
                {
                }));
            }
            if (resource != timecard.Resource)
            {
                return(StatusCode(409, new InvalidResourceError()
                {
                }));
            }

            timecard.RemoveLine(Guid.Parse(lineId));
            var newLine = timecard.AddLine(timecardLine);

            return(Ok(newLine));
        }
コード例 #5
0
        public IActionResult AddLine(string id, [FromBody] TimecardLine timecardLine)
        {
            // API to add lines to the timesheet
            Timecard timecard = Database.Find(id);

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

                // When a new line is added to the timesheet, the line number is auto-incremented
                // to correctly correspond to the right line being added.
                Database.lineNumCount++;
                var annotatedLine = timecard.AddLine(timecardLine, Database.lineNumCount);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #6
0
        public IActionResult AddLine(Guid id, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = timesheetRepository.Find(id);

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

                if (CallerIdentity != timecard.Employee)
                {
                    return(StatusCode(400, new InvalidIdentityError()
                    {
                    }));
                }

                var annotatedLine = timecard.AddLine(documentLine);

                timesheetRepository.Update(timecard);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }
        public IActionResult ReplaceLine(Guid id, Guid lineId, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {id}");

            Timecard timecard = repository.Find(id);

            if (timecard != null)
            {
                logger.LogInformation($"Looking for line {lineId}");

                if (timecard.HasLine(lineId))
                {
                    timecard.DeleteLine(lineId);

                    var annotatedLine = timecard.AddLine(documentLine);

                    repository.Update(timecard);

                    return(Ok(annotatedLine));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #8
0
        public IActionResult ReplaceLineById(Guid id, Guid lineid, [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 line = timecard.Lines
                           .Where(l => l.UniqueIdentifier == lineid)
                           .FirstOrDefault();

                timecard.Lines.Remove(line);

                TimecardLine newLine = timecard.AddLine(documentLine);

                repository.Update(timecard);

                return(Ok(newLine));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #9
0
        public IActionResult ReplaceLine(Guid timesheetId, Guid lineId, [FromBody] DocumentLine documentLine)
        {
            logger.LogInformation($"Looking for timesheet {timesheetId} with line {lineId}");

            Timecard timecard = repository.Find(timesheetId);

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

                if (!timecard.HasLine(lineId))
                {
                    return(StatusCode(409, new LineNotFoundError()
                    {
                    }));
                }

                timecard.deleteLine(lineId);

                var annotatedLine = timecard.AddLine(documentLine);

                repository.Update(timecard);

                return(Ok(annotatedLine));
            }
            else
            {
                return(NotFound());
            }
        }