public IActionResult CrearEmpresa(EmpresaViewModel model) { var result = new TbGeEmpresa(); try { var existeEmpresaN = service.GetEmpresaByNombre(model.Nombre); if (existeEmpresaN != null) { return(Json(new { success = _sharedLocalizer["yaExisteEmpresa"].ToString() })); } var existeEmpresaC = service.GetByCedula(model.CedJuridica); if (existeEmpresaN != null) { return(Json(new { success = _sharedLocalizer["yaExisteEmpresa"].ToString() })); } model.Id_GE = (int)service.GetGE().Id; result = geMap.Create(model); if (result != null) { var res = service.CrearBD(model.Bd); if (res) { service.AgregarUsuarios((int)result.Id); // return Json(new { success = true }); return(Json(new { success = true })); } else { ///eliminar datos si la bd no se crea //var em = service.GetEmpresaById((int)result.Id); var deleted = service.EliminarEmpresa(result); return(Json(new { success = _sharedLocalizer["errorGeneral"].ToString() })); } } else { return(Json(new { success = _sharedLocalizer["errorGeneral"].ToString() })); } } catch (Exception ex) { AltivaLog.Log.Insertar(ex.ToString(), "Error"); var deleted = service.EliminarEmpresa(result); return(BadRequest(new { success = _sharedLocalizer["errorGeneral"].ToString() })); } }
public TbGeEmpresa ViewModelToDomainEditar(EmpresaViewModel model) { var domain = service.GetEmpresaById(model.Id); domain.Bd = model.Bd; if (domain.CedJuridica != model.CedJuridica) { if (service.GetByCedula(model.CedJuridica) == null) { domain.CedJuridica = model.CedJuridica; } } domain.Correo = model.Correo; domain.Direccion = model.Direccion; domain.Estado = model.Estado; domain.FechaMod = DateTime.Now; domain.Nombre = model.Nombre; domain.Telefono1 = model.Telefono1; domain.Telefono2 = model.Telefono2; domain.TienePuntoVentaDefecto = model.TienePuntoVentaDefecto; domain.IdPuntoVenta = model.IdPuntoVenta; //domain.IdGrupoEmpresarial = model.Id_GE; if (model.Foto != null) { var savePath = System.IO.Path.Combine(hostingEnvironment.WebRootPath, "uploads"); domain.Foto = FotosService.SubirFotoEmpresa(model.Foto, savePath); } return(domain); }
public TbGeEmpresa ViewModelToDomainEditar(EmpresaViewModel model) { var domain = service.GetEmpresaById(model.Id); domain.Bd = model.Bd; if (domain.CedJuridica != model.CedJuridica) { if (service.GetByCedula(model.CedJuridica) == null) { domain.CedJuridica = model.CedJuridica; } } domain.Correo = model.Correo; domain.Direccion = model.Direccion; domain.Estado = model.Estado; domain.FechaMod = DateTime.Now; domain.Nombre = model.Nombre; domain.Telefono1 = model.Telefono1; domain.Telefono2 = model.Telefono2; //domain.IdGrupoEmpresarial = model.Id_GE; if (model.Foto != null) { domain.Foto = FotosService.SubirFotoEmpresa(model.Foto); } return(domain); }