public ActionResult Create(HttpPostedFileBase uploadedImage, string title, int category) { if (uploadedImage != null && uploadedImage.ContentLength > 0) { Post post = new Post(); string imagePath = "images/" + System.IO.Path.GetFileName(uploadedImage.FileName); uploadedImage.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Content/"), imagePath)); post.PostTitle = title; post.Image = imagePath; if (category.Equals(null)) { post.CategoryID = null; } else { post.CategoryID = category; } post.DateAdded = DateTime.Now; db.Posts.Add(post); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(View()); } }
public IHttpActionResult PutReviews(int id, Reviews reviews) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != reviews.ID) { return(BadRequest()); } db.Entry(reviews).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ReviewsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ID,CategoryName")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "CategoryID,Created,Modified,CategoryName,Description")] Category category) { if (ModelState.IsValid) { category.Created = DateTime.UtcNow.Ticks; db.Category.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create(ViewModels.Comments.Create model) { var comment = new Comments(); comment.Created = DateTime.UtcNow.Ticks; comment.BookID = model.selecedBookId; comment.UserID = model.selectedUserId; comment.Comment = model.Comment; db.Comments.Add(comment); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "AuthorID,FirstName,LastName,Description,Image,Created,Modified")] Authors authors) { if (ModelState.IsValid) { var ticks = DateTime.Now.Ticks; authors.Created = ticks; DateTime date = new DateTime(ticks, DateTimeKind.Local); db.Authors.Add(authors); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authors)); }
public ActionResult Create(ViewModels.Rating.Create model) { if (ModelState.IsValid) { Rates ratevalue = new Rates(); ratevalue.Created = DateTime.Now.Ticks; ratevalue.RateValue = model.Value; ratevalue.UserID = model.SelectedUserId; ratevalue.BookID = model.SelectedBookId; db.Rates.Add(ratevalue); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
//Remove Users and Roles method.... private void RemoveUsersAndRoles() { var db = new SPContext(); var users = db.UserProfiles.ToList(); foreach (var item in users) { db.UserProfiles.Remove(item); } var Aspusers = db.Users.ToList(); foreach (var item in Aspusers) { db.Users.Remove(item); } var roles = db.Roles.ToList(); foreach (var item in roles) { db.Roles.Remove(item); } try { db.SaveChanges(); } catch (System.Exception e) { var temp = e; } }
public ActionResult Create(ViewModels.Author.Create model) { if (ModelState.IsValid) { var author = new Authors(); author.Created = DateTime.UtcNow.Ticks; author.FirstName = model.FirstName; author.LastName = model.LastName; author.Description = model.Description; author.Image = ViewModels.ImageArray.ToByteArray(model.Upload); db.Authors.Add(author); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(ViewModels.BookViewModel.Create model) { if (ModelState.IsValid) { var book = new Books(); book.Created = DateTime.UtcNow.Ticks; book.BookName = model.Name; book.Description = model.Description; book.Image = ImageArray.ToByteArray(model.Upload); book.AuthorID = model.SelectedAuthorId; book.CategoryID = model.SelectedCategoryId; db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } model = new ViewModels.BookViewModel.Create(db.Authors.ToList(), db.Category.ToList()); return(View(model)); }
public IHttpActionResult PostComment(Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } comment.DateAdded = DateTime.Now; db.Comments.Add(comment); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = comment.ID }, comment)); }
public ActionResult _AddComment(ViewModels.Book.AddComment model) { if (ModelState.IsValid) { //add comment to book, save var comment = new Comments(); comment.BookID = model.BookID; comment.UserID = model.UserID; comment.Comment = model.Comment; comment.Created = DateTime.UtcNow.Ticks; db.Comments.Add(comment); db.SaveChanges(); return(RedirectToAction("Details", new { Id = model.BookID })); } return(RedirectToAction("Details", new { Id = model.BookID })); }
public ActionResult Create(ViewModels.FavouriteBook.FavouriteGeneral model) { if (ModelState.IsValid) { var favouriteBook = new FavouriteBooks(); favouriteBook.Created = DateTime.UtcNow.Ticks; favouriteBook.BookID = model.selectedBookId; favouriteBook.UserID = model.selectedUserId; db.FavouriteBooks.Add(favouriteBook); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public void Save() { scntxt.SaveChanges(); }
public ActionResult Create(ViewModels.User.Edit model) { if (ModelState.IsValid) { //var test = model.CreateUserProfile(); //db.UserProfiles.Add(test); var User = new UserProfiles(); var ID = System.Web.HttpContext.Current.User.Identity.GetUserId(); var AspUser = db.Users.Find(ID); User.Created = DateTime.UtcNow.Ticks; //User.UserID = ID; //Guid.NewGuid().ToString(); User.FirstName = model.FirstName; User.LastName = model.LastName; User.Gender = model.Gender; User.BirthDate = model.DateOfBirth; User.Street = model.Street; User.City = model.City; User.Zip = model.Zip; User.Image = model.Upload == null ? null : ImageArray.ToByteArray(model.Upload); AspUser.UserProfiles = User; db.UserProfiles.Add(User); try { db.SaveChanges(); } catch (Exception e) { var temp = e; } return(RedirectToAction("Index")); } return(View(model)); }
public void Save() { spc.SaveChanges(); }
//Add Authors and Categories method... private void AddAuthorsAndCategories() { var db = new SPContext(); if (db.Authors.Count() == 0) { //Add Authors var Author1 = new Authors(); Author1.FirstName = "Nalin"; Author1.LastName = "Singh"; Author1.Created = DateTime.UtcNow.Ticks; db.Authors.Add(Author1); var Author2 = new Authors(); Author2.FirstName = "Stella"; Author2.LastName = "Parks"; Author2.Created = DateTime.UtcNow.Ticks; db.Authors.Add(Author2); var Author3 = new Authors(); Author3.FirstName = "Stephen"; Author3.LastName = "King"; Author3.Created = DateTime.UtcNow.Ticks; db.Authors.Add(Author3); var Author4 = new Authors(); Author4.FirstName = "Yesmyn"; Author4.LastName = "Ward"; Author4.Created = DateTime.UtcNow.Ticks; db.Authors.Add(Author4); } if (db.Category.Count() == 0) { //Add Categories var Category1 = new Category(); Category1.CategoryName = "Romance"; Category1.Created = DateTime.UtcNow.Ticks; db.Category.Add(Category1); var Category2 = new Category(); Category2.CategoryName = "Action"; Category2.Created = DateTime.UtcNow.Ticks; db.Category.Add(Category2); var Category3 = new Category(); Category3.CategoryName = "Cocking"; Category3.Created = DateTime.UtcNow.Ticks; db.Category.Add(Category3); var Category4 = new Category(); Category4.CategoryName = "Biography"; Category4.Created = DateTime.UtcNow.Ticks; db.Category.Add(Category4); } //Save Changes To DataBase... db.SaveChanges(); }
// In this method we will create default User roles and Admin user for login private void createRolesandUsers() { SPContext context = new SPContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); // In Startup iam creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Admin")) { // first we create Admin rool var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); //Here we create a Admin super user who will maintain the website var user = new ApplicationUser(); user.UserName = "******"; user.Email = "*****@*****.**"; user.PhoneNumber = "0764148554"; string userPWD = "ahmadahmad"; var chkUser = userManager.Create(user, userPWD); //Add default User to Role Admin if (chkUser.Succeeded) { var result = userManager.AddToRole(user.Id, "Admin"); } //Create New UserProfile with same ID var db = new SPContext(); var userprofile = new UserProfiles(); userprofile.UserID = user.Id; userprofile.FirstName = "Ahmad"; userprofile.LastName = "Yassin"; userprofile.Created = DateTime.UtcNow.Ticks; userprofile.City = "Göteborg"; userprofile.Street = "Sandeslätt 44"; userprofile.Zip = 42436; db.UserProfiles.Add(userprofile); db.SaveChanges(); } // creating Creating Readers role if (!roleManager.RoleExists("Readers")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Readers"; roleManager.Create(role); } // creating Creating Auditors role if (!roleManager.RoleExists("Auditors")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Auditors"; roleManager.Create(role); } }