public ActionResult Create([Bind(Include = "MediaId,Name,Email,IsDeleted")] Media media) { if (Request.Cookies["MagazineId"].Value == null) { SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines")); } int magId = Int32.Parse(Request.Cookies["MagazineId"].Value); var user = UserService.GetCurrentUser(); var relation = UserService.UserInMagazine(magId, user.UserId); if (!relation || !ModelState.IsValid) { return(RedirectToAction("Index", "Magazines")); } if (ModelState.IsValid) { db.MediasList.Add(media); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(media)); }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserId) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ReportId,Title,NewsId,IsPositive,IsPaid,Impact,Comments,MediaId,MagazineId,IsDeleted")] Report report) { if (Request.Cookies["MagazineId"].Value == null) { SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines")); } int magId = Int32.Parse(Request.Cookies["MagazineId"].Value); var user = UserService.GetCurrentUser(); var relation = UserService.UserInMagazine(magId, user.UserId); if (!relation || !ModelState.IsValid) { return(RedirectToAction("Index", "Magazines")); } report.MagazineId = magId; if (ModelState.IsValid) { db.ReportsList.Add(report); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.NewsId = new SelectList(db.NewsesList.Where(x => x.Category.MagazineId == magId).Where(x => !x.IsDeleted), "NewsId", "Title"); ViewBag.MediaId = new SelectList(db.MediasList.Where(x => !x.IsDeleted), "MediaId", "Name"); return(View(report)); }
public IHttpActionResult PutMagazine(int id, Magazine magazine) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != magazine.MagazineId) { return(BadRequest()); } db.Entry(magazine).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MagazineExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutNews(int id, Dal.Models.News news) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != news.NewsId) { return(BadRequest()); } db.Entry(news).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "UserMagazineId,UserId,MagazineId")] UserMagazine userMagazine) { if (ModelState.IsValid) { db.UserMagazinesList.Add(userMagazine); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MagazineId = new SelectList(db.MagazinesList.Include(x => x.User).Where(x => x.User.Email.Equals(UserEmail, StringComparison.OrdinalIgnoreCase)), "MagazineId", "Title", userMagazine.MagazineId); ViewBag.UserId = new SelectList(db.UsersList.Where(x => !x.Email.Equals(UserEmail, StringComparison.OrdinalIgnoreCase)), "UserId", "Email", userMagazine.UserId); return(View(userMagazine)); }
public ActionResult Create([Bind(Include = "AdCategoryId,Name,Tags,StartDate,EndDate,Active,MagazineId")] AdCategory adCategory) { if (ModelState.IsValid) { db.AdCategoriesList.Add(adCategory); db.SaveChanges(); SetMessage("Campaña creada", BootstrapAlertTypes.Success); return(RedirectToAction("Index")); } ViewBag.Keywords = Keywords_GetForAdGroup(db.NewsesList.Where(x => x.Category.MagazineId == adCategory.MagazineId).ToList()).OrderByDescending(x => x.Value); SetMessage("Ha ocurrido un error al crear la campaña", BootstrapAlertTypes.Danger); return(View(adCategory)); }
public ActionResult DeleteConfirmed(int id) { Data data = db.DatasList.Find(id); data.IsDeleted = true; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { Advertise advertise = db.AdvertisesList.Find(id); advertise.IsDeleted = true; db.SaveChanges(); SetMessage("Anuncio eliminado exitosamente", BootstrapAlertTypes.Success); return(RedirectToAction("Index", new { id = advertise.AdCategoryId })); }
public HttpResponseMessage PostCategory(Category category) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Faltan datos.")); } if (category.CategoryId != 0) { db.Entry(category).State = EntityState.Modified; } else { db.CategoriesList.Add(category); } db.SaveChanges(); return(Request.CreateErrorResponse(HttpStatusCode.OK, "Categoria creada")); }
public ActionResult Create([Bind(Include = "GaleryId,Title,Description,Alt,MetaDesc,Keywords,Permalink,MagazineId")] Galery galery) { if (Request.Cookies["MagazineId"].Value == null) { SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines")); } int magId = Int32.Parse(Request.Cookies["MagazineId"].Value); galery.MagazineId = magId; galery.CreationDate = DateTime.Now; if (ModelState.IsValid) { db.GaleriesList.Add(galery); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(galery)); }
public ActionResult DeleteConfirmed(int id) { var user = UserService.GetCurrentUser(); var relation = UserService.UserInMagazine(id, user.UserId); if (!relation || !ModelState.IsValid) { return(RedirectToAction("Index", "Magazines")); } Magazine magazine = db.MagazinesList.Find(id); db.MagazinesList.Remove(magazine); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditOrder(List <int> slideId, List <int> order) { for (var i = 0; i < slideId.Count; i++) { var id = slideId[i]; var getSlide = db.SlidesList.SingleOrDefault(x => x.SlideId == id); getSlide.Order = order[i]; db.Entry(getSlide).State = EntityState.Modified; db.SaveChanges(); } SetMessage("Se cambio el orden de tus slides exitosamente.", BootstrapAlertTypes.Success); return(RedirectToAction("Index")); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (EFDataBase db = new EFDataBase()) { User user = db.Users().FirstOrDefault(u => u.Email.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table //db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); //db.SaveChanges(); bool facebookVerified; var client = new Facebook.FacebookClient(Session["facebooktoken"].ToString()); dynamic response = client.Get("me", new { fields = "id,verified" }); if (response.ContainsKey("verified")) { facebookVerified = response["verified"]; } else { facebookVerified = false; } var code = Guid.NewGuid().ToString(); var newUser = new User(); newUser.ActivationDate = DateTime.Now; newUser.Code = code; newUser.Email = model.UserName; newUser.UserName = model.Name; newUser.CreateDate = DateTime.Now.ToString(); newUser.FbId = response["id"]; db.UsersList.Add(newUser); db.SaveChanges(); RoleService.AddUserToRole(model.UserName, "Influencer"); user = UserService.GetUserbyEmail(model.UserName); if (user == null) { SetMessage("Error.", BootstrapAlertTypes.Danger); return(Redirect("/Account/login")); } OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.Name, model.UserName)); claims.Add(new Claim(ClaimTypes.Email, model.UserName)); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id); SetAuthCookie(model.UserName); SetEncryptedCookie(Configuration.UserCookie, new Dictionary <String, String> { { "Email", user.Email }, { "Code", user.Code } }); if (RoleService.IsUserInRole(model.UserName, "Admin")) { return(Redirect("/Magazines")); } if (RoleService.IsUserInRole(model.UserName, "Influencer")) { return(Redirect("/Influencer")); } if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult Create([Bind(Include = "QuizId,Title,Description")] Quiz quiz) { if (Request.Cookies["MagazineId"].Value == null) { SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines")); } int magId = Int32.Parse(Request.Cookies["MagazineId"].Value); quiz.CreationDate = DateTime.Now; quiz.MagazineId = magId; if (ModelState.IsValid) { db.QuizesList.Add(quiz); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quiz)); }