Ejemplo n.º 1
0
        public int New(OrderNew viewModel)
        {
            Order order = null;

            order = new Order() {
                Address1 = viewModel.Address1,
                Address2 = viewModel.Address2,
                City = viewModel.City,
                CountryId = viewModel.CountryCode,
                Country = db.Countries.First(c => c.Id == viewModel.CountryCode.ToLower()),
                Email = viewModel.Email,
                Firstname = viewModel.Firstname,
                Name = viewModel.Name,
                Salutation = viewModel.Salutation,
                Zip = viewModel.Zip,
                Comment = viewModel.Comment
            };

            var productIdsAndQtys = viewModel.Products.ToDictionary(
                k => k.Id,
                v => v.Qty);

            new ShopService().PlaceOrder(db, order, productIdsAndQtys);

            return order.Id;
        }
Ejemplo n.º 2
0
        public virtual ActionResult Index(PostOrderNew viewModel)
        {
            if (ModelState.IsValid) {

                try {
                    var order = new Order() {
                        Address1 = viewModel.Address1,
                        Address2 = viewModel.Address2,
                        City = viewModel.City,
                        CountryId = viewModel.CountryCode,
                        Country = db.Countries.First(c => c.Id == viewModel.CountryCode.ToLower()),
                        Email = viewModel.Email,
                        Firstname = viewModel.Firstname,
                        Name = viewModel.Name,
                        Salutation = viewModel.Salutation,
                        Zip = viewModel.Zip,
                        Comment = viewModel.Comment
                    };

                    var productIdsAndQtys = viewModel.Products.ToDictionary(
                        k => k.Id,
                        v => v.Qty);

                    new ShopService().PlaceOrder(db, order, productIdsAndQtys);

                    return viewModel.UsesPayPal
                        ? RedirectToAction("create", "paypal", new { orderId = order.Id })
                        : RedirectToAction("success", new { id = order.Id });

                }
                catch (AppException e) {
                    Error(e.Message);
                }
            }

			// ViewModel um die Länder anreichern.
            var vm = new OrderNew(db.Countries);
            return View("index", Mapper.Map(viewModel, vm));
        }