public ActionResult Editar(string id, SocioViewModel model) { if (ModelState.IsValid) { try { var socio = new SocioWeb { Id = id, NombreApellidoORazonSocial = model.NombreApellidoORazonSocial, Telefono = model.Telefono, NroCuenta = model.NroCuenta, TipoCuenta = model.TipoCuenta, IdSucursal = model.IdSucursal.Value }; SociosRepositorio.Actualizar(socio); _controllerHelper.CargarResultadoOk("El Socio fue editado correctamente!"); } catch (Exception) { _controllerHelper.CargarError("No se pudo editar el Socio."); } } CargarListasSocioViewModel(model); return(View(model)); }
public void Agregar(SocioWeb socio) { using (var ctx = new HomeBankingContext()) { ctx.Socios.Add(socio); ctx.SaveChanges(); } }
public ActionResult Agregar(SocioViewModel model) { if (ModelState.IsValid) { string idUsuario; var identityResultado = UsuariosRepositorio.Agregar(model.Email, out idUsuario); if (identityResultado.Succeeded) { var socio = new SocioWeb { Id = idUsuario, NombreApellidoORazonSocial = model.NombreApellidoORazonSocial, Telefono = model.Telefono, NroCuenta = model.NroCuenta, TipoCuenta = model.TipoCuenta, IdSucursal = model.IdSucursal.Value }; string tokenActivacion = UsuariosRepositorio.GenerarTokenActivacionCuenta(idUsuario); string urlActivarCuenta = String.Format("{0}{1}", Request.Url.GetLeftPart(UriPartial.Authority), Url.Action("ActivarCuenta", "Acceso", new { u = socio.Id, c = tokenActivacion })); try { SociosRepositorio.Agregar(socio); UsuariosRepositorio.AsignarRol(idUsuario, RolesNombres.SOCIO); var correos = new ServidorCorreos(); correos.EnviarCorreo(model.Email, "Activación de Cuenta", "ActivarCuentaSocio", campos: new Dictionary <string, string> { { "ActivarCuentaURL", urlActivarCuenta } }); _controllerHelper.CargarResultadoOk(String.Format("El Socio {0} fue creado correctamente!", model.Email)); ModelState.Clear(); model = new SocioViewModel(); } catch (Exception) { SociosRepositorio.Eliminar(idUsuario); UsuariosRepositorio.Eliminar(idUsuario); throw; } } else { _controllerHelper.CargarErrores(identityResultado.Errors); } } CargarListasSocioViewModel(model); return(View(model)); }
public void Actualizar(SocioWeb socio) { using (var ctx = new HomeBankingContext()) { ctx.Socios.Attach(socio); ctx.Entry(socio).State = EntityState.Modified; ctx.SaveChanges(); } }
public void Eliminar(string id) { using (var ctx = new HomeBankingContext()) { var entidad = new SocioWeb { Id = id }; ctx.Socios.Attach(entidad); ctx.Entry(entidad).State = EntityState.Deleted; ctx.SaveChanges(); } }