public ActionResult Create(FormCollection collection) { try { ResultSet response = new ResultSet(); if (!topicoenuso(collection["Nombre"].Trim())) { Topico topico = new Topico() { Nombre = collection["Nombre"].Trim(), Descripcion = collection["Descripcion"].Trim(), visible = Convert.ToBoolean(collection["visible"].Split(',')[0]) }; db.Topico.Add(topico); db.SaveChanges(); response.Code = 1; response.Msg = String.Format("Se creó el topico {0}", topico.Nombre); } else { response.Code = -1; response.Msg = String.Format("El tópico {0} ya existe", collection["Nombre"].Trim()); } return(RedirectToAction("Index", new RouteValueDictionary(response))); } catch (Exception exc) { return(View()); } }
public ActionResult Create(HttpPostedFileBase file, FormCollection collection) { try { if (file != null && file.ContentLength > 0) { string path = Path.Combine(Server.MapPath("~/Imagenes"), Path.GetFileName(file.FileName)); if (!System.IO.File.Exists(path)) { file.SaveAs(path); //Guardo el archivo en el server } ResultSet response = new ResultSet(); Imagen imagen = new Imagen() { Titulo = collection["Titulo"].Trim(), Comentarios = collection["Comentarios"].Trim(), Path = String.Format("~/Imagenes/{0}", file.FileName), IdArticulo = Convert.ToInt32(collection["IdArticulo"]) }; db.Imagen.Add(imagen); db.SaveChanges(); response.Code = 1; response.Msg = String.Format("Se creó la imagen {0}", imagen.Titulo); return(RedirectToAction("Index", new RouteValueDictionary(response))); } else { return(View()); } } catch (Exception ex) { return(View()); } }
public ActionResult Create(FormCollection collection) { try { ResultSet response = new ResultSet(); if (usernameenuso(collection["Username"].Trim())) { response.Code = -1; response.Msg = String.Format("El Username {0} ya esta siendo utilizado", collection["Username"].Trim()); } else { if (mailenuso(collection["Email"].Trim())) { response.Code = -1; response.Msg = String.Format("El mail {0} ya esta siendo utilizado", collection["Email"].Trim()); } else { byte[] newsalt = Helper.Helper.Get_SALT(); Usuario usuario = new Usuario() { Username = collection["Username"].Trim(), Password = Helper.Helper.Get_HASH_SHA512(collection["Password"].Trim(), collection["Username"].Trim(), newsalt), salt = newsalt, Rol = Convert.ToInt32(collection["Rol"].Trim()), RegDate = DateTime.Now, Estado = Convert.ToInt32(collection["Estado"].Trim()), Email = collection["Email"].Trim() }; Novedad novedad = new Novedad() { IdUser = usuario.Id, FechaPublicacion = DateTime.Now, IdTemplate = (int)MyTemplate.TypeOp.CreateUser }; db.Novedad.Add(novedad); db.Usuario.Add(usuario); db.SaveChanges(); response.Code = 1; response.Msg = String.Format("Se creó el usuario {0}", usuario.Username); } } return(RedirectToAction("Index", new RouteValueDictionary(response))); } catch (Exception e) { return(View()); } }
public ActionResult Create(FormCollection collection) { try { ResultSet response = new ResultSet(); Articulo articulo = new Articulo() { Titulo = collection["Titulo"].Trim(), Comentarios = collection["Comentarios"].Trim(), FechaPublicacion = DateTime.Now, IdTopico = Convert.ToInt32(collection["IdTopico"]), visible = Convert.ToBoolean(collection["visible"].Split(',')[0]) }; db.Articulo.Add(articulo); db.SaveChanges(); response.Code = 1; response.Msg = String.Format("Se creó el artículo {0}", articulo.Titulo); return(RedirectToAction("Index", new RouteValueDictionary(response))); } catch (Exception ex) { return(View()); } }