public IActionResult Index(OrderPizzaVM orderModel) { if (string.IsNullOrEmpty(orderModel.User.Address)) { return(RedirectToAction("Index", "Order", new { id = orderModel.Pizza.Id, error = "All fields requied" })); } Pizza pizza = StaticDb.Menu.SingleOrDefault(p => p.Id == orderModel.Pizza.Id); User user = new User() { Id = StaticDb.Users.Count + 1, Address = orderModel.User.Address, FirstName = orderModel.User.FirstName, LastName = orderModel.User.LastName, Phone = orderModel.User.Phone }; Order order = new Order() { Delivered = false, Id = StaticDb.Orders.Count + 1, Pizza = pizza, User = user }; StaticDb.Users.Add(user); StaticDb.Orders.Add(order); return(RedirectToAction("OrderMenu")); }
public static Order OrderVMToOrder(OrderPizzaVM model) { return(new Order() { Delivered = model.Delivered, Pizza = PizzaMapper.PizzaVMtoPizza(model.Pizza), User = UserMapper.UserVMtoUser(model.User) }); }
public IActionResult Index(OrderPizzaVM orderModel) { if (string.IsNullOrEmpty(orderModel.User.Address)) { return(RedirectToAction("Index", "Order", new { id = orderModel.Pizza.Id, error = "All fields requied" })); } return(RedirectToAction("OrderMenu")); }
public string CreateNewOrder(OrderPizzaVM model) { var order = OrderMapper.OrderVMtoOrder(model); int response = _orderRepository.Create(order); if (response == -1) { return("Was not successfull, please try again later!"); } return("Order successfully created!"); }
public string CreateNewOrder(OrderPizzaVM model) { var order = OrderMapper.OrderVMToOrder(model); int response = _orderRepository.Create(order); if (response == -1) { return("Order was not correct. Try again"); } return("Order created successfully!"); }
// GET: Order public ActionResult Index(int id, string error) { ViewBag.Error = error == null ? "" : error; var pizza = _pizzaService.GetPizzaById(id); var order = new OrderPizzaVM() { Pizza = pizza }; return(View(order)); }
public string CreateNewOrder(OrderPizzaVM model) { var order = OrderMapper.OrderVMToOrder(model); order.Id = _orderRepo.GetAll().Count + 1; int responce = _orderRepo.Create(order); if (responce == -1) { return("Was not successfull, please try again later."); } return("Order successfully created!"); }
public static Order OrderVMToOrder(OrderPizzaVM orderVM) { return(new Order() { //Delivered = orderVM.Delivered, //Pizza = new Pizza() { Name = orderVM.Pizza.Name, Size = orderVM.Pizza.Size, Price = orderVM.Pizza.Price, ImageUrl = orderVM.Pizza.ImageUrl}, //User = new User() { FirstName = orderVM.User.FirstName, LastName = orderVM.User.LastName, Address = orderVM.User.Address, Phone = orderVM.User.Phone} Delivered = orderVM.Delivered, Pizza = PizzaMapper.PizzaVMToPizza(orderVM.Pizza), User = UserMapper.UserVMToUser(orderVM.User) }); }
public IActionResult Index(OrderPizzaVM orderModel) { if (string.IsNullOrEmpty(orderModel.User.Address)) { return(RedirectToAction("Index", "Order", new { id = orderModel.Pizza.Id, error = "All fields are required" })); } var pizza = _pizzaService.GetPizzaById(orderModel.Pizza.Id); orderModel.Pizza = pizza; _userService.CreateNewUser(orderModel.User); _orderService.CreateNewOrder(orderModel); return(RedirectToAction("OrderMenu")); }
public IActionResult Index(int id, string error) { var pizzaDomain = StaticDb.Menu.SingleOrDefault(pizza => pizza.Id == id); var pizzaVM = new PizzaVM() { Id = pizzaDomain.Id, Name = pizzaDomain.Name, Size = pizzaDomain.Size, Price = pizzaDomain.Price, ImageUrl = pizzaDomain.ImageUrl }; var userVM = new UserVM(); var oderVM = new OrderPizzaVM() { Pizza = pizzaVM, User = userVM }; ViewBag.Error = error == null ? "" : error; return(View(oderVM)); }
public IActionResult Index(OrderPizzaVM orderModel) { if (string.IsNullOrEmpty(orderModel.User.Address)) { return(RedirectToAction("Index", "Order", new { id = orderModel.Pizza.Id, error = "All fields requied" })); } //Pizza pizza = StaticDb.Menu.SingleOrDefault(p => p.Id == orderModel.Pizza.Id); //User user = new User() //{ // Id = StaticDb.Users.Count + 1, // Address = orderModel.User.Address, // FirstName = orderModel.User.FirstName, // LastName = orderModel.User.LastName, // Phone = orderModel.User.Phone //}; //Order order = new Order() //{ // Delivered = false, // Id = StaticDb.Orders.Count + 1, // Pizza = pizza, // User = user //}; //StaticDb.Users.Add(user); //StaticDb.Orders.Add(order); var pizza = _pizzaService.GetPizzaById(orderModel.Pizza.Id); var newUser = new UserVM() { FirstName = orderModel.User.FirstName, LastName = orderModel.User.LastName, Address = orderModel.User.Address, Phone = orderModel.User.Phone }; orderModel.Pizza = pizza; orderModel.User = newUser; _userService.CreateNewUser(newUser); _orderService.CreateNewOrder(orderModel); return(RedirectToAction("OrderMenu")); }
public IActionResult Index(int id, string error) { //var pizzaDomain = StaticDb.Menu.SingleOrDefault(pizza => pizza.Id == id); //var pizzaVM = new PizzaVM() //{ // Id = pizzaDomain.Id, // Name = pizzaDomain.Name, // Size = pizzaDomain.Size, // Price = pizzaDomain.Price, // ImageUrl = pizzaDomain.ImageUrl //}; //var userVM = new UserVM(); //var orderVM = new OrderPizzaVM() { Pizza = pizzaVM, User = userVM }; var pizzaVM = _pizzaService.GetPizzaById(id); var userVM = new UserVM(); var orderVM = new OrderPizzaVM() { Pizza = pizzaVM, User = userVM }; ViewBag.Error = error == null ? "" : error; return(View(orderVM)); }