Пример #1
0
        // GET: ClientSite/Home
        public ActionResult Index()
        {
            try
            {
                ProductViewModels model = new ProductViewModels();
                var data = _factoryPro.GetListProduct();

                var temp = data.OrderByDescending(x => x.CreatedDate)
                           .Skip(0).Take(6).ToList();
                model.TotalProduct = data.Count;
                temp.ForEach(x =>
                {
                    if (!string.IsNullOrEmpty(x.ImageURL))
                    {
                        x.ImageURL = Commons.HostImage + x.ImageURL;
                    }
                });
                model.ListProduct = temp;

                model.ListCate = new List <SelectListItem>()
                {
                    new SelectListItem()
                    {
                        Text = "Đất", Value = Commons.EProductType.Land.ToString("d")
                    },
                    new SelectListItem()
                    {
                        Text = "Nhà", Value = Commons.EProductType.House.ToString("d")
                    }
                };
                var lstLoc = _factoryLoc.GetListLocation();
                model.ListArea = lstLoc.Where(w => w.IsActive).Select(o => new SelectListItem()
                {
                    Value = o.ID,
                    Text  = o.Name,
                }).OrderBy(o => o.Text).ToList();
                return(View(model));
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Index : ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Пример #2
0
 public ActionResult Edit(LocationModels model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Edit", model));
         }
         string msg = "";
         model.CreatedUser = CurrentUser.UserId;
         var result = _factory.UpdateLocation(model, ref msg);
         if (result)
         {
             HttpCookie _LocationCookie = Request.Cookies["LocCookie"];
             //if (_LocationCookie == null)
             //{
             //    HttpCookie cookie = new HttpCookie("LocCookie");
             //    cookie.Expires = DateTime.Now.AddYears(10);
             //}
             LocationFactory _facLoc = new LocationFactory();
             var             _loc    = _facLoc.GetListLocation().Select(x => new LocationSession
             {
                 Id   = x.ID,
                 Name = x.Name
             }).ToList();
             if (_loc != null && _loc.Any())
             {
                 string     myObjectJson = JsonConvert.SerializeObject(_loc); //new JavaScriptSerializer().Serialize(userSession);
                 HttpCookie cookie       = new HttpCookie("LocCookie");
                 cookie.Expires = DateTime.Now.AddYears(10);
                 cookie.Value   = Server.UrlEncode(myObjectJson);
                 Response.Cookies.Add(cookie);
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             model = GetDetail(model.ID);
             if (!string.IsNullOrEmpty(msg))
             {
                 ModelState.AddModelError("Name", msg);
             }
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Edit", model));
         }
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Location_Edit: ", ex);
         ModelState.AddModelError("Name", ex.Message);
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Edit", model));
     }
 }
Пример #3
0
 public ActionResult Search(LocationViewModels model)
 {
     try
     {
         var data = _factory.GetListLocation();
         model.ListLocation = data;
     }
     catch (Exception e)
     {
         NSLog.Logger.Error("GetListLocation: ", e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
     return(PartialView("_ListData", model));
 }
Пример #4
0
 public ActionResult Delete(LocationModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteLocation(model.ID, ref msg);
         if (!result)
         {
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         HttpCookie _LocationCookie = Request.Cookies["LocCookie"];
         //if (_LocationCookie == null)
         //{
         //    HttpCookie cookie = new HttpCookie("LocCookie");
         //    cookie.Expires = DateTime.Now.AddYears(10);
         //}
         LocationFactory _facLoc = new LocationFactory();
         var             _loc    = _facLoc.GetListLocation().Select(x => new LocationSession
         {
             Id   = x.ID,
             Name = x.Name
         }).ToList();
         if (_loc != null && _loc.Any())
         {
             string     myObjectJson = JsonConvert.SerializeObject(_loc); //new JavaScriptSerializer().Serialize(userSession);
             HttpCookie cookie       = new HttpCookie("LocCookie");
             cookie.Expires = DateTime.Now.AddYears(10);
             cookie.Value   = Server.UrlEncode(myObjectJson);
             Response.Cookies.Add(cookie);
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Xóa khu vực: ", ex);
         ModelState.AddModelError("Name", ("Lỗi khi xóa thông tin khu vực!"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Пример #5
0
        //public List<SelectListItem> getListCategory()
        //{
        //    var _lstCate = new List<SelectListItem>();
        //    try
        //    {
        //        CategoryFactory _factory = new CategoryFactory();
        //        var data = _factory.GetListCate();
        //        foreach(var item in data)
        //        {
        //            _lstCate.Add(new SelectListItem
        //            {
        //                Value = item.ID,
        //                Text = item.Name
        //            });
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        NSLog.Logger.Error("getListCategory", ex);
        //    }
        //    return _lstCate;
        //}

        public List <SelectListItem> getListLocation()
        {
            var _lstLocation = new List <SelectListItem>();

            try
            {
                LocationFactory _factory = new LocationFactory();
                var             data     = _factory.GetListLocation();
                foreach (var item in data)
                {
                    _lstLocation.Add(new SelectListItem
                    {
                        Value = item.ID,
                        Text  = item.Name
                    });
                }
            }catch (Exception ex)
            {
                NSLog.Logger.Error("getListLocation", ex);
            }
            return(_lstLocation);
        }
Пример #6
0
        void Application_AcquireRequestState(object sender, EventArgs e)
        {
            HttpCookie _LocationCookie = Request.Cookies["LocCookie"];

            if (_LocationCookie != null)
            {
                var input = Server.UrlDecode(_LocationCookie.Value);
                if (input != null && input.Length > 0)
                {
                    List <LocationSession> locSession = JsonConvert.DeserializeObject <List <LocationSession> >(input); //new JavaScriptSerializer().Deserialize<UserSession>(input);
                    if (locSession != null && HttpContext.Current.Session != null)
                    {
                        Session.Add("Location", locSession);
                    }
                }
            }
            else
            {
                LocationFactory _facLoc = new LocationFactory();
                var             _loc    = _facLoc.GetListLocation().Select(x => new LocationSession
                {
                    Id   = x.ID,
                    Name = x.Name
                }).ToList();
                if (_loc != null && _loc.Any())
                {
                    string     myObjectJson = JsonConvert.SerializeObject(_loc); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("LocCookie");
                    cookie.Expires = DateTime.Now.AddYears(10);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    Response.Cookies.Add(cookie);
                    Session.Add("Location", _loc);
                }
            }


            HttpCookie _CateCookie = Request.Cookies["CateCookie"];

            if (_CateCookie != null)
            {
                var input = Server.UrlDecode(_CateCookie.Value);
                if (input != null && input.Length > 0)
                {
                    List <CateSession> cateSession = JsonConvert.DeserializeObject <List <CateSession> >(input); //new JavaScriptSerializer().Deserialize<UserSession>(input);
                    var ObjSession = new CateSession();
                    if (cateSession != null && HttpContext.Current.Session != null)
                    {
                        ObjSession.MainCate   = cateSession.OrderBy(x => x.Name).Skip(0).Take(7).ToList();
                        ObjSession.OrtherCate = cateSession.OrderBy(x => x.Name).Skip(7).Take(cateSession.Count).ToList();
                        // Session.Add("Catelogies", cateSession);
                        Session.Add("Catelogies", ObjSession);
                    }
                }
            }
            else
            {
                CategoryFactory _facLoc = new CategoryFactory();
                var             _cate   = _facLoc.GetListCategory().Select(x => new CateSession
                {
                    Id   = x.ID,
                    Name = x.Name
                }).ToList();//.OrderBy(x => x.Name).Skip(0).Take(7).ToList();
                if (_cate != null && _cate.Any())
                {
                    var ObjSession = new CateSession();
                    ObjSession.MainCate   = _cate.OrderBy(x => x.Name).Skip(0).Take(7).ToList();
                    ObjSession.OrtherCate = _cate.OrderBy(x => x.Name).Skip(7).Take(_cate.Count).ToList();

                    string     myObjectJson = JsonConvert.SerializeObject(_cate); //new JavaScriptSerializer().Serialize(userSession);
                    HttpCookie cookie       = new HttpCookie("CateCookie");
                    cookie.Expires = DateTime.Now.AddYears(10);
                    cookie.Value   = Server.UrlEncode(myObjectJson);
                    Response.Cookies.Add(cookie);
                    //  Session.Add("Catelogies", _cate);
                    Session.Add("Catelogies", ObjSession);
                }
            }


            HttpCookie _UserClientCookie = Request.Cookies["UserClientCookie"];

            if (_UserClientCookie != null)
            {
                var         input       = Server.UrlDecode(_UserClientCookie.Value);
                UserSession userSession = JsonConvert.DeserializeObject <UserSession>(input); //new JavaScriptSerializer().Deserialize<UserSession>(input);
                if (userSession != null && HttpContext.Current.Session != null)
                {
                    Session.Add("UserClient", userSession);
                }
            }
        }