public ActionResult Index(ActualizarUsuario model, HttpPostedFileBase file) { var fileName = ""; if (file!=null && file.ContentLength > 0) { fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/Uploads/Img"), fileName); file.SaveAs(path); } if (ModelState.IsValid && model!=null) { DataClasses1DataContext db = new DataClasses1DataContext(); string NombreUsuario = User.Identity.Name.ToString(); System.Guid IdUs = db.aspnet_Users.Where(a => a.UserName == NombreUsuario).Select(a => a.UserId).ToArray()[0]; string ce = db.aspnet_Memberships.Where(p => p.UserId == IdUs).Select(p => p.Email).ToArray()[0]; ViewBag.ce = ce; Usuario usuario = db.Usuarios.Single(p => p.UserId == IdUs); ViewBag.usuario = usuario; if (!String.IsNullOrEmpty(fileName)) usuario.Avatar = fileName; if ( !String.IsNullOrEmpty(model.ApPaterno) ) usuario.ApPaterno = model.ApPaterno; if ( !String.IsNullOrEmpty(model.ApMaterno) ) usuario.ApMaterno = model.ApMaterno; if ( !String.IsNullOrEmpty(model.Nombres) ) usuario.Nombres = model.Nombres; if ( !String.IsNullOrEmpty(model.Ubicacion)) usuario.Ubicacion = model.Ubicacion; if (!String.IsNullOrEmpty(model.Intereses)) { } db.SubmitChanges(); } return View(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { DataClasses1DataContext db = new DataClasses1DataContext(); System.Guid IdUs = db.aspnet_Users.Where(a => a.UserName == model.UserName).Select(a => a.UserId).ToArray()[0]; System.Guid IdRol = db.aspnet_Roles.Where(a => a.RoleName == "Usuario").Select(a => a.RoleId).ToArray()[0]; aspnet_UsersInRole rel = new aspnet_UsersInRole() { RoleId = IdRol, UserId = IdUs }; db.aspnet_UsersInRoles.InsertOnSubmit(rel); string email = db.aspnet_Memberships.Where(a => a.UserId == IdUs).Select(a => a.Email).ToArray()[0]; string pwd = db.aspnet_Memberships.Where(a => a.UserId == IdUs).Select(a => a.Password).ToArray()[0]; string nick = db.aspnet_Users.Where(a => a.UserId == IdUs).Select(a => a.UserName).ToArray()[0]; Usuario NuevoUsuario = new Usuario() { UserId = IdUs, //Nick = nick, //Password = pwd, //Email = email, Karma = 0 }; db.Usuarios.InsertOnSubmit(NuevoUsuario); db.SubmitChanges(); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Index(CargarLibro model, HttpPostedFileBase file, HttpPostedFileBase file2) { var fileName = ""; if (file != null && file.ContentLength > 0) { fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/Uploads/Pdf"), fileName); file.SaveAs(path); } var fileName2 = ""; if (file2 != null && file2.ContentLength > 0) { fileName2 = Path.GetFileName(file2.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/Uploads/Img"), fileName2); file2.SaveAs(path); } model.Portada = fileName2; model.PdfLibro = fileName; if (ModelState.IsValid) { DataClasses1DataContext db = new DataClasses1DataContext(); string NombreUsuario = User.Identity.Name.ToString(); System.Guid IdUs = db.aspnet_Users.Where(a => a.UserName == NombreUsuario).Select(a => a.UserId).ToArray()[0]; int IdUsuario = db.Usuarios.Where(a => a.UserId == IdUs).Select(a => a.Id).ToArray()[0]; model.Fecha = DateTime.Now; Contenido contenido = new Contenido() { FechaPublicacion = model.Fecha, IdUsuario = IdUsuario, Tipo = "Libro", Titulo = model.Tema, Descripcion = model.Descripcion, //IdCategoria = 1, UrlReal = model.PdfLibro, UrlVirtual = "", Estado = "Pendiente" }; db.Contenidos.InsertOnSubmit(contenido); db.SubmitChanges(); //Insertar en la tabla Libros int IdConte = db.Contenidos.Where(p => p.IdUsuario==IdUsuario).Where(q => q.FechaPublicacion==model.Fecha).Select(r => r.Id).ToArray()[0]; Libro libro = new Libro() { Autor = model.Autor, Portada = model.Portada, Indice = "", AnhoPublicacion = (int)model.Anho, IdContenido = IdConte }; db.Libros.InsertOnSubmit(libro); db.SubmitChanges(); //Categorias char[] separadores = { ',' }; string[] categorias = model.Categorias.Split(separadores); char[] t = { ' ' }; List<string> CatRechazadas = new List<string>(); foreach (string str in categorias) { string str2 = str.Trim(t); int esta = db.Categorias.Count(c => c.Descripcion == str2); if (esta == 0) { Categoria categoria = new Categoria() { Descripcion = str2, Estado = "Pendiente" }; db.Categorias.InsertOnSubmit(categoria); db.SubmitChanges(); } int IdCat = db.Categorias.Single(c => c.Descripcion == str2).Id; string estado = db.Categorias.Single(c => c.Descripcion==str2).Estado; if (estado != "Rechazado") { RelContenidosCategoria rel = new RelContenidosCategoria() { IdContenido = IdConte, IdCategoria = IdCat }; db.RelContenidosCategorias.InsertOnSubmit(rel); } else CatRechazadas.Add(str2); } ViewBag.CatRecha = CatRechazadas; db.SubmitChanges(); } return View(); }