예제 #1
0
        public ActionResult ChosenParcelLocker(AddressesToChooseViewModel model)
        {
            Guid orderId = _orderService.Create(model.ParcelLockers.FirstOrDefault(p => p.Displayed.Equals(model.SelectedParcel)), _userService.ReturnUserByUsername(User.Identity.Name));

            if (orderId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TempData["ItemsBought"] = "Dziękujemy za zakupy :) Możesz za nie zapłacić w dolnej sekcji na tej stronie";

            return(RedirectToAction("Details", new { orderId }));
        }
예제 #2
0
        public ActionResult ChooseDeliveryAddress()
        {
            AddressesToChooseViewModel model = new AddressesToChooseViewModel();

            foreach (DeliveryAddress address in _userService.ReturnUserByUsername(User.Identity.Name).DeliveryAddresses.ToList())
            {
                model.Addresses.Add(new DeliveryAddressViewModel()
                {
                    DeliveryAddressId = address.DeliveryAddressId,
                    CompanyName       = address.CompanyName,
                    Name           = (address.Name != null && address.Surname != null)?address.Name + " " + address.Surname:address.Name ?? address.Surname,
                    StreetName     = address.StreetName,
                    City           = (address.Postcode != null && address.City != null) ? address.Postcode + " " + address.City : address.Postcode ?? address.City,
                    PhoneNumber    = address.PhoneNumber,
                    AdditionalInfo = address.AdditionalInfo
                });
            }

            HttpWebRequest  req  = (HttpWebRequest)WebRequest.Create("http://api.paczkomaty.pl/?do=listmachines_csv");
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(resp.GetResponseStream());

            string fileList = "";

            string[] tempStr;
            bool     correct;

            while (sr.Peek() >= 0)
            {
                correct  = true;
                fileList = sr.ReadLine();
                ParcelLockerAddressViewModel address = new ParcelLockerAddressViewModel();
                tempStr = fileList.Split(';');
                for (int i = 0; i < tempStr.Length; i++)
                {
                    if (tempStr.Length < 16 || (i >= 1 && i <= 4 && string.IsNullOrEmpty(tempStr[i])))
                    {
                        correct = false;
                        continue;
                    }
                    switch (i)
                    {
                    case 1:
                        address.Street = tempStr[i];
                        break;

                    case 2:
                        address.Street += " " + tempStr[i];
                        break;

                    case 3:
                        address.Postcode = tempStr[i];
                        break;

                    case 4:
                        address.City = tempStr[i];
                        break;
                    }
                }
                if (correct)
                {
                    address.Displayed = address.City + ", " + address.Street;
                    model.ParcelLockers.Add(address);
                }
            }
            sr.Close();
            model.ParcelLockers = model.ParcelLockers.OrderBy(o => o.City).ToList();
            return(View("DeliveryAddress", model));
        }