public componenteselectricos Crear(int equipoid, string Tipo = null, string Caracteristicas = null, string Descripcion = null, string Marca = null, string Modelo = null, string Serial = null, string FechaFabricado = null, string Duracion = null , string Sustitucion = null, string Fotografia = null, string FechaSustitucion = null, string FechaAlerta = null, string obra = null, string equipo = null) { //if (Caracteristicas == null) //{ // Caracteristicas = "null"; //} //if (Descripcion == null) //{ // Descripcion = "null"; //} //if (Marca == null) //{ // Marca = "null"; //} //if (Modelo == null) //{ // Modelo = "null"; //} //if (Serial == null) //{ // Serial = "null"; //} //if (FechaFabricado == null) //{ // FechaFabricado = "22/07/2018"; //} //if (FechaSustitucion == null) //{ // FechaSustitucion = "22/07/2018"; //} //if (Duracion == null) //{ // Duracion = "null"; //} if (Sustitucion == null) { Sustitucion = "NO"; } //if (Fotografia == null) //{ // Fotografia = "null"; //} DateTime?FechaFabricadoD = null; DateTime?FechaSustitucionD = null; DateTime?FechaAlertaD = null; DateTime?SustitucionD = null; DateTime?DuracionD = null; if (FechaFabricado != null) { FechaFabricadoD = DateTime.Parse(FechaFabricado); } if (FechaSustitucion != null) { FechaSustitucionD = DateTime.Parse(FechaSustitucion); } if (FechaAlerta != null) { FechaAlertaD = DateTime.Parse(FechaAlerta); // if (Duracion != null) // { } if (Duracion != null) { DuracionD = DateTime.Parse(Duracion); } try { var componenteelectrico = new componenteselectricos() { IdEquipos = equipoid, Tipo = Tipo, Caracteristicas = Caracteristicas, Descripcion = Descripcion, FechaFabricado = FechaFabricadoD, Marca = Marca, Modelo = Modelo, Serial = Serial, Duracion = DuracionD, Sustitucion = Sustitucion, Fotografia = Fotografia, FechaSustitucion = FechaSustitucionD, FechaAlerta = FechaAlertaD, obra = obra, equipo = equipo }; _db.componenteselectricos.Add(componenteelectrico); _db.SaveChanges(); return(componenteelectrico); } catch (Exception) { throw; } }
public ActionResult Crear(ComponenteElectricoViewModel model, FormCollection collection) { var Url = ""; var pdfUrl = ""; ViewBag.obra = _obrasManager.Find(Convert.ToInt32(TempData["obra"])); if (!ModelState.IsValid) { return(View(model)); } try {/* * HttpPostedFileBase pdf = Request.Files["Pdf"]; * * if (pdf != null && pdf.ContentLength > 0) * { * pdfUrl = CargarPdf(pdf); * } * else { pdfUrl = ""; } */ obras obra = _obrasManager.Find(Convert.ToInt32(TempData["obra"])); equipos equipo = _equiposManager.Find(Convert.ToInt32(TempData["equipo"])); componenteselectricos ce = _componentesElectricos_Manager.Crear(Convert.ToInt32(TempData["equipo"]), model.Tipo, model.Caracteristicas, model.Descripcion, model.Marca, model.Modelo, model.Serial, model.FechaFabricado, model.Duracion, model.Sustitucion, pdfUrl.Trim(), model.FechaSustitucion, model.FechaAlerta, obra.Nombre, equipo.Nombre); HttpPostedFileBase file; for (int i = 0; i < Request.Files.Count; i++) { file = Request.Files[i]; var d = Request.Files.AllKeys[i].ToString(); if (d == "Pdf" && file.FileName != "") { Url = CargarPdf(file); _obrasManager.AgregarArchivos(ce.Id, Url, "componenteselectricos", "fotografia"); } } //TempData["FlashSuccess"] = MensajesResource.INFO_MensajesInstitucionales_CreadoCorrectamente; return(RedirectToAction("ComponentesElectronicos", "AdministrarComponentesElectronicos", new { @id = TempData["equipo"] })); } catch (BusinessException businessEx) { ModelState.AddModelError(string.Empty, businessEx.Message); return(View(model)); } catch (Exception e) { var log = CommonManager.BuildMessageLog( TipoMensaje.Error, ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(), ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(), e.ToString(), Request); CommonManager.WriteAppLog(log, TipoMensaje.Error); ModelState.AddModelError(string.Empty, e.Message); return(View(model)); } }