Пример #1
0
        public IActionResult Post(ProjectDTO model)
        {
            Project item = new Project();

            model.UpdateFromModel(item);

            item.LastEdit = DateTime.Now;

            if (_projectRepo.NameExists(item.OwnerId, item.Name))
            {
                return(Conflict("A project with this name already exists for that owner"));
            }

            _projectRepo.Add(item);
            _projectRepo.SaveChanges();

            ProjectDTO dto = new ProjectDTO {
                Id            = item.Id,
                Name          = item.Name,
                TeamId        = item.TeamId,
                OwnerId       = item.OwnerId,
                LastEdit      = item.LastEdit,
                ContactPerson = item.ContactPerson
            };

            return(CreatedAtAction(nameof(GetAll), dto));
        }
Пример #2
0
        public IActionResult Put(int id, ProjectDTO model)
        {
            Project item = _projectRepo.GetById(id);

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

            model.UpdateFromModel(item);
            item.LastEdit = DateTime.Now;

            _projectRepo.SaveChanges();

            return(NoContent());
        }