public static Response SaveChanges(InfoNetContex db) { try { db.SaveChanges(); return(new Response { Succeded = true }); } catch (Exception ex) { var response = new Response { Succeded = false, }; if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { response.Message = "Ya se encuentra un registro en el sistema"; } else { response.Message = ex.Message; } return(response); } }
public ActionResult Create(PublicationView publicationView) { if (!ModelState.IsValid) { return(View(publicationView)); } //Upload image string path = string.Empty; string pic = string.Empty; if (publicationView.Imagen != null) { pic = Path.GetFileName(publicationView.Imagen.FileName); path = Path.Combine(Server.MapPath("~/Content/Fotos"), pic); publicationView.Imagen.SaveAs(path); using (MemoryStream ms = new MemoryStream()) { publicationView.Imagen.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } } var publication = new Publication { Nombre = publicationView.Nombre, Titulo = publicationView.Titulo, Description = publicationView.Description, Contenido = publicationView.Contenido, Imagen = pic == string.Empty ? string.Empty:string.Format("~/Content/Foto/{0}", pic), }; db.Publications.Add(publication); db.SaveChanges(); return(RedirectToAction("Index")); }