public ActionResult _RemoveProductFromFavorite(int productShopID)
 {
     if (LS.isLogined())
     {
         ShoppingService.RemoveProductFromFavorite(productShopID, LS.CurrentUser.ID);
     }
     return(Content(string.Empty));
 }
Exemplo n.º 2
0
        public ActionResult Settings(UserModel model)
        {
            if (!LS.isLogined())
            {
                return(Redirect("~/"));
            }
            if (ModelState.IsValid)
            {
                var user = _db.Users.FirstOrDefault(x => x.ID == LS.CurrentUser.ID);
                if (user != null)
                {
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.CompanyName = model.CompanyName;
                    user.Phone       = model.Phone;
                    user.Email       = model.Email;
                    if (model.NewsLetter)
                    {
                        var nl = _db.Newsletters.FirstOrDefault(x => x.NewsletterEmail == model.Email);
                        if (nl == null)
                        {
                            Newsletter n = new Newsletter()
                            {
                                NewsletterAccept = true,
                                NewsletterDate   = DateTime.UtcNow,
                                NewsletterEmail  = user.Email,
                                NewsletterName   = user.FirstName + " " + user.LastName,
                                RoleDefault      = "Register"
                            };
                            _db.Newsletters.Add(n);
                            _db.SaveChanges();
                            SF.AddToNewsletter(n);
                        }
                    }
                    else
                    {
                        var nl = _db.Newsletters.FirstOrDefault(x => x.NewsletterEmail == model.Email);
                        if (nl != null)
                        {
                            _db.Newsletters.Remove(nl);
                            _db.SaveChanges();
                        }
                    }
                    _db.SaveChanges();
                    TempData["SuccessMessage"] = "Save Successful";
                    return(RedirectToAction("Settings"));
                }
            }

            TempData["ViewData"] = ViewData;
            return(RedirectToAction("Settings"));
        }
