public async Task <IActionResult> Create(CentroAsistencialViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.LogoFile != null) { path = await _imageHelper.UpLoadImageAsync(model.LogoFile, "Centros"); } CentroAsistencial centroAsistencial = _converterHelper.ToCentroAsistencial(model, path, true); _context.Add(centroAsistencial); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, $"Centro Asistencial {centroAsistencial.Nombre} ya existe"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(model)); }
public CentroAsistencialViewModel ToCentroAsistencialViewModel(CentroAsistencial entidad) { return(new CentroAsistencialViewModel { Equipos = entidad.Equipos, Id = entidad.Id, Logo = entidad.Logo, Nombre = entidad.Nombre }); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } CentroAsistencial centroAsistencial = await _context.CentrosAsistenciales.FindAsync(id); if (centroAsistencial == null) { return(NotFound()); } CentroAsistencialViewModel centroAsistencialViewModel = _converterHelper.ToCentroAsistencialViewModel(centroAsistencial); return(View(centroAsistencialViewModel)); }
public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } CentroAsistencial centroAsistencial = await _context.CentrosAsistenciales.FirstOrDefaultAsync(m => m.Id == id); if (centroAsistencial == null) { return(NotFound()); } _context.CentrosAsistenciales.Remove(centroAsistencial); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, CentroAsistencialViewModel model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { var path = model.Logo; if (model.LogoFile != null) { path = await _imageHelper.UpLoadImageAsync(model.LogoFile, "Centros"); } CentroAsistencial entity = _converterHelper.ToCentroAsistencial(model, path, false); _context.Update(entity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, $"Centro Asistencial {model.Nombre} ya existe"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(model)); }