Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Price,CountryId,ShippingPriceTypeId")] ShippingPrice shippingPrice)
        {
            if (id != shippingPrice.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shippingPrice);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShippingPriceExists(shippingPrice.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ShippingPriceTypeId"] = new SelectList(_context.ShippingPriceTypes, "ID", "ID", shippingPrice.ShippingPriceTypeId);
            return(View(shippingPrice));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,Name,Price,CountryId,ShippingPriceTypeId")] ShippingPrice shippingPrice)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shippingPrice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ShippingPriceTypeId"] = new SelectList(_context.ShippingPriceTypes, "ID", "Name", shippingPrice.ShippingPriceTypeId);
            return(View(shippingPrice));
        }
        public async Task <IActionResult> Edit(string Id)
        {
            var record = await crud.GetById(Id);

            var model = new ShippingPrice()
            {
                Id      = record.Id,
                Country = record.Country,
                Price   = record.Price,
            };

            return(View(model));
        }
        public async Task <IActionResult> Edit(ShippingPrice model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var record = await crud.GetById(model.Id);

            record.Country = model.Country;
            record.Price   = model.Price;

            await crud.Update(record);


            ViewData["Success"] = "Success operation";

            return(RedirectToAction(nameof(Edit), new { id = model.Id }));
        }
        public async Task <IActionResult> Create(ShippingPrice model)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(Create)));
            }

            var record = new ShippingPrice
            {
                Country = model.Country,
                Price   = model.Price,
            };

            await crud.Add(record);

            ViewData["Success"] = "Success operation";

            return(RedirectToAction(nameof(Create)));
        }