Exemplo n.º 3
0
        public ActionResult Index(PollPageModel model)
        {
            if ((!model.token.HasValue || model.token == Guid.Empty) && LS.isLogined())
            {
                model.token = LS.CurrentUser.ID;
            }
            if (!model.token.HasValue || model.token == Guid.Empty)
            {
                return(RedirectToAction("LogOn", "Account", new { returnUrl = Url.Action("Index", "Poll") }));
            }

            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult Settings()
        {
            UserActivityService.InsertUserClick(LS.CurrentUser.ID,
                                                Request.RawUrl,
                                                Request.UrlReferrer != null ? Request.UrlReferrer.OriginalString : null
                                                , LS.GetUser_IP(Request));
            if (!LS.isLogined())
            {
                return(Redirect("~/"));
            }
            if (TempData["ViewData"] != null)
            {
                ViewData = (ViewDataDictionary)TempData["ViewData"];
            }
            var model = new UserModel();

            model.CompanyName = LS.CurrentUser.CompanyName;
            model.Email       = LS.CurrentUser.Email;
            model.FirstName   = LS.CurrentUser.FirstName;
            model.LastName    = LS.CurrentUser.LastName;
            model.Phone       = LS.CurrentUser.Phone;
            model.NewsLetter  = _db.Newsletters.Any(x => x.NewsletterEmail == model.Email);
            return(View(model));
        }
 public ActionResult IsLogined()
 {
     return(Json(LS.isLogined(), JsonRequestBehavior.AllowGet));
 }
        public ActionResult _ChangeShopPopup(int shopID)
        {
            var data     = new List <ShoppingCartOverviewModel>();
            var curdate  = DateTime.Now.Date;
            var lastdate = curdate.AddDays(7);
            var culture  = new System.Globalization.CultureInfo("he-IL");

            ViewBag.CurrentShopID = shopID;
            var curShop      = ShoppingService.GetShopByID(shopID);
            var curShopModel = new ShoppingCartOverviewModel();

            curShopModel.Items    = _shoppingCartService.GetShoppingCartItems(shopID, true);
            curShopModel.ShopID   = shopID;
            curShopModel.Shop     = curShop;
            curShopModel.Total    = curShopModel.Items.Count > 0 ? curShopModel.Items.Sum(x => x.UnitPrice) : 0;
            curShopModel.TotalStr = ShoppingService.FormatPrice(curShopModel.Total);
            curShopModel.Count    = curShopModel.Items.Count;
            //work times
            curShopModel.WorkTimes = _db.ShopWorkTimes.Where(x => x.ShopID == shopID && x.Active &&
                                                             (!x.IsSpecial || (x.Date >= curdate && x.Date <= lastdate))
                                                             ).OrderBy(x => x.IsSpecial).ThenBy(x => x.Day).ThenBy(x => x.Date)
                                     .Select(x => new ShipTimeModel()
            {
                Date        = x.Date,
                Day         = x.Day,
                TimeFromInt = x.TimeFrom,
                TimeToInt   = x.TimeTo,
                IsSpecial   = x.IsSpecial,
            })
                                     .ToList();
            foreach (var t in curShopModel.WorkTimes)
            {
                t.DayStr       = culture.DateTimeFormat.GetDayName(t.Day);
                t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm");
                t.TimeToStr    = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm");
                t.DateStr      = t.Date.ToString("dd/MM");
            }
            data.Add(curShopModel);
            //missing products


            // find by address
            decimal longitude = 0;
            decimal latitude  = 0;

            if (LS.isLogined())
            {
                if (LS.CurrentUser.Latitude != 0)
                {
                    latitude = LS.CurrentUser.Latitude;
                }
                if (LS.CurrentUser.Longitude != 0)
                {
                    longitude = LS.CurrentUser.Longitude;
                }
            }


            //if not regognized
            if (longitude == 0)
            {
                if (Session["longitude"] != null)
                {
                    longitude = (decimal)Session["longitude"];
                }
            }
            if (latitude == 0)
            {
                if (Session["latitude"] != null)
                {
                    latitude = (decimal)Session["latitude"];
                }
            }
            string address = "";

            if (Session["address"] != null)
            {
                address = (string)Session["address"];
            }
            var shops = new List <Shop>();

            if (latitude == 0 || longitude == 0)
            {
                shops = ShoppingService.GetNearestShop(0, latitude, longitude, address, true).ToList();
            }
            else
            {
                shops = ShoppingService.GetNearestShop(0, latitude, longitude, address).ToList();
            }
            string[] ids = new string[] { };
            if (!string.IsNullOrEmpty(curShop.ShopTypeIDs))
            {
                ids = curShop.ShopTypeIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }
            Expression <Func <Shop, bool> > predicate = null;

            foreach (var s in ids)
            {
                if (predicate != null)
                {
                    predicate = predicate.MultiSearchOr(x => x.ShopTypeIDs != null &&
                                                        (x.ShopTypeIDs.Contains("," + s + ",") ||
                                                         x.ShopTypeIDs == s ||
                                                         x.ShopTypeIDs.StartsWith(s + ",") ||
                                                         x.ShopTypeIDs.EndsWith("," + s)
                                                        )
                                                        );
                }
                else
                {
                    predicate = x => x.ShopTypeIDs != null && (x.ShopTypeIDs.Contains("," + s + ",") ||
                                                               x.ShopTypeIDs == s ||
                                                               x.ShopTypeIDs.StartsWith(s + ",") ||
                                                               x.ShopTypeIDs.EndsWith("," + s)
                                                               );
                }
            }
            if (predicate != null)
            {
                shops = shops.Where(predicate.Compile()).ToList();
            }

            foreach (var shop in shops)
            {
                if (shop.ID != curShopModel.ShopID)
                {
                    var model = new ShoppingCartOverviewModel();
                    // model.Items = ShoppingCartService.GetShoppingCartItems(shop.ID, true);
                    model.Items  = ShoppingCartService.GetShoppingCartItemsByList(shop.ID, curShopModel.Items);
                    model.ShopID = shop.ID;
                    model.Shop   = shop;
                    var items = model.Items.Where(x => !x.IsNotAvaliable &&
                                                  !x.SelectedAttributeNotAvaliable &&
                                                  !x.IsHaveNotQuantity).ToList();
                    model.NotAvaliableItems = model.Items.Where(x => x.IsNotAvaliable ||
                                                                x.SelectedAttributeNotAvaliable ||
                                                                x.IsHaveNotQuantity).ToList();
                    model.Total    = items.Count > 0 ? items.Sum(x => x.UnitPrice) : 0;
                    model.TotalStr = ShoppingService.FormatPrice(model.Total);
                    model.Count    = model.Items.Count;
                    //work times

                    model.WorkTimes = _db.ShopWorkTimes.Where(x => x.ShopID == shopID && x.Active &&
                                                              (!x.IsSpecial || (x.Date >= curdate && x.Date <= lastdate))
                                                              ).OrderBy(x => x.IsSpecial).ThenBy(x => x.Day).ThenBy(x => x.Date)
                                      .Select(x => new ShipTimeModel()
                    {
                        Date        = x.Date,
                        Day         = x.Day,
                        TimeFromInt = x.TimeFrom,
                        TimeToInt   = x.TimeTo,
                        IsSpecial   = x.IsSpecial,
                    })
                                      .ToList();
                    foreach (var t in model.WorkTimes)
                    {
                        t.DayStr       = culture.DateTimeFormat.GetDayName(t.Day);
                        t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm");
                        t.TimeToStr    = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm");
                        t.DateStr      = t.Date.ToString("dd/MM");
                    }

                    data.Add(model);
                }
            }

            if (!string.IsNullOrEmpty(curShop.Theme))
            {
                this.HttpContext.Items["ShopTheme"] = curShop.Theme;
            }

            return(PartialView(data));
        }
Exemplo n.º 7
0
 public CheckoutData()
 {
     IsRegistered = LS.isLogined();
     LastAction   = DateTime.UtcNow;
 }