public void InsertRequestOP() { var db = new WerkERPContext(); var solicitudOP = new WerkUI.Models.SolicitudOrdenPago(); TryUpdateModel(solicitudOP); if (ModelState.IsValid) { try { solicitudOP.id_estado = 1; solicitudOP.fecha_solicitud = DateTime.Now; solicitudOP.cod_usuario = GetUserID(User.Identity.Name); if (VerifyNroOP(solicitudOP.nro_comprobante.ToString())) { ErrorLabel.Visible = true; ErrorLabel.Text = "El Nro. de comprobante ya existe."; } else { db.SolicitudOrdenPagoes.Add(solicitudOP); db.SaveChanges(); ErrorLabel.Text = String.Empty; //Si la operacion a sido exitosa voy a los detalles de la nueva SOP Response.Redirect("~/OrdenPago/RequestOPDetails.aspx?RequestID=" + solicitudOP.id_solicitud_orden_pago.ToString() + "&RequestNumber=" + solicitudOP.nro_comprobante); } } catch (DbEntityValidationException ex) { ErrorLabel.Visible = true; ErrorLabel.Text = ex.Message; } catch (Exception exp) { if (exp.InnerException.HResult.ToString() == "-2146233087") { ErrorLabel.Text = "El numero de comprobante corresponde a otra solicitud."; } else { ErrorLabel.Text = exp.Message; } ErrorLabel.Visible = true; } } }
public void DeleteRequestOP(WerkUI.Models.SolicitudOrdenPago subject) { try { var db = new WerkERPContext(); var solicitudOP = db.SolicitudOrdenPagoes.Where(s => s.id_solicitud_orden_pago == subject.id_solicitud_orden_pago).SingleOrDefault(); db.SolicitudOrdenPagoes.Remove(solicitudOP); db.SaveChanges(); ErrorLabel.Text = String.Empty; } catch (DbEntityValidationException ex) { ErrorLabel.Visible = true; ErrorLabel.Text = ex.Message; } catch (Exception exp) { ErrorLabel.Text = exp.Message; ErrorLabel.Visible = true; } }