Ejemplo n.º 1
0
        // GET: Customer
        public ActionResult Index(ManageMessageId? message)
        {
            string userId = User.Identity.GetUserId();
            if (String.IsNullOrEmpty(userId))
                return RedirectToAction("Error404", "Home");
            var user = db.Users.Where(x => x.Id == userId).FirstOrDefault();
            if (User.IsInRole("Customer") && user.ActivationCode == null)
            {
                if (User.IsInRole("Supplier"))
                    return RedirectToAction("Index", "Supplier");

                if (User.IsInRole("Admin"))
                    return RedirectToAction("Index", "Admin");

                var orderList = new List<CustomerRetrieveOrdersViewModel>();
                var records = from o in db.Orders
                              where o.CustomerUserId == userId && o.Status != "Inactive"
                              select o;
                foreach (var item in records.OrderByDescending(o => o.DtCreated).Take(5))
                {
                    var orderItem = new CustomerRetrieveOrdersViewModel()
                    {
                        OrderId = item.OrderId,
                        ModelId = item.ModelId,
                        ModelNumber = (from m in db.Models
                                       where m.ModelId == item.ModelId
                                       select m.ModelNumber).FirstOrDefault(),
                        SupplierName = (from c in db.Suppliers
                                        where c.SupplierId == item.SupplierId
                                        select c.Name).FirstOrDefault(),
                        Status = item.Status,
                        DtCreated = item.DtCreated,
                        HasReturn = item.HasReturn
                    };
                    orderList.Add(orderItem);
                }
                ViewBag.Orders = orderList;

                ViewBag.StatusMessage =
                    message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                    : message == ManageMessageId.Error ? "An error has occurred."
                    : "";

                GetCustomerReturnNotification();
                GetCustomerNotification();
                return View();
            }
            return RedirectToAction("Login", "Account");
        }
Ejemplo n.º 2
0
        public ActionResult CustomerRetrieveOrders(int? page, ManageMessageId? message)
        {
            try
            {
                var initialRequest = Request.Url.AbsoluteUri.ToString();
                if (!String.IsNullOrWhiteSpace(initialRequest))
                    Session["InitialRequest"] = initialRequest;

                string userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return RedirectToAction("Login", "Account");
                }

                if (User.IsInRole("Customer"))
                {
                    var orderList = new List<CustomerRetrieveOrdersViewModel>();
                    var records = from o in db.Orders
                                  where o.CustomerUserId == userId && o.Status != "Inactive"
                                  select o;
                    foreach (var item in records)
                    {
                        var orderItem = new CustomerRetrieveOrdersViewModel()
                        {
                            OrderId = item.OrderId,
                            ModelId = item.ModelId,
                            ModelNumber = (from m in db.Models
                                           where m.ModelId == item.ModelId
                                           select m.ModelNumber).FirstOrDefault(),
                            SupplierName = (from c in db.Suppliers
                                            where c.SupplierId == item.SupplierId
                                            select c.Name).FirstOrDefault(),
                            Status = item.Status,
                            DtCreated = item.DtCreated,
                            HasReturn = item.HasReturn
                        };
                        orderList.Add(orderItem);
                    }

                    ViewBag.Title = "List of your Orders";
                    GetCustomerReturnNotification();
                    GetCustomerNotification();

                    var pageNumber = page ?? 1;
                    var pageOfProducts = orderList.OrderBy(o => o.Status).ToPagedList(pageNumber, 10);
                    ViewBag.pageOfProducts = pageOfProducts;

                    ViewBag.CustomerOrderStatus =
               message == ManageMessageId.CancelOrderSuccess ? "Your Order has been cancelled."
               : message == ManageMessageId.ReviewSuccess ? "Your review has been successfully saved."
               : message == ManageMessageId.ReviewFailure ? "You have already reviewed this model."
               : message == ManageMessageId.Error ? "An error has occurred."
               : "";
                    return View();
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public ActionResult RetrieveInactiveOrders(int? page, ManageMessageId? message)
        {
            string userId = User.Identity.GetUserId();
            if (userId == null)
            {
                return RedirectToAction("Login", "Account");
            }

            if (User.IsInRole("Customer"))
            {
                var inactiveOrders = db.Orders.Where(o => o.CustomerUserId == userId && o.Status == "Inactive");
                var orderList = new List<CustomerRetrieveOrdersViewModel>();
                foreach (var item in inactiveOrders)
                {
                    var orderItem = new CustomerRetrieveOrdersViewModel()
                    {
                        OrderId = item.OrderId,
                        ModelId = item.ModelId,
                        ModelNumber = (from m in db.Models
                                       where m.ModelId == item.ModelId
                                       select m.ModelNumber).FirstOrDefault(),
                        SupplierName = (from c in db.Suppliers
                                        where c.SupplierId == item.SupplierId
                                        select c.Name).FirstOrDefault(),
                        Status = item.Status,
                        DtCreated = item.DtCreated,
                        HasReturn = item.HasReturn
                    };
                    orderList.Add(orderItem);
                }

                ViewBag.Title = "List of your Cancelled Orders";
                GetCustomerReturnNotification();
                GetCustomerNotification();

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

                ViewBag.CustomerOrderStatus =
           message == ManageMessageId.CancelOrderSuccess ? "Your Order has been cancelled."
           : message == ManageMessageId.Error ? "An error has occurred."
           : "";

                return View();
            }
            if (User.IsInRole("Supplier"))
            {
                return RedirectToAction("Index", "Supplier");
            }
            if (User.IsInRole("Admin"))
            {
                return RedirectToAction("Index", "Admin");
            }

            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 4
0
        public ActionResult UpdatedOrders(int? page)
        {
            var userId = User.Identity.GetUserId();
            var updatedOrders = db.Orders.Where(o => o.CustomerUserId == userId && o.Notification == "Customer").ToList();
            if (updatedOrders.Count() <= 0)
            {
                return RedirectToAction("CustomerRetrieveOrders");
            }
            foreach (var item in updatedOrders)
            {
                item.Notification = null;
            }
            db.SaveChanges();

            var updatedOrderList = new List<CustomerRetrieveOrdersViewModel>();

            foreach (var item in updatedOrders)
            {
                var orderItem = new CustomerRetrieveOrdersViewModel()
                {
                    OrderId = item.OrderId,
                    ModelId = item.ModelId,
                    ModelNumber = (from m in db.Models
                                   where m.ModelId == item.ModelId
                                   select m.ModelNumber).FirstOrDefault(),
                    SupplierName = (from c in db.Suppliers
                                    where c.SupplierId == item.SupplierId
                                    select c.Name).FirstOrDefault(),
                    Status = item.Status,
                    DtCreated = item.DtCreated,
                    HasReturn = item.HasReturn
                };
                updatedOrderList.Add(orderItem);
            }

            GetCustomerReturnNotification();
            GetCustomerNotification();
            ViewBag.Title = "List of your Updated Orders";
            ViewBag.CustomerOrderStatus = "Your order status has been updated. Please check it.";

            var pageNumber = page ?? 1;
            var pageOfProducts = updatedOrderList.ToPagedList(pageNumber, 10);
            ViewBag.pageOfProducts = pageOfProducts;
            return View("CustomerRetrieveOrders");
        }