public async Task <ActionResult <ProjectItem> > UpdateItem(
            [FromRoute(Name = "id")][Range(0, int.MaxValue)] int id,
            [FromBody] UpdateProjectParameters parameters)
        {
            try
            {
                var command = new UpdateProjectItemCommand
                {
                    Id          = id,
                    Name        = parameters.Name,
                    Description = parameters.Description
                };

                return(await _projectRepository.UpdateProject(command));
            }
            catch (Exception e)
            {
                //Logger.Log(e);
                return(BadRequest());
            }
        }
Esempio n. 2
0
        public async Task <ProjectItem> UpdateProject(UpdateProjectItemCommand command)
        {
            var existingItem = await _context.ProjectItems.FindAsync(command.Id);

            if (existingItem == null)
            {
                throw new ArgumentOutOfRangeException(nameof(command.Id));
            }

            existingItem.Name        = command.Name;
            existingItem.Description = command.Description;

            existingItem.Modified = DateTime.UtcNow;

            _context.ProjectItems.Add(existingItem);

            _context.Entry(existingItem).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(existingItem);
        }