Esempio n. 6
0
        public override object Clone()
        {
            var result = base.Clone() as ShoppingCart;

            result.HandlingTotal        = HandlingTotal?.Clone() as Money;
            result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money;
            result.DiscountAmount       = DiscountAmount?.Clone() as Money;
            result.Total                = Total?.Clone() as Money;
            result.SubTotal             = SubTotal?.Clone() as Money;
            result.SubTotalWithTax      = SubTotalWithTax?.Clone() as Money;
            result.ShippingPrice        = ShippingPrice?.Clone() as Money;
            result.ShippingPriceWithTax = ShippingPriceWithTax?.Clone() as Money;
            result.ShippingTotal        = ShippingTotal?.Clone() as Money;
            result.ShippingTotalWithTax = ShippingTotalWithTax?.Clone() as Money;
            result.PaymentPrice         = PaymentPrice?.Clone() as Money;
            result.PaymentPriceWithTax  = PaymentPriceWithTax?.Clone() as Money;
            result.PaymentTotal         = PaymentTotal?.Clone() as Money;
            result.PaymentTotalWithTax  = PaymentTotalWithTax?.Clone() as Money;
            result.HandlingTotal        = HandlingTotal?.Clone() as Money;
            result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money;
            result.DiscountTotal        = DiscountTotal?.Clone() as Money;
            result.DiscountTotalWithTax = DiscountTotalWithTax?.Clone() as Money;
            result.TaxTotal             = TaxTotal?.Clone() as Money;

            if (Discounts != null)
            {
                result.Discounts = new List <Discount>(Discounts.Select(x => x.Clone() as Discount));
            }
            if (TaxDetails != null)
            {
                result.TaxDetails = new List <TaxDetail>(TaxDetails.Select(x => x.Clone() as TaxDetail));
            }
            if (DynamicProperties != null)
            {
                result.DynamicProperties = new List <DynamicProperty>(DynamicProperties.Select(x => x.Clone() as DynamicProperty));
            }
            if (ValidationErrors != null)
            {
                result.ValidationErrors = new List <ValidationError>(ValidationErrors.Select(x => x.Clone() as ValidationError));
            }
            if (Addresses != null)
            {
                result.Addresses = new List <Address>(Addresses.Select(x => x.Clone() as Address));
            }
            if (Items != null)
            {
                result.Items = new List <LineItem>(Items.Select(x => x.Clone() as LineItem));
            }
            if (Payments != null)
            {
                result.Payments = new List <Payment>(Payments.Select(x => x.Clone() as Payment));
            }
            if (Shipments != null)
            {
                result.Shipments = new List <Shipment>(Shipments.Select(x => x.Clone() as Shipment));
            }
            if (Coupons != null)
            {
                result.Coupons = new List <Coupon>(Coupons.Select(x => x.Clone() as Coupon));
            }
            if (AvailablePaymentMethods != null)
            {
                result.AvailablePaymentMethods = new List <PaymentMethod>(AvailablePaymentMethods.Select(x => x.Clone() as PaymentMethod));
            }

            return(result);
        }
        // GET: Orders/Create
        public async Task <IActionResult> Create(Guid?id)
        {
            cartHelper.CheckAndRemove();

            OrderCreateViewModel   vm        = new OrderCreateViewModel();
            List <ShippingAddress> addresses = new List <ShippingAddress>();
            var identity    = User.Identity;
            var currentUser = _userManager.Users.Single(u => u.UserName == identity.Name);
            var userId      = currentUser.Id;

            var customer = await _context.Customers.Where(c => c.UserId == userId).SingleAsync();

            ShippingPrice shippingPriceDefault = null;
            decimal       shipDefaultPrice     = 0.0M;

            int countryDefault          = 1;   //Country 1 Deutschland
            int ShippingPeriodDefaultID = 1;

            if (customer.CustomerID != Guid.Empty)
            {
                var shipping = await _context.ShippingAddresses.SingleOrDefaultAsync(c => c.CustomerID == customer.CustomerID && c.IsMainAddress);

                if (shipping == null)
                {
                    return(RedirectToAction("CustomerIndex", "ShippingAddresses", new { id = customer.CustomerID }));
                }

                countryDefault = shipping.CountryID;
            }

            var countries = await _context.Countries.ToListAsync();

            var country = countries.Single(c => c.ID == countryDefault);

            ViewData["CustomerCountryCode"] = country.Code;

            if (id != null)
            {
                Guid cartId       = (Guid)id;
                var  shoppingCart = await _context.ShoppingCarts.SingleAsync(sc => sc.ID == id);

                decimal total = 0.0M;
                var     lines = _context.ShoppingCartLines.Where(l => l.ShoppingCartID.Equals(shoppingCart.ID));
                List <CartLineViewModel> vmcLines = new List <CartLineViewModel>();

                foreach (var item in lines)
                {
                    string path = string.Empty;
                    try
                    {
                        path = _context.ProductImages.Where(i => i.ProductID.Equals(item.ProductID) && i.IsMainImage).SingleOrDefault().ImageUrl;
                    }
                    catch (Exception)
                    {
                        path = "noImage.svg";
                    }
                    var product = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault();

                    if (ShippingPeriodDefaultID < product.ShippingPeriod)
                    {
                        ShippingPeriodDefaultID = product.ShippingPeriod;
                    }
                    var productShipPrice = await _context.ShippingPrices.SingleAsync(s => s.ShippingPriceTypeId == product.ShippingPriceType && s.CountryId == countryDefault);

                    if (shipDefaultPrice < productShipPrice.Price)
                    {
                        shipDefaultPrice     = productShipPrice.Price;
                        shippingPriceDefault = productShipPrice;
                    }

                    decimal baseprice = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault().Price;

                    decimal pPrice = 0.0M;
                    if (baseprice != 0.0M)
                    {
                        pPrice = baseprice * item.Quantity;
                    }

                    if (string.IsNullOrEmpty(path))
                    {
                        path = "noImage.svg";
                    }
                    var               unitHelper = new UnitHelper(_context, factory);
                    string            unit       = unitHelper.GetUnitName(product.BasesUnitID);
                    string            sekunit    = unitHelper.GetUnitName(product.SecondBaseUnit);
                    CartLineViewModel cvml       = new CartLineViewModel()
                    {
                        ID                      = item.ID,
                        CartID                  = item.ShoppingCartID,
                        ImgPath                 = path,
                        Position                = item.Position,
                        PosPrice                = Math.Round(pPrice, 2),
                        Quantity                = Math.Round(item.Quantity, 2),
                        ProductID               = item.ProductID,
                        Unit                    = unit,
                        ProductName             = product.Name,
                        ProductNo               = product.ProductNumber.ToString(),
                        MinimumPurchaseQuantity = Math.Round(product.MinimumPurchaseQuantity, 2),
                        AvailableQuantity       = Math.Round(product.AvailableQuantity, 2),
                        ShoppingCartID          = shoppingCart.ID,
                        SellBasePrice           = Math.Round(item.SellBasePrice, 2),
                        SellSekPrice            = Math.Round(product.SecondBasePrice, 2),
                        SekUnit                 = sekunit,
                        ShortDescription        = product.ShortDescription,
                        UnitID                  = product.BasesUnitID
                    };
                    vmcLines.Add(cvml);
                    total = total + pPrice;
                }

                CartViewModel cvm = new CartViewModel()
                {
                    ID      = shoppingCart.ID,
                    Number  = shoppingCart.Number,
                    OrderId = shoppingCart.OrderId,
                    Lines   = vmcLines,
                    Total   = total,
                };

                addresses = await _context.ShippingAddresses.Where(sh => sh.CustomerID == customer.CustomerID).ToListAsync();

                vm.ShippingAddresseVMs = new List <ShippingAddressViewModel>();
                int mainShipID = 0;
                foreach (var item in addresses)
                {
                    var shipVm = new ShippingAddressViewModel
                    {
                        ID                = item.ID,
                        FirstName         = item.FirstName,
                        LastName          = item.LastName,
                        Address           = item.Address,
                        AdditionalAddress = item.AdditionalAddress,
                        PostCode          = item.PostCode,
                        City              = item.City,
                        CountryID         = item.CountryID,
                        CustomerID        = item.CustomerID,
                        IsMainAddress     = item.IsMainAddress,
                        CountryName       = countries.Single(c => c.ID == item.CountryID).Name
                    };
                    if (shipVm.IsMainAddress)
                    {
                        mainShipID = shipVm.ID;
                    }
                    vm.ShippingAddresseVMs.Add(shipVm);
                }

                string strOrderNo = await GetActualOrderNo();

                vm.Cart                    = cvm;
                vm.Order                   = new Order();
                vm.Order.Number            = strOrderNo;
                vm.Order.CartID            = cvm.ID;
                vm.Order.ShippingAddressId = mainShipID;
                vm.Order.OrderDate         = DateTime.Now;
            }

            var paymends = await _context.Paymends.ToListAsync();

            ShippingPeriod periodDefault = await _context.ShpippingPeriods.SingleAsync(s => s.ShippingPeriodID == ShippingPeriodDefaultID);

            vm.Cart.Total = vm.Cart.Total + shipDefaultPrice;

            vm.Cart.Total = Math.Round(vm.Cart.Total, 2);

            vm.PayPalTotal = Math.Round(vm.Cart.Total, 2).ToString(CultureInfo.CreateSpecificCulture("en-US"));

            shipDefaultPrice = Math.Round(shipDefaultPrice);

            vm.ShippingPrice = shippingPriceDefault;

            vm.ShippingPeriod = periodDefault;

            vm.CanBuyWithBill = customer.AllowedPayByBill;

            ViewData["Paymends"] = paymends;


            return(View(vm));
        }
