// GET: Cheques/Create public IActionResult Create() { var model = new ChequesViewModel { FechaIngreso = DateTime.Today, FechaDeposito = DateTime.Today, Destino = "En cartera", Clientes = this.chequesRepository.GetComboClientes(User.Identity.Name) }; return(View(model)); }
public async Task <IActionResult> Edit(ChequesViewModel view) { if (ModelState.IsValid) { try { var path = view.ImageUrl; if (view.ImageFile != null && view.ImageFile.Length > 0) { var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\images\\Cheques", file); using (var stream = new FileStream(path, FileMode.Create)) { await view.ImageFile.CopyToAsync(stream); } path = $"~/images/Cheques/{file}"; } view.User = await this.userHelper.GetUserByEmailAsync(this.User.Identity.Name); decimal importe = Convert.ToDecimal(view.Importe, cultures); view.Importe = importe; var cheque = this.toCheques(view, path); await this.chequesRepository.UpdateAsync(cheque); } catch (DbUpdateConcurrencyException) { if (!await this.chequesRepository.ExistAsync(view.Id)) { return(new NotFoundViewResult("ChequeNotFound")); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(view)); }
private Cheque toCheques(ChequesViewModel view, string path) { return(new Cheque { Id = view.Id, ImageUrl = path, Destino = view.Destino, FechaIngreso = view.FechaIngreso, FechaDeposito = view.FechaDeposito, Firmante = view.Firmante, ClienteId = view.ClienteId, Cliente = view.Cliente, Importe = view.Importe, Numero = view.Numero, User = view.User }); }
public async Task <IActionResult> Create(ChequesViewModel view) { if (ModelState.IsValid) { var path = string.Empty; if (view.ImageFile != null && view.ImageFile.Length > 0) { var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\images\\Cheques", file); using (var stream = new FileStream(path, FileMode.Create)) { await view.ImageFile.CopyToAsync(stream); } path = $"~/images/cheques/{file}"; } view.User = await this.userHelper.GetUserByEmailAsync(this.User.Identity.Name); decimal importe = Convert.ToDecimal(view.Importe, cultures); view.Importe = importe; var cheque = this.toCheques(view, path); await this.chequesRepository.CreateAsync(cheque); return(RedirectToAction(nameof(Index))); } return(View(view)); }