public async Task <IActionResult> PutClient([FromRoute] int id, [FromBody] CSAppFE.Common.Models.Client client) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } if (id != client.Id) { return(BadRequest()); } var oldClient = await this.clientRepo.GetByIdAsync(id); if (oldClient == null) { return(this.BadRequest("Client Id don't exists.")); } //TODO: Upload images oldClient.CUIT = client.Cuit; oldClient.Name = client.Name; oldClient.Email = client.Email; oldClient.Phone = client.Phone; var updatedClient = await this.clientRepo.UpdateAsync(oldClient); return(Ok(updatedClient)); }
public async Task <IActionResult> PostClient([FromBody] CSAppFE.Common.Models.Client client) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var user = await this.userHelper.GetUserByEmailAsync(client.User.Email); if (user == null) { return(this.BadRequest("Invalid user")); } //TODO: Upload images var entityClient = new Client { CUIT = client.Cuit, Name = client.Name, Email = client.Email, Phone = client.Phone, User = user }; var newClient = await this.clientRepo.CreateAsync(entityClient); return(Ok(newClient)); }