public static Pin ToPin(this UpdatePinDto model, Pin pin, long modifiedBy)
 {
     pin.Name        = model.Name;
     pin.Description = model.Description;
     pin.UpdatedBy   = modifiedBy;
     return(pin);
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdatePin(
            UpdatePinDto model
            )
        {
            try
            {
                var responsePayload = await _pinService.UpdatePinAsync(model);

                return(Ok(responsePayload));
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public async Task <PinReturnDto> UpdatePinAsync(UpdatePinDto model)
        {
            var userId = long.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var pinOld =
                await _pinService.GetByIdAsync(model.Id);

            if (pinOld == null)
            {
                throw new ObjectNotFoundException("Pin not found.");
            }

            if (pinOld.CreatedBy != userId)
            {
                throw new UnauthorizedAccessException("You have no permissions to delete this pin.");
            }

            var board =
                await _pinService.UpdateAsync(model.ToPin(pinOld, userId));

            return(board.ToPinReturnDto());
        }