예제 #1
0
        public IActionResult Create([FromBody] GroupApiModel group)
        {
            if (group == null)
            {
                throw new BadRequestException("Group data was not provided");
            }

            var result = Mapper.Map <GroupApiModel, Group>(group);

            _groupRepository.Add(result);

            return(CreatedAtRoute("GetGroup", new { id = result.Id }, result));
        }
예제 #2
0
        public IActionResult Update(int id, [FromBody] GroupApiModel group)
        {
            if (group == null)
            {
                throw new BadRequestException("Group data was not provided");
            }

            if (group.Id != id)
            {
                throw new BadRequestException("Group data data doesn`t match provided id.");
            }

            var baseGroup = _groupRepository.Find(id);

            baseGroup.Name        = group.Name;
            baseGroup.Description = group.Description;
            baseGroup.IsActive    = group.IsActive;

            _groupRepository.Update(baseGroup);
            return(new NoContentResult());
        }