Beispiel #1
0
        public ActionResult getRecentActivity(int cid)
        {
            using (MainContext db = new MainContext())
            {
                var recentOrders =
                    (
                        from ro in db.Orders

                        where (ro.CustomerId == cid)
                        select ro
                    ).ToList();


                var cpObject = new CustomerProfileVM();

                foreach (var item in recentOrders)
                {
                    var order = new ViewModels.CustomerOrder();

                    order.OrderId    = item.OrderId;
                    order.CustomerId = item.CustomerId;


                    cpObject.recentActivity.Add(order);
                    cpObject.CustomerProfileVMId = cid;
                    db.SaveChanges();
                }

                return(Redirect("/CustomerProfile/" + cid));

                //var data = db.Orders.Where(e => e.CustomerId == cid);
                //return Json(data, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #2
0
        public void postProfile(string id, CustomerProfileVM vm)
        {
            CustomerInfo CustInfo = _db.Users.Where(u => u.Id == id).FirstOrDefault().CustomerInfo;

            if (CustInfo != null)
            {
                if (vm.FirstName != null)
                {
                    CustInfo.FirstName = vm.FirstName;
                }
                if (vm.LastName != null)
                {
                    CustInfo.LastName = vm.LastName;
                }
                if (vm.ImageUrl != null)
                {
                    CustInfo.ImageUrl = vm.ImageUrl;
                }
                if (vm.Gender != null)
                {
                    CustInfo.Gender = vm.Gender;
                }
            }

            _db.SaveChanges();
        }
        public IHttpActionResult PostProfile(CustomerProfileVM vm)
        {
            var userId = User.Identity.GetUserId();

            if (_unit.User.IsSeat(userId) || _unit.User.IsCustomer(userId))
            {
                _unit.Customer.postProfile(userId, vm);

                return(Ok());
            }
            return(Unauthorized());
        }
Beispiel #4
0
        public CustomerProfileVM ReadCustomerProfile(int customerId)
        {
            CustomerProfileVM _customerProfile = new CustomerProfileVM();

            using (var conn = GetOpenConnection())
            {
                _customerProfile = conn.Query <CustomerProfileVM>(" SELECT * FROM Customer WHERE Id =  @Id ",
                                                                  new
                {
                    Id = customerId
                }).SingleOrDefault();
            }
            return(_customerProfile);
        }
Beispiel #5
0
        public CustomerProfileVM getCustomerProfile(string id)
        {
            CustomerProfileVM vm = _db.Users
                                   .Where(c => c.Id == id)
                                   .Select(c => new CustomerProfileVM
            {
                FirstName = c.CustomerInfo.FirstName,
                LastName  = c.CustomerInfo.LastName,
                ImageUrl  = c.CustomerInfo.ImageUrl,
                Gender    = c.CustomerInfo.Gender,
                Email     = c.Email,
                Birthday  = c.CustomerInfo.Birthday
            }).FirstOrDefault();

            return(vm);
        }
Beispiel #6
0
        // GET: Customer/Details/5
        public ActionResult CustomerProfile(int id)
        {
            using (MainContext db = new MainContext())
            {
                CustomerProfileVM selectedCustomer = new CustomerProfileVM();
                //search for the customer where customerId equals id
                var customer = db.Customers.Find(id);

                //instantiate a new viewmodel for Customer profile page

                //Bind the csutomer attribute values to the ViewModel
                selectedCustomer.CustomerVM = customer;

                var recentOrders =
                    (
                        from ro in db.Orders

                        where (ro.CustomerId == id)
                        select ro
                    ).ToList();

                var orderCount = 0;

                selectedCustomer.CustomerProfileVMId = id;
                foreach (var item in recentOrders)
                {
                    selectedCustomer.CustomerVM.CustomerId = item.CustomerId;
                    var order = new ViewModels.CustomerOrder();

                    order.OrderId    = item.OrderId;
                    order.CustomerId = item.CustomerId;
                    order.OrderTotal = item.TotalAmount;

                    //add to orderCount
                    orderCount += 1;
                    //Populate recent activity model.
                    selectedCustomer.recentActivity.Add(order);
                }
                //Determine Customer Rating
                int ocSwitch = 0;
                if (orderCount == 0)
                {
                    ocSwitch = 0;
                }
                else if (orderCount > 0 && orderCount < 2)
                {
                    ocSwitch = 1;
                }
                else if (orderCount > 2 && orderCount < 3)
                {
                    ocSwitch = 2;
                }
                else if (orderCount > 3 && orderCount < 4)
                {
                    ocSwitch = 3;
                }
                else if (orderCount > 4 && orderCount < 5)
                {
                    ocSwitch = 4;
                }
                else if (orderCount > 5)
                {
                    ocSwitch = 5;
                }

                switch (ocSwitch)
                {
                case 1: selectedCustomer.rating = 1;
                    break;

                case 2:
                    selectedCustomer.rating = 2;
                    break;

                case 3:
                    selectedCustomer.rating = 3;
                    break;

                case 4:
                    selectedCustomer.rating = 4;
                    break;

                case 5:
                    selectedCustomer.rating = 5;
                    break;

                default:
                    break;
                }



                return(View(selectedCustomer));
            }
        }