Esempio n. 8
0
File: Order.cs Progetto: p8b/OSnack
        internal async Task <PayPalCheckoutSdk.Orders.Order> ConvertToPayPalOrder()
        {
            OrderRequest orderRequest = new OrderRequest();

            orderRequest.CheckoutPaymentIntent = "CAPTURE";
            orderRequest.ApplicationContext    = new ApplicationContext()
            {
                BrandName          = AppConst.Settings.BrandName,
                UserAction         = "CONTINUE",
                ShippingPreference = "SET_PROVIDED_ADDRESS",
            };

            orderRequest.PurchaseUnits = new List <PurchaseUnitRequest>()
            {
                new PurchaseUnitRequest()
                {
                    ReferenceId         = "PUHF",
                    Description         = "Snacks and food products",
                    CustomId            = "CUST-HighFashions",
                    SoftDescriptor      = "Snacks",
                    AmountWithBreakdown = new AmountWithBreakdown()
                    {
                        CurrencyCode    = AppConst.Settings.PayPal.CurrencyCode,
                        Value           = TotalPrice.ToString("0.00"),
                        AmountBreakdown = new AmountBreakdown()
                        {
                            ItemTotal = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = TotalItemPrice.ToString("0.00")
                            },
                            Shipping = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = ShippingPrice.ToString("0.00")
                            },
                            Discount = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = TotalDiscount.ToString("0.00")
                            }
                        }
                    },
                    Items = ConvertItem(),
                }
            };
            if (User != null)
            {
                orderRequest.PurchaseUnits.FirstOrDefault().ShippingDetail = new ShippingDetail()
                {
                    Name = new Name()
                    {
                        FullName = $"{User.FirstName} {User.Surname}"
                    },
                    AddressPortable = new AddressPortable()
                    {
                        AddressLine1 = FirstLine,
                        AddressLine2 = SecondLine,
                        PostalCode   = Postcode,
                        CountryCode  = "GB",
                        AdminArea1   = "UK",
                        AdminArea2   = City
                    },
                };
                orderRequest.Payer = new Payer()
                {
                    Email = User.Email,
                    Name  = new Name()
                    {
                        GivenName = User.FirstName,
                        Surname   = User.Surname
                    },
                    AddressPortable = new AddressPortable()
                    {
                        AddressLine1 = FirstLine,
                        AddressLine2 = SecondLine,
                        PostalCode   = Postcode,
                        CountryCode  = "GB",
                        AdminArea2   = City
                    }
                };
            }
            else
            {
                orderRequest.ApplicationContext.ShippingPreference = "GET_FROM_FILE";
            }
            OrdersCreateRequest request = new OrdersCreateRequest();

            request.Prefer("return=representation");

            request.RequestBody(orderRequest);
            var response = await PayPalClient.client().Execute(request).ConfigureAwait(false);

            PayPalCheckoutSdk.Orders.Order paypalOrder = response.Result <PayPalCheckoutSdk.Orders.Order>();

            return(paypalOrder);
        }