public async Task <IActionResult> Create(Sliders sliders) { if (!ModelState.IsValid) { return(View(sliders)); } if (!sliders.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Selected image is not valid!"); return(View(sliders)); } if (sliders.Photo == null) { ModelState.AddModelError("Photo", "Please select any image!"); return(View(sliders)); } sliders.Image = await sliders.Photo.SaveFileAsync(_env.WebRootPath); await _context.Sliders.AddAsync(sliders); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(Workers workers) { if (!ModelState.IsValid) { return(View(workers)); } if (workers.Photo == null) { ModelState.AddModelError("Photo", "Please select any image!"); return(View(workers)); } if (!workers.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Image is not valid!"); return(View(workers)); } workers.Image = await workers.Photo.SaveFileAsync(_env.WebRootPath); await _context.Workers.AddAsync(workers); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(Gallery gallery) { if (ModelState.IsValid) { return(View(gallery)); } if (gallery.Photo == null) { ModelState.AddModelError("Photo", "Please select any image!"); return(View(gallery)); } if (!gallery.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Image is not valid!"); return(View(gallery)); } gallery.Image = await gallery.Photo.SaveFileAsync(_env.WebRootPath); await _context.Galleries.AddAsync(gallery); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(Videos videos) { if (!ModelState.IsValid) { return(View(videos)); } await _context.Videos.AddAsync(videos); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Subscribe(string email) { if (await _context.Subcribes.AnyAsync(s => s.Email == email)) { return(Ok(new { status = 400, data = "", message = "Error dublicate!" })); } else { await _context.Subcribes.AddAsync(new Subcribes { Email = email }); await _context.SaveChangesAsync(); return(Ok(new { status = 200, data = "", message = "You subscribed successfully!" })); } }
public async Task <IActionResult> Edit(int?id, EmailInfo emailInfo) { if (!ModelState.IsValid) { return(View(emailInfo)); } EmailInfo emailInfodb = await _context.EmailInfos.FindAsync(id); emailInfodb.Email = emailInfo.Email; emailInfodb.Password = emailInfo.Password; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(ColdMenu coldMenu) { if (!ModelState.IsValid) { return(View(coldMenu)); } if (coldMenu.Photo == null) { ModelState.AddModelError("Photo", "Please select any image!"); return(View(coldMenu)); } if (!coldMenu.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Image is not valid!"); return(View(coldMenu)); } coldMenu.Image = await coldMenu.Photo.SaveFileAsync(_env.WebRootPath); await _context.ColdMenus.AddAsync(coldMenu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }