예제 #1
0
        public void SaveOrder(WAGUser user, MakeOrderViewModel makeOrderViewModel)
        {
            var artwork = ArtisticWorkService.GetArtisticWorkById(makeOrderViewModel.ArtWorkId);

            if (makeOrderViewModel.TelephoneNumberForContact == null)
            {
                makeOrderViewModel.TelephoneNumberForContact = user.PhoneNumber;
            }

            if (makeOrderViewModel.DeliveryAddress == null)
            {
                makeOrderViewModel.DeliveryAddress = user.Address;
            }

            var order = new Order()
            {
                WAGUser      = user,
                ArtisticWork = artwork,
                OrderInfo    = makeOrderViewModel.OrderInfo,
                TelephoneNumberForContact = makeOrderViewModel.TelephoneNumberForContact,
                DeliveryAddress           = makeOrderViewModel.DeliveryAddress,
                CreatedOn = DateTime.UtcNow
            };

            this.DbContext.Orders.Add(order);
            this.DbContext.SaveChanges();
        }
예제 #2
0
        public IActionResult Order(MakeOrderViewModel model)
        {
            var pizza = StaticDb.Menu.FirstOrDefault(x => x.Name == model.PizzaName);

            var lastUserId = StaticDb.Users.Last().Id;
            var user       = new User()
            {
                Id        = lastUserId + 1,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Address   = model.Addres,
                Phone     = model.Phone
            };

            var lastOrderId = StaticDb.Orders.Last().Id;
            var order       = new Order()
            {
                Id     = lastOrderId,
                User   = user,
                Pizzas = new List <Pizza>()
                {
                    pizza
                },
                Price       = pizza.Price + 50,
                IsDelivered = false
            };


            StaticDb.Orders.Add(order);
            StaticDb.Users.Add(user);


            return(View("_ThankYou"));
        }
예제 #3
0
        public IActionResult Order(string error, int?pizzas)
        {
            var menu = _menuService.GetMenu();

            var pizzaNames = new List <string>();

            foreach (var pizza in menu)
            {
                pizzaNames.Add(pizza.Name);
            }

            var filteredPizzaNames = pizzaNames.Distinct().ToList();

            var viewModel = new MakeOrderViewModel()
            {
                PizzaNames = filteredPizzaNames,
                Pizzas     = new List <PizzaViewModel>()
            };

            for (int i = 0; i < pizzas; i++)
            {
                viewModel.Pizzas.Add(new PizzaViewModel());
            }

            ViewBag.Error = error;

            return(View(viewModel));
        }
예제 #4
0
        public MakeOrder()
        {
            MakeOrderViewModel makeOrderView = new MakeOrderViewModel();

            this.DataContext = makeOrderView;

            InitializeComponent();
        }
예제 #5
0
        public ActionResult New(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Page404", "Home"));
            }
            var model = new MakeOrderViewModel(db, id.Value);

            return(View(model));
        }
예제 #6
0
        public IActionResult MakeOrder(int id, MakeOrderViewModel makeOrderViewModel)
        {
            if (this.ArtisticWorkService.GetArtisticWorkById(id) == null)
            {
                return(RedirectToAction("Categories", "ArtisticWork"));
            }

            makeOrderViewModel.ArtWorkId = id;

            return(this.View(makeOrderViewModel));
        }
예제 #7
0
        public IActionResult MakeOrder(MakeOrderViewModel makeOrderViewModel)
        {
            if (this.ArtisticWorkService.GetArtisticWorkById(makeOrderViewModel.ArtWorkId) == null)
            {
                return(RedirectToAction("Categories", "ArtisticWork"));
            }
            var currUser = this.UserAccountService.GetCurrentUser(HttpContext);

            this.OrderService.SaveOrder(currUser, makeOrderViewModel);

            return(RedirectToAction("Success", "Home"));
        }
예제 #8
0
        public IActionResult Submit([FromForm] MakeOrderViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(OrderControllerAction.Index,
                            model: new MakeOrderViewModel(GetProducts())));
            }


            var address = new Address
            {
                Streetname = model.Streetname,
                Number     = model.Number,
                PostalCode = model.PostalCode,
                City       = model.City,
                Country    = model.Country
            };
            var customer = new Customer
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Email     = model.Email,
                Address   = address,
                //VatNumber =
            };
            var order = new Order
            {
                Date     = DateTime.UtcNow,
                Customer = customer,
                Products = model.Products,
                Status   = OrderStatus.Placed
            };

            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    _db.Addresses.Add(address);
                    _db.Customers.Add(customer);
                    _db.Orders.Add(order);
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Redirect(OrderControllerRoute.GetFail));
                }
            }

            return(Redirect(OrderControllerRoute.GetSuccess));
        }
예제 #9
0
        public ActionResult ByPartner(int id)
        {
            var clientId       = this.UserProfile.OrganizationId ?? 0;
            var nextDayOfOrder = this.ScheduleOrders.GetNextDayOfOrder(clientId, id);
            var products       = this.Products.GetProductsBySupplier(id)
                                 .Project()
                                 .To <ProductViewModel>()
                                 .ToList();
            var supplier = Mapper.Map <OrganizationViewModel>(this.Organizations.GetById(id));

            var model = new MakeOrderViewModel
            {
                NextDayOfOrder = nextDayOfOrder,
                Products       = products,
                Supplier       = supplier
            };

            return(this.View(model));
        }
