Ejemplo n.º 1
0
        public async Task <AccountResponseDto> UpdateAsync(int id, UpdateRequestDto request)
        {
            await _updateRequestValidator.ValidateAndThrowAsync(request);

            var account = await GetAccount(id);

            // validate
            if (account.Email != request.Email && _dbContext.Accounts.Any(x => x.Email == request.Email))
            {
                throw new AppException($"Email '{request.Email}' is already taken");
            }

            // hash password if it was entered
            if (!string.IsNullOrEmpty(request.Password))
            {
                account.PasswordHash = BC.HashPassword(request.Password);
            }

            // copy model to account and save
            _mapper.Map(request, account);
            account.UpdatedDate = DateTime.UtcNow;
            _dbContext.Accounts.Update(account);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <AccountResponseDto>(account));
        }
Ejemplo n.º 2
0
        public ActionResult Update(UpdateRequestDto model)
        {
            var entity = _repo.Get(model.EntityId);

            if (entity == null)
            {
                return(RedirectToAction("Index"));
            }

            return(View(entity));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <AccountResponseDto> > Update(int id, UpdateRequestDto model)
        {
            // users can update their own account and admins can update any account
            if (id != Account.Id && Account.Role != Role.Admin)
            {
                return(Unauthorized(new { message = "Unauthorized" }));
            }

            // only admins can update role
            if (Account.Role != Role.Admin)
            {
                model.Role = null;
            }

            return(Ok(await _accountService.UpdateAsync(id, model)));
        }
Ejemplo n.º 4
0
        public void UpdateRequestStatus(UpdateRequestDto requestDto)
        {
            var request = _requestRepository.GetById(requestDto.RequestId);

            if (request != null && request.CourierId == requestDto.CourierId &&
                request.Status != (int)StatusRequest.Cancelled &&
                !(request.Status == (int)StatusRequest.Abandoned &&
                  requestDto.RequestType == (int)StatusRequest.Waiting))
            {
                request.Status = requestDto.RequestType;
                if (requestDto.PriorityNumber != 0)
                {
                    request.PriorityNumber = requestDto.PriorityNumber;
                }
                _requestRepository.Update(request);
                _requestRepository.Commit();
            }
        }
Ejemplo n.º 5
0
        public IActionResult Update([FromBody] UpdateRequestDto request)
        {
            // Find id of currently logged-in user
            var id = Guid.Parse(ControllerContext.HttpContext.User.Identity.Name);

            // Map dto to entity and set id
            var user = _mapper.Map <User>(request);

            user.Id = id;

            try
            {
                // Update user
                _userService.Update(user, request.Password);
                return(Ok());
            }
            catch (AppException ex)
            {
                // Return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 6
0
 public IHttpActionResult UpdateRequestStatus(UpdateRequestDto requestDto)
 {
     _requestService.UpdateRequestStatus(requestDto);
     return(Ok());
 }