public ActionResult Create([Bind(Include = "MovieId,DirectorId,YearRangeId,Title,Price,Year,Rating, Description")] Movie movie, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var poster = new File
                    {
                        FileName    = System.IO.Path.GetFileName(upload.FileName),
                        FileType    = FileType.Poster,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        poster.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    movie.Files = new List <File> {
                        poster
                    };
                }
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.DirectorId  = new SelectList(db.Directors, "DirectorId", "Name", movie.DirectorId);
            ViewBag.YearRangeId = new SelectList(db.YearRanges, "YearRangeId", "Range", movie.YearRangeId);

            return(View(movie));
        }
示例#2
0
 public ActionResult Edit([Bind(Include = "Id, Name")] IdentityRole role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(role));
 }
        public ActionResult Create([Bind(Include = "YearRangeId,Range")] YearRange yearrange)
        {
            if (ModelState.IsValid)
            {
                db.YearRanges.Add(yearrange);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(yearrange));
        }
        public ActionResult Create([Bind(Include = "Id,Title,YearRelasesed,Price,GenreId")] MoviesTable moviesTable)
        {
            if (ModelState.IsValid)
            {
                db.MoviesTable.Add(moviesTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(moviesTable));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "GenreId,Name,Description")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "DirectorId,Name")] Director director)
        {
            if (ModelState.IsValid)
            {
                db.Directors.Add(director);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(director));
        }
示例#7
0
        public IHttpActionResult CreateMovie(MovieDto movieDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var movie = Mapper.Map <MovieDto, Movie>(movieDto);

            _context.Movies.Add(movie);
            _context.SaveChanges();

            movieDto.Id = movie.Id;
            return(Created(new Uri(Request.RequestUri + "/" + movie.Id), movieDto));
        }
        public ActionResult Save(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieFormViewModel(movie)
                {
                    Genres = _context.Genres.ToList(),
                };
                return(View("MovieForm", viewModel));
            }
            if (movie.Id == 0)
            {
                movie.DateAdded = DateTime.Now;
                _context.Movies.Add(movie);
            }
            else
            {
                var MovieDb = _context.Movies.Single(m => m.Id == movie.Id);

                MovieDb.Name          = movie.Name;
                MovieDb.GenreId       = movie.GenreId;
                MovieDb.NumberInStock = movie.NumberInStock;
                MovieDb.ReleaseDate   = movie.ReleaseDate;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerFormViewModel
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("CustomerForm", viewModel));
            }

            if (customer.Id == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _context.Customers.Single(c => c.Id == customer.Id);

                customerInDb.Name      = customer.Name;
                customerInDb.Birthdate = customer.Birthdate;
                customerInDb.isSubscribedToNewsletter = customer.isSubscribedToNewsletter;
                customerInDb.MembershipTypeId         = customer.MembershipTypeId;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Customer"));
        }
示例#10
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();
                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return(RedirectToAction("Complete", new { id = order.OrderId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
示例#11
0
        public IHttpActionResult CreateCustomer(CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            var customer = Mapper.Map <CustomerDto, Customer>(customerDto);

            _context.Customers.Add(customer);
            _context.SaveChanges();

            customerDto.Id = customer.Id;

            return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDto));
        }