public ActionResult Subir_Proyecto(int Estatus, ProyectoViewModel model, HttpPostedFileBase PolizaAnticipo, HttpPostedFileBase PolizaVicios, HttpPostedFileBase PolizaCumplimiento) { model.fechaContrato.ToString("dd-MMM-yyyy"); SubirDocs oSubir = new SubirDocs(); if (!ModelState.IsValid) { return(View("Crear_Proyecto", model)); } else { string polizaAnticipo = null; if (PolizaAnticipo != null) { string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-01-" + PolizaAnticipo.FileName; oSubir.Subir(path, PolizaAnticipo); polizaAnticipo = PolizaAnticipo.FileName; } string polizaVicios = null; if (PolizaVicios != null) { string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-02-" + PolizaVicios.FileName; oSubir.Subir(path, PolizaVicios); polizaVicios = PolizaVicios.FileName; } string polizaCumplimiento = null; if (PolizaCumplimiento != null) { string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-03-" + PolizaCumplimiento.FileName; oSubir.Subir(path, PolizaCumplimiento); polizaCumplimiento = PolizaCumplimiento.FileName; } using (var db = new sgopEntities()) { proyectos oProyecto = new proyectos(); oProyecto.idLicitacion = model.idLicitacion; oProyecto.fechaContrato = Convert.ToDateTime(model.fechaContrato.ToString("dd-MMM-yyyy")); oProyecto.polizaAnticipo = polizaAnticipo; oProyecto.polizaVicios = polizaVicios; oProyecto.policaCumplimiento = polizaCumplimiento; oProyecto.idEstatus = Estatus; //Falta plazo dias. oProyecto.fechaInicioContrato = Convert.ToDateTime(model.fechaInicioContrato.ToString("dd-MMM-yyyy")); oProyecto.fechaFinalContrato = Convert.ToDateTime(model.fechaFinalContrato.ToString("dd-MMM-yyyy")); oProyecto.fechaInicioReal = Convert.ToDateTime(model.fechaInicioReal.ToString("dd-MMM-yyyy")); oProyecto.fechaFinalReal = Convert.ToDateTime(model.fechaFinalReal.ToString("dd-MMM-yyyy")); //Falta Acta entrega y Jefe de Obra. oProyecto.fechaCreacion = DateTime.Today; oProyecto.usuarioCreacion = 1; //Session["Id"].ToString(); db.proyectos.Add(oProyecto); db.SaveChanges(); } if (oSubir.confirmacion != true) { ViewBag.message = "Ocurrio un error al cargar algun documento."; ViewBag.status = "Error!"; } else { ViewBag.message = "Se agrego el usuario exitosamente!"; ViewBag.status = "Exito!"; } return(View("Crear_Proyecto")); } }
public ActionResult ModificarProyecto(EditarProyectoViewModel model, HttpPostedFileBase PolizaAnticipo, HttpPostedFileBase PolizaVicios, HttpPostedFileBase PolizaCumplimiento) { try { bool flag = false; SubirDocs oSubir = new SubirDocs(); using (var db = new sgopEntities()) { var oProyecto = db.proyectos.Find(model.idProyecto); if (oProyecto.idEstatus == Int32.Parse(model.Status) && oProyecto.fechaContrato == model.fechaContrato && oProyecto.fechaInicioContrato == model.fechaInicioContrato && oProyecto.fechaFinalContrato == model.fechaFinalContrato && oProyecto.fechaInicioReal == model.fechaInicioReal && oProyecto.fechaFinalReal == model.fechaFinalReal && PolizaVicios == null && PolizaCumplimiento == null && PolizaAnticipo == null) { ViewBag.message = "No hay nada que actualizar!"; ViewBag.status = "Info!"; flag = true; } if (PolizaAnticipo != null) { int i = PolizaAnticipo.FileName.IndexOf("."); string temp = PolizaAnticipo.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-01" + temp; oSubir.Subir(path, PolizaAnticipo); oProyecto.polizaAnticipo = PolizaAnticipo.FileName; } if (PolizaVicios != null) { int i = PolizaVicios.FileName.IndexOf("."); string temp = PolizaVicios.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-02" + temp; oSubir.Subir(path, PolizaVicios); oProyecto.polizaVicios = PolizaVicios.FileName; } if (PolizaCumplimiento != null) { int i = PolizaCumplimiento.FileName.IndexOf("."); string temp = PolizaCumplimiento.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-03" + temp; oSubir.Subir(path, PolizaCumplimiento); oProyecto.policaCumplimiento = PolizaCumplimiento.FileName; } BorrarArchivo oBorrar = new BorrarArchivo(); oProyecto.idEstatus = Int32.Parse(model.Status); oProyecto.fechaContrato = model.fechaContrato; oProyecto.fechaInicioContrato = model.fechaInicioContrato; oProyecto.fechaFinalContrato = model.fechaFinalContrato; oProyecto.fechaInicioReal = model.fechaInicioReal; oProyecto.fechaFinalReal = model.fechaFinalReal; oProyecto.usuarioModificacion = 1; //Session["User"].ToString(); oProyecto.fechaModificacion = DateTime.Today; if (flag == false) { db.Entry(oProyecto).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } if (oProyecto.polizaAnticipo != null) { model.polizaAnticipo = true; } else { model.polizaAnticipo = false; } if (oProyecto.polizaVicios != null) { model.polizaVicios = true; } else { model.polizaVicios = false; } if (oProyecto.policaCumplimiento != null) { model.polizaCumplimiento = true; } else { model.polizaCumplimiento = false; } if (oProyecto.polizaAnticipo != null) { model.NpolizaAnticipo = oProyecto.polizaAnticipo; } else { model.NpolizaAnticipo = null; } if (oProyecto.polizaVicios != null) { model.NpolizaVicios = oProyecto.polizaVicios; } else { model.NpolizaVicios = null; } if (oProyecto.policaCumplimiento != null) { model.NpolizaCumplimiento = oProyecto.policaCumplimiento; } else { model.NpolizaCumplimiento = null; } var oEstatus = db.catalogoEstatus.ToArray(); List <SelectListItem> opciones = new List <SelectListItem>(); foreach (var i in oEstatus) { SelectListItem selListItem = new SelectListItem() { Text = i.descripcion, Value = i.idEstatus.ToString() }; opciones.Add(selListItem); } foreach (var opcion in opciones) { if (opcion.Value.Contains(oProyecto.idEstatus.ToString())) { opcion.Selected = true; } } ViewBag.opciones = opciones; } if (flag == true) { return(View(model)); } ViewBag.message = "Se actualizaron los datos exitosamente!"; ViewBag.status = "Exito!"; return(View(model)); } catch (Exception) { ViewBag.message = "Ocurrio un error al actualizar los datos!."; ViewBag.status = "Error!"; return(View(model)); } }
public ActionResult Subir_Proyecto(int Estatus, ProyectoViewModel model, HttpPostedFileBase PolizaAnticipo, HttpPostedFileBase PolizaVicios, HttpPostedFileBase PolizaCumplimiento) { model.fechaContrato.ToString("dd-MMM-yyyy"); SubirDocs oSubir = new SubirDocs(); if (!ModelState.IsValid) { return(View("Crear_Proyecto", model)); } else { string polizaAnticipo = null; if (PolizaAnticipo != null) { int i = PolizaAnticipo.FileName.IndexOf("."); string temp = PolizaAnticipo.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-01-" + temp; oSubir.Subir(path, PolizaAnticipo); polizaAnticipo = PolizaAnticipo.FileName; } string polizaVicios = null; if (PolizaVicios != null) { int i = PolizaVicios.FileName.IndexOf("."); string temp = PolizaVicios.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-02-" + temp; oSubir.Subir(path, PolizaVicios); polizaVicios = PolizaVicios.FileName; } string polizaCumplimiento = null; if (PolizaCumplimiento != null) { int i = PolizaCumplimiento.FileName.IndexOf("."); string temp = PolizaCumplimiento.FileName.Substring(i); string path = Server.MapPath("~/Res/Documentos/"); path += model.idLicitacion + "-03-" + temp; oSubir.Subir(path, PolizaCumplimiento); polizaCumplimiento = PolizaCumplimiento.FileName; } int IdProyecto = -1; using (var db = new sgopEntities()) { proyectos oProyecto = new proyectos(); if (oProyecto.idLicitacion == model.idLicitacion) { TempData["messag"] = "Ya existe un Proyecto para esa Licitacion!"; TempData["stat"] = "Error!!"; return(RedirectToAction("MenuProyectos")); } Rangos oRango = new Rangos(); int idProyecto = oRango.getSiguienteID("PROYECTOS"); IdProyecto = idProyecto; oProyecto.idProyecto = idProyecto; oProyecto.idLicitacion = model.idLicitacion; oProyecto.fechaContrato = Convert.ToDateTime(model.fechaContrato.ToString("dd-MMM-yyyy")); oProyecto.polizaAnticipo = polizaAnticipo; oProyecto.polizaVicios = polizaVicios; oProyecto.policaCumplimiento = polizaCumplimiento; oProyecto.idEstatus = Estatus; //Falta plazo dias. oProyecto.fechaInicioContrato = Convert.ToDateTime(model.fechaInicioContrato.ToString("dd-MMM-yyyy")); oProyecto.fechaFinalContrato = Convert.ToDateTime(model.fechaFinalContrato.ToString("dd-MMM-yyyy")); oProyecto.fechaInicioReal = Convert.ToDateTime(model.fechaInicioReal.ToString("dd-MMM-yyyy")); oProyecto.fechaFinalReal = Convert.ToDateTime(model.fechaFinalReal.ToString("dd-MMM-yyyy")); //Falta Acta entrega y Jefe de Obra. oProyecto.fechaCreacion = DateTime.Today; oProyecto.usuarioCreacion = 1; //Session["Id"].ToString(); db.proyectos.Add(oProyecto); db.SaveChanges(); } if (PolizaAnticipo != null && PolizaVicios != null && PolizaCumplimiento != null) { if (oSubir.confirmacion != true) { TempData["messag"] = "Ocurrio un error al cargar algun documento."; TempData["stat"] = "Error!"; return(RedirectToAction("MenuProyectos")); } else { TempData["messag"] = "Se agrego el proyecto exitosamente!"; TempData["stat"] = "Exito!"; return(RedirectToAction("MenuProyectos")); } } else { TempData["messag"] = "Se agrego el proyecto exitosamente!"; TempData["stat"] = "Exito!"; return(RedirectToAction("MenuProyectos")); } } }