Exemplo n.º 1
0
        public static double getCartTotal(out int CartItemsCount)
        {
            double total = 0;

            CartItemsCount = 0;
            PrimeMarketEntities context = new PrimeMarketEntities();
            var CustomerId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (string.IsNullOrEmpty(CustomerId))
            {
                //return RedirectToAction("Login", "Account",new { ReturnUrl ="/shop/index"});
                var tempCustomerId = Helper.GetCookie("tempCustomerId");
                if (tempCustomerId == null)
                {
                    tempCustomerId = Guid.NewGuid().ToString();
                    Helper.SetCookie("tempCustomerId", tempCustomerId, DateTime.Now.AddDays(20));
                }
                CustomerId = tempCustomerId;
            }
            try
            {
                var cart = context.Carts.Where(c => c.CustomerId == CustomerId).ToList();
                CartItemsCount = cart.Count;
                foreach (var item in cart)
                {
                    total += (double)item.Commodity.Price * (double)item.Quantity;
                }
            }
            catch
            { }
            return(total);
        }
Exemplo n.º 2
0
        public static string getUserFullName(string UserName)
        {
            PrimeMarketEntities db   = new PrimeMarketEntities();
            AspNetUser          user = db.AspNetUsers.Where(x => x.UserName == UserName).FirstOrDefault();

            if (user != null)
            {
                return(user.FullName);
            }
            return(string.Empty);
        }
Exemplo n.º 3
0
        public static bool isInRole(string UserName, string rolename)
        {
            PrimeMarketEntities db = new PrimeMarketEntities();
            AspNetRole          R  = db.AspNetRoles.Where(x => x.Name == rolename).FirstOrDefault();

            if (R != null)
            {
                var RoleId = R.Id;
                //var userRole = db.AspNetUser
            }
            return(false);
        }
Exemplo n.º 4
0
        public static void MigrateCart(string LoggedInUserId)
        {
            PrimeMarketEntities db = new PrimeMarketEntities();

            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return;
            }
            var CustomerId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (string.IsNullOrEmpty(CustomerId))
            {
                CustomerId = LoggedInUserId;
            }
            var tempCustomerId = GetCookie("tempCustomerId");

            if (tempCustomerId != null)
            {
                var CustomerCartItems     = db.Carts.Where(c => c.CustomerId == CustomerId).ToList();
                var tempCustomerCartItems = db.Carts.Where(c => c.CustomerId == tempCustomerId).ToList();
                foreach (var tempItem in tempCustomerCartItems)
                {
                    // check if temp item in the temp cart already exist in user cart, then update the old quantity else add the temp item
                    var item = CustomerCartItems.Where(c => c.CommodityId == tempItem.CommodityId).FirstOrDefault();
                    if (item != null)
                    {
                        item.Quantity += tempItem.Quantity;
                        db.Carts.Remove(tempItem);
                    }
                    else
                    {
                        tempItem.CustomerId = CustomerId;
                    }
                }
                db.SaveChanges();
                // delete cookies
                SetCookie("tempCustomerId", tempCustomerId, DateTime.Now.AddDays(-1));
            }
        }