コード例 #1
0
 // GET: DeliveryAddress
 public ActionResult Retrieve()
 {
     var userId = User.Identity.GetUserId();
     if (userId == null)
     {
         return RedirectToAction("Login", "Account");
     }
     if (User.IsInRole("Admin"))
     {
         var records = db.DeliveryAddresses.ToList();
         var addressList = new List<DeliveryAddressActionViewModel>();
         foreach (var item in records)
         {
             var addressItem = new DeliveryAddressActionViewModel()
             {
                 DeliveryAddressId = item.DeliveryAddressId,
                 UserId = item.UserId,
                 CustomerId = item.CustomerId,
                 Street = item.Street,
                 City = item.City,
                 Zipcode = item.Zipcode,
                 Status = item.Status
             };
             addressList.Add(addressItem);
         }
         return View(addressList);
     }
     return RedirectToAction("Login", "Account");
 }
コード例 #2
0
        // public ActionResult CustomerUpdateDeliveryAddress(DeliveryAddressActionViewModel item)
        public ActionResult CustomerUpdateDeliveryAddress(DeliveryAddressActionViewModel item)
        {
            //var recordToUpdate = Session["Data"] as DeliveryAddressActionViewModel;
            var userId = User.Identity.GetUserId();
            if (userId == null || !User.IsInRole("Customer"))
            {
                return RedirectToAction("Login", "Account");
            }
            if (ModelState.IsValid)
            {
                ViewBag.DeliveryAddressStatusId = new SelectList(db.DeliveryAddressStatuses, "DeliveryAddressStatusId", "Status", item.DeliveryAddressStatusId);

                var updatedRecord = db.DeliveryAddresses.Where(x => x.DeliveryAddressId == item.DeliveryAddressId).FirstOrDefault();

                //updatedRecord.CustomerId = updatedRecord.CustomerId;
                //updatedRecord.UserId = updatedRecord.UserId;
                updatedRecord.Zipcode = item.Zipcode;
                updatedRecord.City = item.City;
                updatedRecord.Street = item.Street;
                updatedRecord.Status = (from da in db.DeliveryAddressStatuses
                                        where da.DeliveryAddressStatusId == item.DeliveryAddressStatusId
                                        select da.Status).FirstOrDefault();
                if (updatedRecord.Status == "Default")
                {
                    var allDelAddress = db.DeliveryAddresses.Where(x => x.Status == "Default" && x.UserId == userId);
                    foreach (var obj in allDelAddress)
                    {
                        obj.Status = "Other";
                    }
                }
                if (updatedRecord.Status == "Other")
                {
                    var allDelAddress = db.DeliveryAddresses.Where(x => x.Status == "Default" && x.UserId == userId && x.DeliveryAddressId != updatedRecord.DeliveryAddressId);
                    if (!allDelAddress.Any())
                    {
                        var firstDelAddress = db.DeliveryAddresses.OrderByDescending(x => x.DeliveryAddressId).FirstOrDefault();
                        firstDelAddress.Status = "Default";
                    }
                }
                db.SaveChanges();

                string requestedUrl = Session["InitialRequest"] as string;
                if (String.IsNullOrWhiteSpace(requestedUrl))
                {
                    return RedirectToAction("CustomerRetrieveDeliveryAddress", "Customer");
                }
                Session.Remove("InitialRequest");

                GetCustomerReturnNotification();
                GetCustomerNotification();
                return Redirect(requestedUrl);
            }

            return RedirectToAction("Home", "Error404");
        }
コード例 #3
0
        public ActionResult CustomerUpdateDeliveryAddress(int id)
        {
            var userId = User.Identity.GetUserId();
            if (userId == null || !User.IsInRole("Customer"))
            {
                return RedirectToAction("Login", "Account");
            }
            var record = db.DeliveryAddresses.Where(x => x.UserId == userId && x.DeliveryAddressId == id).FirstOrDefault();
            if (record == null)
                return RedirectToAction("Home", "Error404");

            var recordToUpdate = new DeliveryAddressActionViewModel()
            {
                City = record.City,
                CustomerId = record.CustomerId,
                DeliveryAddressId = record.DeliveryAddressId,
                Status = record.Status,
                Street = record.Street,
                Zipcode = record.Zipcode,

                //DeliveryAddressStatusId = 2,
                UserId = record.UserId
            };

            //Need to test !!
            ViewBag.DeliveryAddressStatusId = new SelectList(db.DeliveryAddressStatuses, "DeliveryAddressStatusId", "Status");

            GetCustomerReturnNotification();
            GetCustomerNotification();

            //Session["Data"] = recordToUpdate;
            return View(recordToUpdate);
        }
