Пример #1
0
 public void Shipping(ShippingInfoInputModel shipping)
 {
     if (string.IsNullOrEmpty(shipping.FullName))
     {
         throw new Exception("You need to put your name here");
     }
     else if (String.IsNullOrEmpty(shipping.Country))
     {
         throw new Exception("Please select a country");
     }
     else if (String.IsNullOrEmpty(shipping.Zipcode))
     {
         throw new Exception("You need enter your zipcode");
     }
     else if (string.IsNullOrEmpty(shipping.City))
     {
         throw new Exception("You need enter your city");
     }
     else if (string.IsNullOrEmpty(shipping.Adress))
     {
         throw new Exception("You need to enter your adress");
     }
     else if (string.IsNullOrEmpty(shipping.PhoneNumber))
     {
         throw new Exception("Please enter a valid phone number");
     }
     // if(_orderRepo.G)
 }
Пример #2
0
        //Upplisingar sendingarupplýsingar
        public bool ShippingInfo(ShippingInfoInputModel shipping, string user, int cartId)
        {
            if (cartId == 0)
            {
                return(false);
            }
            //Bý til nýjar sendinarupplýsingar
            //Á eftir að útfæra ef notandi hefur þegar gert pöntun og hann vill breyta
            //Get séð út frá nýjasta ID með pöntuninni hvað á að nota
            var userInfo = new ShippingInfo
            {
                UserId      = user,
                OrderId     = cartId,
                FullName    = shipping.FullName,
                Country     = shipping.Country,
                Zipcode     = shipping.Zipcode,
                City        = shipping.City,
                Adress      = shipping.Adress,
                PhoneNumber = shipping.PhoneNumber
            };

            //ef næst ekki í notanda
            if (userInfo == null)
            {
                return(false);
            }
            //bæti við í gangagrunninn
            _db.ShippingInfos.Add(userInfo);
            _db.SaveChanges();
            return(true);
        }
Пример #3
0
 public IActionResult ShippingInfo(ShippingInfoInputModel shipping)
 {
     ViewBag.Title = "Flutnings upplýsingar";
     if (ModelState.IsValid)
     {
         string userId = _userManager.GetUserId(User);
         _accountService.AddShippingInfo(shipping, userId);
         return(RedirectToAction("MyAccount", "Account"));
     }
     return(View(shipping));
 }
Пример #4
0
        public void UpdateShippingInfo(ShippingInfoInputModel shipping, string userId)
        {
            var newShipping = _db.ShippingInfo.Find(shipping.Id);

            newShipping.PostalCode    = shipping.PostalCode;
            newShipping.Street        = shipping.Street;
            newShipping.City          = shipping.City;
            newShipping.Country       = shipping.Country;
            newShipping.SendingMethod = shipping.SendingMethod;

            _db.SaveChanges();
        }
Пример #5
0
        public IActionResult Shipping(ShippingInfoInputModel shipping)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }
            var user   = _userManager.GetUserId(User);
            var cartId = _orderServices.GetCart(user);

            //if ()
            if (!_orderServices.ShippingInfo(shipping, user, cartId))
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }
            return(RedirectToAction("BillingInfo"));
        }
Пример #6
0
        public IActionResult ShippingInfo()
        {
            ViewBag.Title = "Flutnings upplýsingar";
            var shippingInfo     = new ShippingInfoInputModel();
            var shippingInfoView = _accountService.GetShippingInfo(_userManager.GetUserId(User));

            if (shippingInfoView != null)
            {
                shippingInfo.Id            = shippingInfoView.Id;
                shippingInfo.Street        = shippingInfoView.Street;
                shippingInfo.City          = shippingInfoView.City;
                shippingInfo.PostalCode    = shippingInfoView.PostalCode;
                shippingInfo.SendingMethod = shippingInfoView.SendingMethod;
                shippingInfo.Country       = shippingInfoView.Country;
            }
            return(View(shippingInfo));
        }
Пример #7
0
        public void AddShippingInfo(ShippingInfoInputModel shipping, string userId)
        {
            var user = GetShippingInfo(userId);

            if (user != null)
            {
                shipping.Id = user.Id;
                UpdateShippingInfo(shipping, userId);
            }
            else
            {
                var newShipping = new ShippingInfo
                {
                    UserId        = userId,
                    Street        = shipping.Street,
                    City          = shipping.City,
                    PostalCode    = shipping.PostalCode,
                    Country       = shipping.Country,
                    SendingMethod = shipping.SendingMethod
                };
                _db.ShippingInfo.Add(newShipping);
                _db.SaveChanges();
            }
        }
Пример #8
0
 public void AddShippingInfo(ShippingInfoInputModel shipping, string userId)
 {
     _accountRepo.AddShippingInfo(shipping, userId);
 }