Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        public ViewResult AdTest()
        {
            AdvertRepository          advert = new AdvertRepository();
            List <AdvertisementModel> model  = advert.GetAllAdvertisements();

            ViewData["Adverts"] = model;
            return(View());
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 5
0
 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();
     }
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 9
0
        // 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"));
        }
Ejemplo n.º 10
0
 public CategoryController()
 {
     _advertRepository   = new AdvertRepository();
     _categoryRepository = new CategoryRepository();
 }
Ejemplo n.º 11
0
 public UserController()
 {
     _userRepository   = new UserRepository();
     _advertRepository = new AdvertRepository();
 }
Ejemplo n.º 12
0
 public AdvertController()
 {
     _advertRepository = new AdvertRepository();
 }