示例#1
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                string name        = collection["name"];
                string description = collection["description"];

                if (string.IsNullOrWhiteSpace(name))
                {
                    return(BadRequest());
                }

                Film film = new Film()
                {
                    Name        = name,
                    Description = description
                };
                _context.Films.Add(film);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
        public ActionResult Reserve(IFormCollection collection)
        {
            try
            {
                string sessionIdStr = collection["sessionId"];
                string seatIdStr    = collection["seatId"];
                string emailStr     = collection["email"];

                if (string.IsNullOrWhiteSpace(sessionIdStr) ||
                    string.IsNullOrWhiteSpace(seatIdStr) ||
                    string.IsNullOrWhiteSpace(emailStr)
                    )
                {
                    return(BadRequest("All field is required"));
                }

                Ticket ticket = new Ticket()
                {
                    Email     = emailStr,
                    SessionId = int.Parse(sessionIdStr),
                    SeatId    = int.Parse(seatIdStr)
                };

                _context.Tickets.Add(ticket);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
示例#3
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                string filmId    = collection["FilmId"];
                string hallId    = collection["HallId"];
                string is3d      = collection["Is3d"];
                string price     = collection["Price"];
                string startTime = collection["StartTime"];


                if (string.IsNullOrWhiteSpace(filmId) ||
                    string.IsNullOrWhiteSpace(hallId) ||
                    string.IsNullOrWhiteSpace(is3d) ||
                    string.IsNullOrWhiteSpace(price) ||
                    string.IsNullOrWhiteSpace(startTime)
                    )
                {
                    return(BadRequest());
                }

                Session session = new Session()
                {
                    FilmId    = int.Parse(filmId),
                    HallId    = int.Parse(hallId),
                    Is3d      = is3d.Contains("true"),
                    Price     = decimal.Parse(price),
                    StartTime = DateTime.Parse(startTime)
                };

                _context.Sessions.Add(session);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
示例#4
0
        public static void Initialize(TestContext tc)
        {
            var options = new DbContextOptionsBuilder <Lab1Context>().UseInMemoryDatabase(databaseName: "Lab1TestDb").Options;

            _context = new Lab1Context(options);

            Dealership dealership1 = new Dealership {
                Name = "dealership1", Email = "*****@*****.**"
            };
            Dealership dealership2 = new Dealership {
                Name = "dealership2", Email = "*****@*****.**"
            };

            _context.Dealership.AddRange(dealership1, dealership2);
            _context.SaveChanges();
        }