public ActionResult Create([Bind(Include = "FirstName,Description")] Authors authors) { authors.LastName = "poop"; authors.Created = DateTime.Now; authors.IsDeleted = false; db.Authors.Add(authors); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Description,Created,IsDeleted")] Author author) { if (ModelState.IsValid) { db.Authors.Add(author); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(author)); }
public ActionResult Create([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser) { if (ModelState.IsValid) { db.AspNetUsers.Add(aspNetUser); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id = new SelectList(db.Users, "UserId", "FirstName", aspNetUser.Id); return(View(aspNetUser)); }
public ActionResult Create([Bind(Include = "Id,Name,Description,Created,IsDeleted")] Genres genres) { if (ModelState.IsValid) { genres.Created = DateTime.Now; genres.IsDeleted = false; db.Genres.Add(genres); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(genres)); }
public ActionResult Create([Bind(Include = "Id,BookId,UserId,Title,Text,Rating,Created,IsDeleted")] Review review) { if (ModelState.IsValid) { db.Reviews.Add(review); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", review.UserId); ViewBag.BookId = new SelectList(db.Books, "Id", "UserId", review.BookId); return(View(review)); }
public ActionResult BookReview(BookReviewModel bookReviewModel) { bookReviewModel.Review.UserId = bookReviewModel.Book.UserId; bookReviewModel.Review.BookId = bookReviewModel.Book.Id; bookReviewModel.Review.Created = DateTime.Now; if (ModelState.IsValid) { db.Reviews.Add(bookReviewModel.Review); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", bookReviewModel.Review.UserId); ViewBag.BookId = new SelectList(db.Books, "Id", "UserId", bookReviewModel.Review.BookId); return(View(bookReviewModel)); }
public ActionResult Create([Bind(Include = "Id,UserId,AuthorId,GenreId,Title,AlternativeTitle,Part,Description,ISBN,PublishDate,ImagePath,Created,IsDeleted")] Books books) { if (ModelState.IsValid) { books.GenreId = 1; books.Created = DateTime.Now; books.IsDeleted = false; //try //{ // if (books.ImagePath != null) // { // string path = Path.Combine(Server.MapPath("~/BookImaGes"), Path.GetFileName(books.ImagePath)); // file.SaveAs(path); // } // ViewBag.FileStatus = "File uploaded successfully."; //} //catch (Exception) //{ // ViewBag.FileStatus = "Error while file uploading."; //} db.Books.Add(books); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", books.UserId); ViewBag.AuthorId = new SelectList(db.Authors, "Id", "FirstName", books.AuthorId); ViewBag.GenreId = new SelectList(db.Genres, "Id", "Name", books.GenreId); return(View(books)); }
public ActionResult Profile([Bind(Include = "FirstName,LastName,Gender,Birthdate,Picture,Phone,Address,ZipCode,City,Country,Email,Info")] Users users) { bool hasErrors = false; /* * if (!ModelState.IsValid) * { * ViewBag.ErrMessage = "There are error(s) in your input"; * hasErrors = true; * } */ if (hasErrors) { return(View()); } else { users.UserId = (string)Session["UserId"]; db.Users.Add(users); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult SignUp([Bind(Include = "Email,UserName")] AspNetUsers aspNetUsers) { bool hasErrors = false; string password = Request.Form["Password"]; string password2 = Request.Form["Password2"]; if (!ModelState.IsValid) { ViewBag.ErrMessage = "There are error(s) in your input"; hasErrors = true; } if (!this.IsCaptchaValid("Validate your captcha")) { ViewBag.ErrMessage = "Your captcha answer is incorrect."; hasErrors = true; } if (password != password2) { ViewBag.ErrMessage = "Passwords don't match."; hasErrors = true; } if (password.Trim() == "") { ViewBag.ErrMessage = "Password must be filled in."; hasErrors = true; } if (aspNetUsers.UserName.Trim() == "") { ViewBag.ErrMessage = "Username must be filled in."; hasErrors = true; } int count = (from i in db.AspNetUsers where (i.UserName == aspNetUsers.UserName) select i).Count(); if (0 < count) { ViewBag.ErrMessage = "User name already exists."; hasErrors = true; } if (!ModelState.IsValid) { ViewBag.ErrMessage = "There are error(s) in your input"; hasErrors = true; } if (hasErrors) { return(View()); } else { aspNetUsers.Id = Guid.NewGuid().ToString(); aspNetUsers.EmailConfirmed = true; aspNetUsers.PasswordHash = GetPasswordHash(password); aspNetUsers.SecurityStamp = ""; aspNetUsers.PhoneNumber = ""; aspNetUsers.PhoneNumberConfirmed = false; aspNetUsers.TwoFactorEnabled = false; aspNetUsers.LockoutEndDateUtc = null; aspNetUsers.LockoutEnabled = false; aspNetUsers.AccessFailedCount = 0; aspNetUsers.AspNetRoles.Add(db.AspNetRoles.Find("2")); db.AspNetUsers.Add(aspNetUsers); Users users = new Users(); users.UserId = aspNetUsers.Id; users.FirstName = ""; users.LastName = ""; users.Email = aspNetUsers.Email; users.Created = DateTime.Now; users.IsDeleted = false; db.Users.Add(users); db.SaveChanges(); Session["UserInfo"] = aspNetUsers; Session["UserName"] = aspNetUsers.UserName; Session["UserId"] = aspNetUsers.Id; Session["IsAdmin"] = false; return(RedirectToAction("../Users/Profile")); } }
public ActionResult Create([Bind(Include = "Id,UserId,AuthorId,GenreId,Title,AlternativeTitle,Part,Description,ISBN,PublishDate,ImagePath,Created,IsDeleted")] Books books) { ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", books.UserId); ViewBag.AuthorId = new SelectList(db.Authors, "Id", "FirstName", books.AuthorId); ViewBag.GenreId = new SelectList(db.Genres, "Id", "Name", books.GenreId); string s1 = Request.Form["n1"]; if (s1.Equals("Save")) { Reviews rev = new Reviews(); rev.UserId = ((AspNetUsers)Session["UserInfo"]).Id; rev.BookId = Int32.Parse(Request.Form["TxtBookId"]); rev.Text = Request.Form["Comments"]; if (Request.Form["star"] != null) { rev.Rating = Byte.Parse(Request.Form["star"]); } else { rev.Rating = 0; } rev.Created = DateTime.Now; rev.Title = Request.Form["RevTitle"]; rev.IsDeleted = false; db.Reviews.Add(rev); db.SaveChanges(); return(RedirectToAction("Details", new { id = rev.BookId })); } if (ModelState.IsValid) { // books.GenreId = 1; string s = Request.Form["n1"]; if (s.Equals("autofill")) { int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"c:\isbnstuff3.txt"); while ((line = file.ReadLine()) != null) { try { Item item = GoogleBooksAPI.SearchBook(line); books.UserId = "04e9d61c-eb4d-4821-9f97-91c3bc31f45a"; books.AuthorId = GetAuthorByName(item.VolumeInfo.Authors[0]); books.Created = DateTime.Now; books.GenreId = GetGenreByName(item.VolumeInfo.Categories[0]); books.IsDeleted = false; books.Title = item.VolumeInfo.Title; books.ISBN = line; books.Description = item.VolumeInfo.Description; books.ImagePath = item.VolumeInfo.ImageLinks.Thumbnail; // books.PublishDate = item.VolumeInfo.PublishedDate; db.Books.Add(books); db.SaveChanges(); } catch { int a = 1; } counter++; } file.Close(); } if (s1.Equals("Create")) { books.UserId = ((AspNetUsers)Session["UserInfo"]).Id; books.Created = DateTime.Now; books.IsDeleted = false; db.Books.Add(books); db.SaveChanges(); return(RedirectToAction("Index")); } else { // Item book = GoogleBooksAPI.SearchBook(books.ISBN); //ViewBag.booktitle = book.VolumeInfo.Title; ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", books.UserId); ViewBag.AuthorId = new SelectList(db.Authors, "Id", "FirstName", books.AuthorId); ViewBag.GenreId = new SelectList(db.Genres, "Id", "Name", books.GenreId); return(View()); } } else { return(View(books)); } }