public Banner GetBanner(int cityId, string zone) { var banner = context.Banners.FirstOrDefault(b => b.CityId == cityId && b.Type.Equals(zone) && b.StartDate >= DateTime.Today); if (banner == null) { banner = new Banner { CityId = cityId, Text = "Meniu", Title = "Meniu", Type = zone, ImgUrl = "/Content/ads/Default/meniuAd.jpg" }; } return banner; }
public void SaveAds(AdsViewModel model) { int cityId = int.Parse(model.CityId); if (locationRepository.CityExists(cityId)) { string cityName = locationRepository.GetCityNameById(cityId); string imgUrl= String.Empty; if (model.Image != null) { ImageService.Image = model.Image; imgUrl = ImageService.SaveAdImage(model.Zone.ToString(), cityName); } var banner = new Banner { CityId = cityId, EndDate = model.ToBeConcluded, StartDate = model.StartsOn, ImgUrl = imgUrl, Type = model.Zone.ToString() }; adsRepository.SaveAd(banner); } }
public void SaveAd(Banner banner) { context.Banners.Add(banner); context.SaveChanges(); }