public async Task <ActionResult <GroupRes> > Put([FromBody] GroupWithIdReq request, [FromRoute] int groupId)
        {
            bool found = await _groupService.EditAsync(request, groupId);

            if (found)
            {
                return(StatusCode(204));
            }
            return(StatusCode(404));
        }
Exemple #2
0
        /// <summary>
        /// Edit Group
        /// </summary>
        /// <param name="model">Group DTO</param>
        /// <param name="groupId">Group ID</param>
        /// <returns>Bool if Group was found</returns>
        public async Task <bool> EditAsync(GroupWithIdReq model, int groupId)
        {
            // route id and model id differs
            if (groupId != model.GroupId)
            {
                throw new AppLogicException("Neplatný požadavek");
            }

            var group = await _context.Groups.FirstOrDefaultAsync(gr => gr.GroupId == groupId);

            // group not found - 404
            if (group == null)
            {
                return(false);
            }

            // edit group
            group.Name = model.Name;
            await _context.SaveChangesAsync();

            return(true);
        }