Ejemplo n.º 1
0
        public bool MakeOrder(MakeOrderBindingModel model, string username)
        {
            var user = this.context.Users.SingleOrDefault(u => u.UserName == username);

            var movie = this.context.Movies.SingleOrDefault(m => m.Id == model.MovieId);

            if (user == null || movie == null || movie.TotalTickets < model.TicketCount)
            {
                return(false);
            }

            var order = Mapper.Map <Order>(model);

            order.User      = user;
            order.CreatedOn = DateTime.Now;

            movie.TotalTickets -= model.TicketCount;

            this.context.Movies.Update(movie);

            this.context.Orders.Add(order);

            this.context.SaveChanges();

            return(true);
        }
        public IActionResult MakeOrder(MakeOrderBindingModel model)
        {
            var result = this.orderService.MakeOrder(model, this.User.Identity.Name);

            if (!result)
            {
                return(NotFound());
            }

            return(this.RedirectToAction("All", "Movies"));
        }