コード例 #1
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
コード例 #2
0
        public ActionResult Create(CreateCustomerViewModel customerViewModel)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customerViewModel.Customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.membershipTypeId = new SelectList(db.MembershipTypes, "ID", "Name", customerViewModel.Customer.membershipTypeId);
            return(View("Create", customerViewModel));
        }
コード例 #3
0
        public CustomerDto createCustomer(CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var customer = Mapper.Map <CustomerDto, Customer>(customerDto);

            db.Customers.Add(customer);
            db.SaveChanges();
            customerDto.custID = customer.custID;
            return(customerDto);
        }
コード例 #4
0
        public MoviesDto createMovie(MoviesDto moviesDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var movie = Mapper.Map <MoviesDto, Movie>(moviesDto);

            if (movie == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            moviesDto.movieID = movie.movieID;

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

            return(moviesDto);
        }