示例#1
0
        public ActionResult Checkout(CheckoutViewModel model)
        {
            if (ModelState.IsValid)
            {
                var address = _addressManager.Find(x => x.Id == model.AddressId);
                var userId  = User.Identity.GetUserId();
                var cart    = GetCart();

                var order = new Order()
                {
                    AddressLine       = address.AddressLine,
                    PostCode          = address.PostCode,
                    CityId            = address.CityId,
                    MobilePhone       = address.MobilePhone,
                    OrderDate         = DateTime.Now,
                    ApplicationUserId = userId,
                    Total             = cart.Total(),
                    OrderLines        = new List <OrderLine>()
                };
                foreach (var item in cart.CartLines)
                {
                    var oL = new OrderLine()
                    {
                        Quantity  = item.Quantity,
                        Price     = item.Product.Price * item.Quantity,
                        ProductId = item.Product.Id
                    };
                    order.OrderLines.Add(oL);
                }

                BusinessLayerResult <Order> res = _orderManager.Insert(order);

                if (res.Errors.Count > 0)
                {
                    res.Errors.ForEach(x => ModelState.AddModelError("", x.Message));
                }
                else
                {
                    cart.Clear();

                    OkViewModel notifyObj = new OkViewModel()
                    {
                        Title          = "Ödeme Başarılı.",
                        RedirectingUrl = Url.Action("UserOrders", "Account")
                    };

                    notifyObj.Items.Add("Siparişiniz alındı.");
                    notifyObj.Items.Add("Ödemenin onaylanması sonrasında siparişleriniz en kısa sürede hazırlanıp kargoya verilecektir.");

                    return(View("Ok", notifyObj));
                }
            }

            var uuserId     = User.Identity.GetUserId();
            var addressList = _addressManager.ListQueryable().Where(x => x.ApplicationUserId == uuserId).ToList();

            ViewBag.AddressId = new SelectList(addressList, "Id", "Title");

            return(View(model));
        }
示例#2
0
        public ActionResult DeleteAddress(Guid id)
        {
            var userId  = User.Identity.GetUserId();
            var address = _addressManager.Find(x => x.Id == id && x.ApplicationUserId == userId);

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

            int res = _addressManager.Delete(address);

            return(RedirectToAction("UserAddress", "Account"));
        }