public JsonResult RemoveRealtyImage(string realtyId, string image) { int id = Convert.ToInt32(realtyId); try { var realty = _realtyRepository.Read(id); if (realty == null) { throw new Exception(); } if (realty.UserId != WebSecurity.CurrentUserId && !User.IsInRole("Administrator")) { throw new Exception(); } _realtyPhotoRepository.DeleteImage(id, image); var path = AppDomain.CurrentDomain.BaseDirectory + image; System.IO.File.Delete(path); path = AppDomain.CurrentDomain.BaseDirectory + ProjectConfiguration.Get.FilePaths["realty_thumb"] + "//" + image.Split('/').Last(); System.IO.File.Delete(path); } catch { return(Json(new { status = "fail" }, "text/html")); } return(Json(new { status = "success" }, "text/html")); }
public ActionResult MyAnnouncementsMobile(PagerSortModel sortModel = null) { //var myAnnouncements = _announcementRepository.ReadByUser(_announcementRepository.Read(), WebSecurity.CurrentUserId); ViewBag.UpTimeAnnouncement = int.Parse(_configRepository.ReadByName("UpTimeAnnouncement").Value); ViewBag.SortModel = sortModel; ViewBag.Title = "Мои объявления"; ViewBag.IsAdmin = false; try { var user = _profileRepository.Read(WebSecurity.CurrentUserId); if (user != null) { ViewBag.UserName = user.Name; ViewBag.UserSurName = user.Surname; ViewBag.Site = user.Site; ViewBag.Skype = user.Skype; ViewBag.Icq = user.Icq; } } catch { } if (Roles.IsUserInRole(WebSecurity.CurrentUserName, "Administrator")) { ViewBag.IsAdmin = true; var model = _realtyRepository.Read().OrderByDescending(x => x.CreatedAt); return(View("MyAnnouncementsMobile", model.ToPagedList(sortModel.CurrentPage.Value, sortModel.PageSize))); } else { var model = _realtyRepository.Read().Where(x => x.UserId == WebSecurity.CurrentUserId).OrderByDescending(x => x.CreatedAt); return(View("MyAnnouncementsMobile", model.ToPagedList(sortModel.CurrentPage.Value, sortModel.PageSize))); } }
public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; //return View(); var model = _realtyRepository.Read().OrderByDescending(x => x.CreatedAt).Take(100).ToList(); return(IsMobileDevice() ? View("IndexMobile", model) : View("Index")); }
public bool RemoveImage(string announcementId, string imageName, ImagesType type) { var id = Convert.ToInt32(announcementId); try { switch (type) { case ImagesType.Anouncement: var announcement = _announcement.Read(id); if (announcement == null) { throw new Exception(); } _announcementImage.DeleteImage(id, imageName); break; case ImagesType.Realty: var realty = _realty.Read(id); if (realty == null) { throw new Exception(); } _realtyImage.DeleteImage(id, imageName); break; } RemoveImage(imageName, type); } catch { return(false); } return(true); }
public ActionResult List(RealtySortByParams sortModel = null) { var realty = _realtyRepository.Read(); ViewBag.Categories = _categoryRepository.Read(); ViewBag.Cities = _cityRepository.Read(); ViewBag.Sections = _sectionRepository.Read(); ViewBag.SortModel = sortModel ?? new RealtySortByParams(); if (sortModel != null && sortModel.IsEnableSort) { realty = _realtyRepository.SortByParams(realty, sortModel.CategoryId, sortModel.CityId, sortModel.FromPrice, sortModel.ToPrice, sortModel.CountsRoom, sortModel.FromSquare, sortModel.ToSquare, sortModel.FromFloorCount, sortModel.ToFloorCount, sortModel.FromFloor, sortModel.ToFloor, sortModel.FromCeillingHeight, sortModel.ToCeillingHeight, sortModel.WithPhoto, sortModel.IsAuction, sortModel.IsPerson, sortModel.WithGarage, sortModel.WithGarden, sortModel.WithExtension, sortModel.WithBasement, sortModel.Street); } realty = _realtyRepository.Sort(realty, sortModel.SortOrder, sortModel.SortOptions, sortModel.SectionId, sortModel.CategoryId); return(View("List", realty.ToPagedList(sortModel.CurrentPage.HasValue ? sortModel.CurrentPage.Value : 1, sortModel.PageSize))); }