コード例 #4
0
        public ActionResult CustomerCreateDeliveryAddress(DeliveryAddressActionViewModel item)
        {
            var userId = User.Identity.GetUserId();
            if (userId == null || !User.IsInRole("Customer"))
            {
                return RedirectToAction("Login", "Account");
            }
            if (ModelState.IsValid)
            {
                ViewBag.DeliveryAddressStatusId = new SelectList(db.DeliveryAddressStatuses, "DeliveryAddressStatusId", "Status", item.DeliveryAddressStatusId);
                var deliveryAddress = new DeliveryAddressViewModel()
                {
                    UserId = userId,
                    CustomerId = (from c in db.Customers
                                  where c.Id == userId
                                  select c.CustomerId).FirstOrDefault(),
                    Street = item.Street,
                    City = item.City,
                    Zipcode = item.Zipcode,
                    Status = (from ds in db.DeliveryAddressStatuses
                              where ds.DeliveryAddressStatusId == item.DeliveryAddressStatusId
                              select ds.Status).FirstOrDefault()
                };
                if (deliveryAddress.Status == "Default")
                {
                    var otherAddresses = db.DeliveryAddresses.Where(x => x.UserId == userId).ToList();
                    if (otherAddresses != null)
                    {
                        foreach (var obj in otherAddresses)
                        {
                            obj.Status = "Other";
                        }
                    }
                }
                db.DeliveryAddresses.Add(deliveryAddress);
                db.SaveChanges();

                GetCustomerReturnNotification();
                GetCustomerNotification();
                return RedirectToAction("CustomerRetrieveDeliveryAddress", "Customer", new { message = ManageMessageId.AddDeliveryAddressSuccess });
            }
            return RedirectToAction("Login", "Account");
        }
コード例 #5
0
 public ActionResult CustomerCreateDeliveryAddress()
 {
     var userId = User.Identity.GetUserId();
     if (userId == null || !User.IsInRole("Customer"))
     {
         return RedirectToAction("Login", "Account");
     }
     var deliveryAddress = new DeliveryAddressActionViewModel();
     ViewBag.DeliveryAddressStatusId = new SelectList(db.DeliveryAddressStatuses, "DeliveryAddressStatusId", "Status");
     GetCustomerNotification();
     return View(deliveryAddress);
 }
コード例 #6
0
        public ActionResult CustomerRetrieveDeliveryAddress(string returnUrl, ManageMessageId? message, int? page)
        {
            var userId = User.Identity.GetUserId();
            if (userId == null)
            {
                return RedirectToAction("Login", "Account");
            }
            if (User.IsInRole("Customer"))
            {
                string requestedUrl = returnUrl;

                //if (String.IsNullOrEmpty(requestedUrl))
                //{
                //    return View();
                //}
                Session["InitialRequest"] = requestedUrl;

                var records = db.DeliveryAddresses.Where(x => x.UserId == userId && x.Status != "Archived");
                var addressList = new List<DeliveryAddressActionViewModel>();
                foreach (var item in records)
                {
                    var addressItem = new DeliveryAddressActionViewModel()
                    {
                        DeliveryAddressId = item.DeliveryAddressId,
                        UserId = item.UserId,
                        CustomerId = item.CustomerId,
                        Street = item.Street,
                        City = item.City,
                        Zipcode = item.Zipcode,
                        Status = item.Status
                    };
                    addressList.Add(addressItem);
                }
                ViewBag.StatusMessage =
                message == ManageMessageId.AddDeliveryAddressSuccess ? "New delivery address successfully added."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";

                GetCustomerReturnNotification();
                GetCustomerNotification();

                var pageNumber = page ?? 1;
                var pageOfProducts = addressList.ToPagedList(pageNumber, 10);
                ViewBag.pageOfProducts = pageOfProducts;

                return View();
            }
            return RedirectToAction("Login", "Account");
        }