Пример #1
0
        public async Task <ActionResult <V1DTO.PermissionDTO> > PostPermission(V1DTO.PermissionDTO permissionDTO)
        {
            // Create permission
            var bllEntity = _mapper.Map(permissionDTO);

            _bll.Permissions.Add(bllEntity);
            await _bll.SaveChangesAsync();

            permissionDTO.Id = bllEntity.Id;
            return(CreatedAtAction(
                       "GetPermission",
                       new { id = permissionDTO.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                       permissionDTO
                       ));
        }
Пример #2
0
        public async Task <IActionResult> PutPermission(Guid id, V1DTO.PermissionDTO permissionDTO)
        {
            // Don't allow wrong data
            if (id != permissionDTO.Id)
            {
                return(BadRequest(new V1DTO.MessageDTO("id and permission.id do not match")));
            }
            var permission = await _bll.Permissions.FirstOrDefaultAsync(permissionDTO.Id, User.UserGuidId());

            if (permission == null)
            {
                _logger.LogError($"EDIT. No such permission: {permissionDTO.Id}, user: {User.UserGuidId()}");
                return(NotFound(new V1DTO.MessageDTO($"No Permission found for id {id}")));
            }
            // Update existing permission
            await _bll.Permissions.UpdateAsync(_mapper.Map(permissionDTO), User.UserId());

            await _bll.SaveChangesAsync();

            return(NoContent());
        }