public ViewResult AdsPage(string searchCondition = "&none&", string sortCondition = "created", string sortDirection = "desc", string location = "none") { AdvertRepository advert = new AdvertRepository(); if (searchCondition == null) { searchCondition = "&none&"; } if (sortCondition == null) { sortCondition = "created"; } if (sortDirection == null) { sortDirection = "desc"; } if (location == null) { location = "none"; } if (location.Equals("Anywhere")) { location = "none"; } List <AdvertisementModel> model = advert.GetAllAdvertisements(searchCondition, sortCondition, sortDirection, location); ViewData["Adverts"] = model; ViewBag.Name = HttpContext.Session.GetString(SessionName); // ViewBag.Age = HttpContext.Session.GetInt32(SessionAge); return(View()); }
public ViewResult AdTest() { AdvertRepository advert = new AdvertRepository(); List <AdvertisementModel> model = advert.GetAllAdvertisements(); ViewData["Adverts"] = model; return(View()); }
public ViewResult AdView(int id) { AdvertRepository advert = new AdvertRepository(); AdvertisementModel model = advert.GetAdvertisement(id); ViewData["Adverts"] = model; ViewBag.Name = HttpContext.Session.GetString(SessionName); return(View()); }
public async Task <ActionResult> postAd(string iName, string iCategory, string iAvailable, string iLoc, IFormFile img, string iDescription, string iContact, string iPrice, string iCondition, string iNegotiable) { AdvertRepository ad = new AdvertRepository(); AuthResponseModel response = new AuthResponseModel(); int negotiable = 0; var filePath = Path.GetTempFileName(); string iimg = null; try { if (img.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await img.CopyToAsync(stream); } var bytes = System.IO.File.ReadAllBytes(filePath); iimg = Convert.ToBase64String(bytes); } } catch (Exception) { Stream imgStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream( "DSProject.Resources.notfound.png"); var path1 = @"D:\MS_VS_Projects\DSProject\DSProject\WebSite\Resources\notfound.png"; var path2 = @"..\WebSite\Resources\notfound.png"; var bytes = System.IO.File.ReadAllBytes(path2); iimg = Convert.ToBase64String(bytes); } if (iNegotiable.Equals("Negotiable")) { negotiable = 1; } else { negotiable = 0; } response = await ad.AddAdvert(iName, iCategory, iAvailable, iLoc, iimg, iDescription, iContact, iPrice, iCondition, negotiable); if (response.Response.Equals(200)) { return(RedirectToAction("AdsPage")); } else { var rsp = new AuthResponseModel { Response = response.Response, Status = response.Status, Info = response.Info }; return(RedirectToAction("Home", "Home")); } }
public static void Refresh() { try { db = new DataContext(options); advertRepository = new AdvertRepository(db); userRepository = new UserRepository(db); favoriteRepository = new FavoriteRepository(db); } catch { MessageBox.Show("Во время работы с базой данных произошла ошибка. Проверьте работу сервера, или попробуйте вернуться позже!"); Application.Current.Shutdown(); } }
public AdvertRepositoryTests() { var dbObtions = new DbContextOptionsBuilder <AdvertContext>() .UseInMemoryDatabase(databaseName: "AdvertTest") .Options; _context = new AdvertContext(dbObtions); _context.Database.EnsureDeleted(); _context.Database.EnsureCreated(); #region SeedData //Some mock adverts; var adverts = new[] { new Advert { Id = 1, Title = "Audi A4 Avant", Fuel = FuelType.Diesel, Price = 15000, IsNew = false, Mileage = 35000, FirstRegistration = new DateTime(2015, 10, 1) }, new Advert { Id = 2, Title = "Audi A3", Fuel = FuelType.Diesel, Price = 5000, IsNew = false, Mileage = 135000, FirstRegistration = new DateTime(2015, 10, 1) }, new Advert { Id = 3, Title = "Audi A2", Fuel = FuelType.Gasoline, Price = 3000, IsNew = false, Mileage = 235000, FirstRegistration = new DateTime(2013, 10, 1) }, new Advert { Id = 4, Title = "Audi A5", Fuel = FuelType.Diesel, Price = 25000, IsNew = false, Mileage = 5000, FirstRegistration = new DateTime(2012, 10, 1) }, new Advert { Id = 5, Title = "Volkswagen Golf", Fuel = FuelType.Diesel, Price = 15000, IsNew = false, Mileage = 1000, FirstRegistration = new DateTime(2011, 10, 1) } }.ToList(); _context.Adverts.AddRange(adverts); _context.SaveChanges(); #endregion _advertRepository = new AdvertRepository(_context); }
public ActionResult EditAdvertisement(EditAdModel obj) { if (Session["ID"] != null) { var AdID = obj.ID; AddingAdsRepository model = new AddingAdsRepository(); model.CategoryID = -1; model.Categories = addingAdsRepository.GetList(); ADVERTS AdData = new AdvertRepository().GetAdData(AdID); return(View(AdData)); } else { return(RedirectToAction("Logowanie", "Home")); } }
// GET: Cars public ActionResult Cars() { AdvertRepository advertRepository = new AdvertRepository(); CarsRepository carsRepository = new CarsRepository(); CarPhotoRepository carPhotoRepository = new CarPhotoRepository(); List <AdvertViewModel> advertViews = new List <AdvertViewModel>(); var result = carsRepository.GetAll(); var resultadvert = advertRepository.GetAll(); foreach (var item in result) { advertViews.Add(new AdvertViewModel { Carss = item, Photo = carPhotoRepository.GetByFilterx(x => x.CarId == item.Id).Photo }); } foreach (var item in resultadvert) { advertViews.ForEach(x => x.Adverts = item); } return(View(advertViews)); }
// POST AdvertAdd public ActionResult AdvertAdd(AdvertViewModel model) { AdvertRepository advertRepository = new AdvertRepository(); CarsRepository carsRepository = new CarsRepository(); Random rnd = new Random(); string deger = null; for (int i = 0; i < 4; i++) { var sayi = rnd.Next(0, 9); deger += sayi.ToString(); } var advertn = Convert.ToInt16(deger); var result = advertRepository.GetByFilter(x => x.AdvertNo != advertn); var saveresult = advertRepository.Add(model.Adverts); TempData["Mesaj"] = saveresult ? new TempDataDictionary { { "class", "alert-success" }, { "Msg", "Kayıt başarıyla eklendi." } } : new TempDataDictionary { { "class", "alert-danger" }, { "Msg", "Kayıt eklenemedi bilgilerini kontrol et." } }; return(Redirect("ilanlar")); }
public CategoryController() { _advertRepository = new AdvertRepository(); _categoryRepository = new CategoryRepository(); }
public UserController() { _userRepository = new UserRepository(); _advertRepository = new AdvertRepository(); }
public AdvertController() { _advertRepository = new AdvertRepository(); }