示例#1
0
        public async Task <ActionResult> UpdatePosition([FromBody] UpdatePositionDto updatePositionDto)
        {
            if (!ModelState.IsValid || updatePositionDto.Id < 1)
            {
                return(BadRequest(ModelState));
            }
            var position = await _unitOfWork.PositionRepository.GetPositionByIdAsync(updatePositionDto.Id);

            if (position == null)
            {
                return(BadRequest("Submitted data is invalid."));
            }
            var userId    = User.GetUserId();
            var portfolio = await _unitOfWork.PortfolioRepository.GetPortfolioByIdAsync(position.PortfolioId);

            if (userId != portfolio.AppUserId)
            {
                return(Unauthorized("You are not authorized to edit this position."));
            }
            _mapper.Map(updatePositionDto, position);
            _unitOfWork.PositionRepository.UpdatePosition(position);
            if (await _unitOfWork.Complete())
            {
                return(NoContent());
            }

            return(BadRequest());
        }
 public IHttpActionResult Update([FromBody] UpdatePositionDto position)
 {
     if (position == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         _positionService.Update(position);
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
示例#3
0
        public void Update(UpdatePositionDto dto)
        {
            var position = _positionRepository.GetById(dto.Id);

            if (position != null)
            {
                position.WorkUnitId = dto.WorkUnitId;
                position.Title      = dto.Title;

                _positionRepository.Update(position);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "Position entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }
示例#4
0
 public IActionResult Update(UpdatePositionDto updatePositionDto)
 {
     try
     {
         var region = _positionService.Update(updatePositionDto);
         return(Ok(region));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#5
0
        public GetPositionDto Update(UpdatePositionDto updatePositionDto)
        {
            var positionInDb = _unitOfWork.PositionRepository.Get(updatePositionDto.Id);

            if (positionInDb == null)
            {
                throw new Exception("Not Found");
            }

            var position = _mapper.Map <Position>(updatePositionDto);

            positionInDb.Name = updatePositionDto.Name;
            positionInDb.PositionsAndDepartments = position.PositionsAndDepartments;

            _unitOfWork.PositionRepository.Update(positionInDb);
            _unitOfWork.SaveChanges();
            return(_mapper.Map <GetPositionDto>(positionInDb));
        }