public void ShouldAddNewAdvert() { Advert a = new Advert() { Id = 20, FuelType = "Gasoline", FirstRegistration = new DateTime(2012, 10, 02), Title = "Golf Avant", IsNew = false, Mileage = 25000, Price = 12000 }; var adv = _advertRepository.Add(a); Assert.True(adv.Title == a.Title); }
public JsonResult Add(AddForm form) { AdvertEntity advert = new AdvertEntity() { Title = form.Title, Desсription = form.Desсription, UserId = (int)Session["UserId"], CategoryList = _categoryRepository.GetList() }; _advertRepository.Add(advert); int advertId = advert.Id; return(Json(new { IsSuccess = true, AdvertId = advertId })); }
// 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")); }