public void GuardarModificarEmpleadoCuchilloPrestado(EMPLEADO_CUCHILLO_PRESTADO model) { using (ASIS_PRODEntities db = new ASIS_PRODEntities()) { var result = db.EMPLEADO_CUCHILLO_PRESTADO.FirstOrDefault(x => x.Fecha == model.Fecha && x.Cedula == model.Cedula && x.EstadoRegistro == clsAtributos.EstadoRegistroActivo); if (result != null) { result.CuchilloBlanco = model.CuchilloBlanco; result.CuchilloNegro = model.CuchilloNegro; result.CuchilloRojo = model.CuchilloRojo; result.FechaModificacionLog = DateTime.Now; result.TerminalModificacionLog = model.TerminalIngresoLog; result.UsuarioModificacionLog = model.UsuarioIngresoLog; } else { db.EMPLEADO_CUCHILLO_PRESTADO.Add(model); } db.SaveChanges(); } }
public ActionResult EmpleadoCuchilloPrestado(EMPLEADO_CUCHILLO_PRESTADO model) { try { lsUsuario = User.Identity.Name.Split('_'); if (string.IsNullOrEmpty(lsUsuario[0])) { return(Json("101", JsonRequestBehavior.AllowGet)); } clsDCuchillo = new clsDCuchillo(); clsDEmpleado = new clsDEmpleado(); var empleado = clsDEmpleado.ConsultaEmpleado(lsUsuario[1]).FirstOrDefault(); var modelEmpleado = clsDCuchillo.ConsultaEmpleadoPrestadoPorLineaFecha(empleado.CODIGOLINEA, model.Fecha).FirstOrDefault(x => x.CEDULA == model.Cedula); if (modelEmpleado == null) { return(Json("0", JsonRequestBehavior.AllowGet)); } model.UsuarioIngresoLog = lsUsuario[0]; model.TerminalIngresoLog = Request.UserHostAddress; model.FechaIngresoLog = DateTime.Now; model.EstadoRegistro = clsAtributos.EstadoRegistroActivo; model.Linea = modelEmpleado.CODIGOLINEA; model.Cargo = modelEmpleado.CODIGOCARGO; if (!clsDCuchillo.ValidarCuchilloEmpleadoPrestado(model)) { return(Json("1", JsonRequestBehavior.AllowGet)); } clsDCuchillo.GuardarModificarEmpleadoCuchilloPrestado(model); return(Json("Registro Exitoso", JsonRequestBehavior.AllowGet)); } catch (DbEntityValidationException e) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; clsDError = new clsDError(); lsUsuario = User.Identity.Name.Split('_'); string Mensaje = clsDError.ControlError(lsUsuario[0], Request.UserHostAddress, this.ControllerContext.RouteData.Values["controller"].ToString(), "Metodo: " + this.ControllerContext.RouteData.Values["action"].ToString(), null, e); return(Json(Mensaje, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; clsDError = new clsDError(); lsUsuario = User.Identity.Name.Split('_'); string Mensaje = clsDError.ControlError(lsUsuario[0], Request.UserHostAddress, this.ControllerContext.RouteData.Values["controller"].ToString(), "Metodo: " + this.ControllerContext.RouteData.Values["action"].ToString(), ex, null); return(Json(Mensaje, JsonRequestBehavior.AllowGet)); } }
public bool ValidarCuchilloEmpleadoPrestado(EMPLEADO_CUCHILLO_PRESTADO model) { using (ASIS_PRODEntities db = new ASIS_PRODEntities()) { var result = db.EMPLEADO_CUCHILLO_PRESTADO.Where(x => x.Cedula != model.Cedula && x.Fecha == model.Fecha && ((x.CuchilloBlanco == model.CuchilloBlanco && model.CuchilloBlanco > 0) || (x.CuchilloRojo == model.CuchilloRojo && model.CuchilloRojo > 0)) && x.EstadoRegistro == clsAtributos.EstadoRegistroActivo).FirstOrDefault(); if (result != null) { return(false); } else { return(true); } } }