public async Task <IActionResult> UpdateClient(string id, [FromBody] ClientUpdateModel clientUpdateModel) { var currentUserId = User.Identity.Name; try { if (User.IsInRole(Roles.Admin)) { await _clientsService.UpdateClientFromAdminAsync(id, clientUpdateModel); } else { await _clientsService.UpdateClientAsync(currentUserId, id, clientUpdateModel); } return(Ok()); } catch (UnauthorizedAccessException e) { return(Unauthorized($"Can't update the client: {e.Message}")); } catch (Exception e) { return(BadRequest($"Can't update the client: {e.Message}")); } }
public async Task <Domain.Client> CreateAsync(ClientUpdateModel model) { var result = await Context.Clients.AddAsync(Mapper.Map <Client>(model)); await Context.SaveChangesAsync(); return(Mapper.Map <Domain.Client>(result.Entity)); }
public async Task <Client> InsertAsync(ClientUpdateModel client) { var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Client>(client)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Client>(result.Entity)); }
public async Task <ActionResult <Client> > PutClient(int id, ClientUpdateModel clientModel) { try { var updatedClient = await _clientService.Update(id, clientModel); log.Info($"Client {id} has been updated."); return(updatedClient); } catch (System.Exception e) { log.Error(e); return(BadRequest(new { error = new { message = e.Message } })); } }
public async Task <Domain.Client> UpdateAsync(ClientUpdateModel model) { var existing = await Get(model); Context.Entry(existing).State = EntityState.Modified; var result = Mapper.Map(model, existing); Context.Update(result); await Context.SaveChangesAsync(); return(Mapper.Map <Domain.Client>(result)); }
public async Task <Client> UpdateAsync(ClientUpdateModel client) { var existing = await this.Get(client); var result = this.Mapper.Map(client, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Client>(result)); }
public HttpStatusCode Update(ClientUpdateModel model) { var client = ClientRepository.Get(model.ChannelUri); if (client != null) { // update the client ClientRepository.UpdateClientChangeset(client.ChannelUri, model.Changeset); } return(HttpStatusCode.OK); }
public async Task UpdateClientFromAdminAsync(string id, ClientUpdateModel toUpdate) { var update = Builders <Client> .Update .Set(dbClient => dbClient.Adress, toUpdate.Adress) .Set(dbClient => dbClient.Town, toUpdate.Town) .Set(dbClient => dbClient.Zipcode, toUpdate.Zipcode) .Set(dbClient => dbClient.Country, toUpdate.Country); await _clients.UpdateOneAsync(dbClient => dbClient.Id == id, update ); }
public async Task UpdateAsync(Guid id, ClientUpdateModel model) { var client = await _repository.GetAsync(id); // TODO: Throw proper exception if (client is null) { return; } client.Name = model.Name; await _repository.SaveAsync(client); }
public async Task UpdateClientAsync(string currentUserId, string id, ClientUpdateModel toUpdate) { var client = await GetClientFromIdAsync(id); if (client == null) { throw new Exception("The client doesn't exist"); } if (client.UserId != currentUserId) { throw new UnauthorizedAccessException("You are not allowed to update this client"); } await UpdateClientFromAdminAsync(id, toUpdate); }
public async Task <IActionResult> Edit(Guid id, ClientUpdateModel model) { if (ModelState.IsValid) { var updateClientCommand = new UpdateClientCommand(model.Id, model.Name, model.Website, model.Description); var result = await _mediator.Send(updateClientCommand); if (result.IsSuccess) { return(RedirectToAction(nameof(ClientController.Index))); } else { ModelState.AddModelError("", result.Error); } } return(View(model)); }
public async Task <ActionResult> Update(string clientId) { ClientUpdateModel model = new ClientUpdateModel(); GetClientByClientIdDto getClientByClientIdDto = await Mediator.Send(new GetClientByClientIdQuery { ClientId = clientId }); if (getClientByClientIdDto != null && getClientByClientIdDto.Id > 0) { model = getClientByClientIdDto.ToClientUpdateModel(); model.AvailableScopes = await GetScopes(); model.AvailableClaims = await GetClaims(); return(View(model)); } return(RedirectToAction("List")); }
public async Task <Client> Update(int id, ClientUpdateModel clientModel) { if (!ClientExists(id)) { throw new Exception("No client found with given Id."); } var client = await _context.Clients.FindAsync(id); client.FirstName = clientModel.FirstName; client.LastName = clientModel.LastName; client.Email = clientModel.Email; client.Password = clientModel.Password; try { await _context.SaveChangesAsync(); } catch (Exception) { throw; } return(await Get(id)); }
public Task <Client> CreateAsync(ClientUpdateModel client) { return(ClientDataAccess.InsertAsync(client)); }
public Task <Client> UpdateAsync(ClientUpdateModel client) { return(ClientDataAccess.UpdateAsync(client)); }