public async Task <IActionResult> PostProduct([FromBody] Common.Models.Cheque cheque) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var user = await this.userHerlper.GetUserByEmailAsync(cheque.User.Email); if (user == null) { return(this.BadRequest("Invalid user")); } var cliente = await this.clienteRepository.GetByIdAsync(cheque.ClienteId); var imageUrl = string.Empty; if (cheque.ImageArray != null && cheque.ImageArray.Length > 0) { var stream = new MemoryStream(cheque.ImageArray); var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; var folder = "wwwroot\\images\\Cheques"; var fullPath = $"~/images/Cheques/{file}"; var response = FilesHelper.UploadPhoto(stream, folder, file); if (response) { imageUrl = fullPath; } } var entityCheque = new Cheque { ClienteId = cheque.ClienteId, //Cliente = cliente, FechaDeposito = cheque.FechaDeposito, FechaIngreso = cheque.FechaIngreso, Destino = cheque.Destino, Firmante = cheque.Firmante, Importe = cheque.Importe, Numero = cheque.Numero, User = user, ImageUrl = imageUrl }; var newCheque = await this.chequesRepository.CreateAsync(entityCheque); return(Ok(newCheque)); }
public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Common.Models.Cheque cheque) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } if (id != cheque.Id) { return(BadRequest()); } var oldCheque = await this.chequesRepository.GetByIdAsync(id); if (oldCheque == null) { return(this.BadRequest("Cheque Id don't exists.")); } var cliente = await this.clienteRepository.GetByIdAsync(cheque.ClienteId); var imageUrl = cheque.ImageUrl; if (cheque.ImageArray != null && cheque.ImageArray.Length > 0) { var stream = new MemoryStream(cheque.ImageArray); var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; var folder = "wwwroot\\images\\Cheques"; var fullPath = $"~/images/Cheques/{file}"; var response = FilesHelper.UploadPhoto(stream, folder, file); if (response) { imageUrl = fullPath; } } oldCheque.ClienteId = cheque.ClienteId; oldCheque.Cliente = cliente; oldCheque.FechaDeposito = cheque.FechaDeposito; oldCheque.FechaIngreso = cheque.FechaIngreso; oldCheque.Destino = cheque.Destino; oldCheque.Firmante = cheque.Firmante; oldCheque.Importe = cheque.Importe; oldCheque.Numero = cheque.Numero; oldCheque.ImageUrl = imageUrl; var updatedCheque = await this.chequesRepository.UpdateAsync(oldCheque); return(Ok(updatedCheque)); }