// PUT api/Genres/5 public HttpResponseMessage PutGenre(int id, Genre genre) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != genre.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(genre).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, genre)); }
public IHttpActionResult PutMovie(int id, Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movie.MovieId) { return(BadRequest()); } db.Entry(movie).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// PUT api/ReviewsByGenre/5 public HttpResponseMessage PutvWGetReviewsByGenre(string id, vWGetReviewsByGenre vwgetreviewsbygenre) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != vwgetreviewsbygenre.Name) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(vwgetreviewsbygenre).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult Create([Bind(Include = "MovieId,Title,Length,Price,Amount,Date,Description,Director,IMDBScore")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public ActionResult Create([Bind(Include = "MovieId,Title,Price,ImageUrl")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
/// <summary> /// User hozzáadása az Adabzásihoz /// Ellenőrzi hogy vannak-e ütközések, vagy hibák /// </summary> /// <param name="registerModel"></param> /// <returns>AccountCreateStatus enum hozzáadás eredménye szerint</returns> public static AccountCreateStatus CreateUser(RegisterModel registerModel) { // Van egyező username if (storeEntities.Accounts.Any(account => account.UserName == registerModel.UserName)) { return(AccountCreateStatus.DuplicateUserName); } // Van egyező email else if (storeEntities.Accounts.Any(account => account.Email == registerModel.Email)) { return(AccountCreateStatus.DuplicateEmail); } // invalid password if ((registerModel.Password.Length < 6 || registerModel.Password.Length > 100) || (registerModel.Password != registerModel.ConfirmPassword)) { return(AccountCreateStatus.InvalidPassword); } // invalid username if (registerModel.UserName == "") { return(AccountCreateStatus.InvalidUserName); } // invalid email: üres, vagy nincs benne kukac //forma: [email protected] if (registerModel.Email == "" || registerModel.Email.Split('@').Length != 2) { return(AccountCreateStatus.InvalidEmail); } //invalid email: van benne kukac, de a kukac utáni részben nem csak egy pont van //forma: [email protected] if (registerModel.Email.Split('@')[1] .Split('.').Length != 2) { return(AccountCreateStatus.InvalidEmail); } // nem dobott hibát azaz beletette az entitibe storeEntities.Accounts.Add( new Account() { UserName = registerModel.UserName, Email = registerModel.Email, Password = registerModel.Password }); storeEntities.SaveChanges(); return(AccountCreateStatus.Success); }
public ActionResult Create(Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", movie.GenreId); ViewBag.ActorId = new SelectList(db.Actors, "ActorId", "Name", movie.ActorId); return(View(movie)); }
public bool Commit() { transaction = db.Database.BeginTransaction(); int affected = db.SaveChanges(); transaction.Commit(); return(affected > 0); }
public ActionResult Add(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cart cart = db.Carts.Find(id); if (cart == null) { return(HttpNotFound()); } int quantity = cart.Count; quantity++; // in case there are no more items in the storage if (quantity > db.Movies.Find(cart.MovieId).Amount) { string Error = String.Format("The amount in the storage for {0} is not avaiable", Data.getInstance().getDictionary()[cart.MovieId]); TempData["AmountMessage"] = Error; return(RedirectToAction("Index")); } else { db.Database.ExecuteSqlCommand("UPDATE dbo.Carts SET Count = Count+1 WHERE CartId = {0}", id); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult AddMyEmployee(Employee employee) { if (!ModelState.IsValid) { EmployeeManiViewModel model = new EmployeeManiViewModel { Employee = new Employee(), Titles = _db.Titles.ToList() }; return(View(model)); } _db.Entry(employee).State = System.Data.Entity.EntityState.Added; _db.SaveChanges(); return(RedirectToAction("AddMyEmployeeDetail", new { id = employee.EmployeeID })); }
public void AddMovie(MovieDTO m) { // do data check; var movie = new Movie { Title = m.Title, Genre = m.Genre, About = m.About, Rating = m.Rating }; _db.Movie.Add(movie); _db.SaveChanges(); }
public ActionResult Index(User u, object [] GenreList) { MultiSelectList l = ViewBag.GenreList; List <string> genres = new List <string>(); User newUser = new User(); if (ModelState.IsValid) { newUser.UserName = u.UserName; newUser.Password = u.Password; newUser.ConfirmPassword = u.ConfirmPassword; newUser.CreditCardNumber = u.CreditCardNumber; newUser.Email = u.Email; newUser.FirstName = u.FirstName; newUser.LastName = u.LastName; newUser.QuestionId = u.QuestionId; newUser.Answer = u.Answer; newUser.City = u.City; newUser.Address = u.Address; newUser.CountryId = u.CountryId; newUser.Cellular = u.Cellular; newUser.Phone = u.Phone; db.Users.Add(newUser); //save the user db.SaveChanges(); //save the question for the user. UserQuestion uq = new UserQuestion(); uq.UserId = newUser.UserId; uq.QuestionId = newUser.QuestionId; db.UserQuestions.Add(uq); db.SaveChanges(); foreach (object o in GenreList) { UserGenre ug = new UserGenre(); ug.GenreId = Convert.ToInt32(o); ug.UserId = newUser.UserId; db.UserGenres.Add(ug); } db.SaveChanges(); return(RedirectToAction("Index", "Login")); } return(View()); }
public bool InsertCategoryType(Category cateogory) { try { db.Categories.Add(cateogory); db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
public bool InsertMovieType(MovieType movieType) { try { db.MovieTypes.Add(movieType); db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
public void RentMovieById(int id, string UserName) { var movie = GetMovieById(id); var rent = new Rent { MovieId = id, MovieTitle = movie.Title, UserId = UserName }; _db.Rent.Add(rent); _db.SaveChanges(); }
public string CreateUser(UserRegistrationViewModel um) { User u = new User(); u.Id = Guid.NewGuid().ToString(); u.UserName = um.UserName; u.PasswordHash = Password.sha256(um.Password); u.CreatedAt = DateTime.Now; u.Status = true; u.Roles = 0; try { db.Users.Add(u); db.SaveChanges(); } catch (Exception) { throw; } return("Ok"); }