public bool update(ContactoDTO Contacto) { using (var context = getContext()) { try { var row = context.Contacto.Where(x => x.IdContacto == Contacto.IdContacto).SingleOrDefault(); row.IdEntidadResponsable = Contacto.IdEntidadResponsable; row.Nombre = Contacto.Nombre; row.Telefono = Contacto.Telefono; row.Celular = Contacto.Celular; row.Email = Contacto.Email; row.Estado = Contacto.Estado; row.Cargo = Contacto.Cargo; context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public bool add(ContactoDTO Contacto) { using (var context = getContext()) { try { Contacto nuevo = new Contacto(); nuevo.Nombre = Contacto.Nombre; nuevo.IdEntidadResponsable = Contacto.IdEntidadResponsable; nuevo.Estado = true; nuevo.Telefono = Contacto.Telefono; nuevo.Celular = Contacto.Celular; nuevo.Email = Contacto.Email; nuevo.Cargo = Contacto.Cargo; context.Contacto.Add(nuevo); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public ActionResult AddContacto(ContactoDTO dto) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } try { ContactoBL objBL = new ContactoBL(); if (dto.IdContacto == 0) { if (objBL.add(dto)) { //objBL.ActualizarSaldos(dto.IdCuentaBancaria); createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Entidad", new { id = dto.IdEntidadResponsable }); } } else if (dto.IdContacto != 0) { if (objBL.update(dto)) { //objBL.ActualizarSaldos(dto.IdCuentaBancaria); createResponseMessage(CONSTANTES.SUCCESS); return RedirectToAction("Entidad", new { id = dto.IdEntidadResponsable }); } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); } } else { createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } } catch (Exception e) { if (dto.IdContacto != 0) createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE); else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE); } TempData["Contacto"] = dto; return RedirectToAction("Contacto"); }
public ActionResult Contacto(int? id = null, int? idEntidad = null) { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } //if (!this.isAdministrator()) { return RedirectToAction("Index"); } ViewBag.Title = "Contacto"; MenuNavBarSelected(6); UsuarioDTO miUsuario = getCurrentUser(); ContactoBL objBL = new ContactoBL(); ViewBag.IdContacto = id; EntidadResponsableBL objEntidadBL = new EntidadResponsableBL(); EntidadResponsableDTO objEntidad = objEntidadBL.getEntidadResponsableEnEmpresa(miUsuario.IdEmpresa, idEntidad.GetValueOrDefault()); if (objEntidad == null) { return RedirectToAction("Entidades", "Admin"); } var objSent = TempData["Contacto"]; if (objSent != null) { TempData["Contacto"] = null; return View(objSent); } if (id == 0 && idEntidad != null) { ContactoDTO nuevo = new ContactoDTO(); nuevo.IdEntidadResponsable = (int)idEntidad; nuevo.Estado = true; return View(nuevo); } else if (id != null) { ContactoDTO obj = objBL.getContacto((int)id); if (obj == null) return RedirectToAction("Entidad", "Admin", new { id = objEntidad.IdEntidadResponsable }); if (obj.IdEntidadResponsable != objEntidad.IdEntidadResponsable) return RedirectToAction("Entidad", "Admin", new { id = objEntidad.IdEntidadResponsable }); EntidadResponsableDTO objEntidadProy = objEntidadBL.getEntidadResponsableEnEmpresa(miUsuario.IdEmpresa, obj.IdEntidadResponsable); if (objEntidadProy == null) return RedirectToAction("Entidades", "Admin"); if (objEntidadProy.IdEmpresa != miUsuario.IdEmpresa) return RedirectToAction("Entidades", "Admin"); return View(obj); } return View(); }