// 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));
        }
Пример #2
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        /// <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));
        }
Пример #8
0
        public bool Commit()
        {
            transaction = db.Database.BeginTransaction();
            int affected = db.SaveChanges();

            transaction.Commit();
            return(affected > 0);
        }
Пример #9
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"));
        }
Пример #10
0
        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 }));
        }
Пример #11
0
        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();
        }
Пример #12
0
        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());
        }
Пример #13
0
 public bool InsertCategoryType(Category cateogory)
 {
     try
     {
         db.Categories.Add(cateogory);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Пример #14
0
 public bool InsertMovieType(MovieType movieType)
 {
     try
     {
         db.MovieTypes.Add(movieType);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Пример #15
0
        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();
        }
Пример #16
0
        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");
        }