public ActionResult Create(AdvertismentViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { using (var db = DbFactory.Create()) { db.Advertisment.Add(new Advertisment() { Since = model.Since, Details = model.Details, Location = model.Location, Until = model.Until }); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View(model)); } }
public ActionResult Create() { var model = new AdvertismentViewModel() { Advertisment = new Advertisment(), File = null }; return(View("AdvertismentForm", model)); }
protected async override void OnAppearing() { UserDataStore = new UserDataStore(); var seller = await UserDataStore.GetItemAsync(Advertisement.UserId); BindingContext = AdViewModel = new AdvertismentViewModel { Advertisment = this.Advertisement, CurrentImageIndex = 0, FirebaseUser = seller }; foreach (var imageUrl in AdViewModel.Advertisment.PicturesURL) { AdViewModel.ImageSources.Add(ImageSource.FromUri(new Uri(imageUrl))); } }
public async Task <ActionResult> Update(int id) { var Advertisment = await _Advertismentrepo.GetAdvertismentById(id); var model = new AdvertismentViewModel { Advertisment = Advertisment, File = null }; return(View("AdvertismentForm", model)); }
// GET: Advertisement public ActionResult Index() { List <AdvertismentViewModel> model = new List <AdvertismentViewModel>(); var advList = _advService.GetAllAdvertisment(); foreach (var item in advList) { AdvertismentViewModel adv = new AdvertismentViewModel(); adv.Id = item.Id; adv.Information = item.Information; adv.Date = Convert.ToDateTime(item.Date); model.Add(adv); } return(View(model)); }
public ActionResult Edit(AdvertismentViewModel model) { try { using (var db = DbFactory.Create()) { var entity = db.Advertisment.First(a => a.Id == model.Id); entity.Location = model.Location; entity.Since = model.Since; entity.Until = model.Until; entity.Details = model.Details; db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public AddPromotionCommand(AdvertismentViewModel advertismentViewModel) { AdvertismentViewModel = advertismentViewModel; }
public Advertisement() { this.InitializeComponent(); Vm = new AdvertismentViewModel(); this.DataContext = Vm; }
public async Task <ActionResult> Save(AdvertismentViewModel collection) { if (!ModelState.IsValid) { return(View("AdvertismentForm", collection)); } var root = Path.Combine(_webHostEnvironment.WebRootPath, "uploads"); if (collection.Advertisment.Id == 0) { if (collection.File == null) { collection.Error = "Please Add Image !"; return(View("CategoryForm", collection)); } string fileName; var isImageSaved = _coreRepo.SaveSingleImageFormFile(root, collection.File, out fileName); if (!isImageSaved) { collection.Error = "There was an error in raising the pictures !"; } collection.Advertisment.File = fileName; collection.Advertisment.IsActive = true; _coreRepo.Add(collection.Advertisment); await _coreRepo.SaveAll(); } else { var Advertisment = await _Advertismentrepo.GetAdvertismentById(collection.Advertisment.Id); Advertisment.CountDays = collection.Advertisment.CountDays; Advertisment.Description = collection.Advertisment.Description; Advertisment.File = collection.Advertisment.File; Advertisment.StartDate = collection.Advertisment.StartDate; Advertisment.Subject = collection.Advertisment.Subject; Advertisment.Title = collection.Advertisment.Title; Advertisment.UriLink = collection.Advertisment.UriLink; if (collection.File != null) { string fullPath = root + "/" + Advertisment.File; if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } string fileName; var isImageSaved = _coreRepo.SaveSingleImageFormFile(root, collection.File, out fileName); if (!isImageSaved) { collection.Error = "There was an error in raising the pictures !"; } Advertisment.File = fileName; } } await _coreRepo.SaveAll(); return(RedirectToAction("Index")); }