예제 #10
0
        public async Task <IActionResult> MakeOrder(MakeOrderViewModel model)
        {
            ApplicationUser currentUser = await _userManager.GetUserAsync(HttpContext.User);

            if (!ModelState.IsValid)
            {
                return(View("MakeOrder", model));
            }

            Order target = new Order(
                currentUser.Id,
                model.Mail,
                model.Phone,
                model.Address);

            await _repository.MakeOrder(target);

            return(View("Index"));
        }
예제 #11
0
        public IActionResult Order()
        {
            var menu = StaticDB.Menu;

            var pizzaNames = new List <string>();

            foreach (var pizza in menu)
            {
                pizzaNames.Add(pizza.Name);
            }

            var filteredPizzaNames = pizzaNames.Distinct().ToList();

            var viewModel = new MakeOrderViewModel()
            {
                PizzaName = filteredPizzaNames
            };

            return(View(viewModel));
        }
        public IActionResult Order(MakeOrderViewModel model)
        {
            try
            {
                var pizza = StaticDb.Menu.FirstOrDefault(x => x.Name == model.Pizzas && x.Size == model.Size);

                var lastUserId = StaticDb.Users.Last().Id;

                var user = new User()
                {
                    Id        = lastUserId + 1,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Address   = model.Address,
                    Phone     = model.Phone
                };

                var lastOrderId = StaticDb.Orders.Last().Id;

                var order = new Order()
                {
                    Id          = lastOrderId + 1,
                    IsDelivered = false,
                    Price       = pizza.Price + 1.5,
                    User        = user,
                    Pizzas      = new List <Pizza>()
                    {
                        pizza
                    }
                };

                StaticDb.Users.Add(user);
                StaticDb.Orders.Add(order);
                return(View("_ThankYou"));
            }
            catch
            {
                var message = "There was problem with the order, plesae select diferent pizza.";
                return(RedirectToAction("Order", "Order", new { error = message }));
            }
        }
예제 #13
0
        public void SaveOrderShouldSaveOrderCorrect()
        {
            var options = new DbContextOptionsBuilder <WAGDbContext>()
                          .UseInMemoryDatabase(databaseName: "Save_Order_Db")
                          .Options;

            var dbContext = new WAGDbContext(options);

            var user = new WAGUser()
            {
                UserName = "******",
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var makeOrderViewModel = new MakeOrderViewModel()
            {
                ArtWorkId = 5,
                OrderInfo = "Test order info",
            };

            var artisticWorkService = new Mock <IArtisticWorkService>();

            artisticWorkService
            .Setup(a => a.GetArtisticWorkById(makeOrderViewModel.ArtWorkId))
            .Returns(new ArtisticWork()
            {
                Id = 5
            });

            var service = new OrderService(dbContext, artisticWorkService.Object);

            service.SaveOrder(user, makeOrderViewModel);

            var savedOrder = dbContext.Orders.LastOrDefault();

            Assert.NotNull(savedOrder);
            Assert.Equal(makeOrderViewModel.ArtWorkId, savedOrder.ArtisticWorkId);
            Assert.Equal(makeOrderViewModel.OrderInfo, savedOrder.OrderInfo);
        }
예제 #14
0
        public IActionResult Order()
        {
            var menu = StaticDb.Menu;

            var pizzaNames = new List <string>();

            foreach (var item in menu)
            {
                pizzaNames.Add(item.Name);
            }

            var uniquePizzaName = pizzaNames.Distinct().ToList();

            var makeOrderViewModel = new MakeOrderViewModel()
            {
                Pizzas = uniquePizzaName
            };


            return(View(makeOrderViewModel));
        }
예제 #15
0
        public IActionResult Order(MakeOrderViewModel model)
        {
            var pizza = StaticDB.Menu.FirstOrDefault(x => x.Name == model.Pizzas && x.Size == model.Size);

            var lastPizzaId = StaticDB.Menu.Last().Id;


            var user = new User()
            {
                Id = lastPizzaId += 1,

                FirstName = model.FirstName,

                LastName = model.LastName,

                Address = model.Address,

                PhoneNumber = model.Phone
            };

            var lastOrderId = StaticDB.Orders.Last().Id;

            var order = new Order()
            {
                Id          = lastOrderId += 1,
                IsDelivered = false,
                Price       = pizza.Price + 1.5,
                User        = user,
                Pizzas      = new List <Pizza>()
                {
                    pizza
                }
            };

            StaticDB.Users.Add(user);
            StaticDB.Orders.Add(order);

            return(View(model));
        }
예제 #16
0
        public IActionResult Order(MakeOrderViewModel model)
        {
            try
            {
                var user = new User()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Address   = model.Address,
                    Phone     = model.Phone
                };

                _userService.AddUser(user);

                var order = new Order()
                {
                    IsDelivered = false,
                    Price       = 1.5,
                    User        = user,
                    Pizzas      = new List <Pizza>()
                };

                foreach (var pizza in model.Pizzas)
                {
                    var tempPizza = _menuService.GetPizzaByNameAndSize(pizza.Name, pizza.Size);
                    order.Price += tempPizza.Price;
                    order.Pizzas.Add(tempPizza);
                }

                _orderService.CreateOrder(order);

                return(View("_ThankYou"));
            }
            catch (Exception ex)
            {
                var message = "We dont have selected pizza/s at this moment, please select another one.";
                return(RedirectToAction("Order", "Order", new { error = message, pizzas = model.Pizzas.Count }));
            }
        }
예제 #17
0
 public ActionResult MakeAnOrder(MakeOrderViewModel model)
 {
     shopService.CreateOrder(model.BasketId, model.Address);
     return(null);
 }
예제 #18
0
 public AddOrderWindow(MakeOrderViewModel viewModel) : this()
 {
     DataContext = viewModel;
 }