public async Task <IActionResult> Edit(int?id, OurPartner ourPartner) { if (!ModelState.IsValid) { return(View(ourPartner)); } OurPartner ourPartnerFromDb = await _db.OurPartners.FindAsync(ourPartner.Id); if (ourPartner.Photo != null) { if (!ourPartner.Photo.IsImage()) { ModelState.AddModelError("Photo", "File type is not valid"); return(View(ourPartner)); } if (!ourPartner.Photo.IsLessThan(2)) { ModelState.AddModelError("Photo", "File size can not be more than 2 mb"); return(View(ourPartner)); } //remove old image RemoveImage(_env.WebRootPath, ourPartnerFromDb.Image); //save new image ourPartnerFromDb.Image = await ourPartner.Photo.SaveAsync(_env.WebRootPath, "ourPartners"); } await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Partner))); }
public async Task <IActionResult> Create(OurPartner ourPartner) { if (!ModelState.IsValid) { return(View()); } if (ourPartner.Photo == null) { ModelState.AddModelError("Photo", "Photo should be selected"); return(View(ourPartner)); } if (!ourPartner.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "File type is not valid"); return(View(ourPartner)); } if (ourPartner.Photo.Length / 1024 / 1024 > 2) { ModelState.AddModelError("Photo", "File size can not be more than 2 mb"); return(View(ourPartner)); } ourPartner.Image = await ourPartner.Photo.SaveAsync(_env.WebRootPath, "partners"); await _db.OurPartners.AddAsync(ourPartner); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Partner))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } OurPartner ourPartner = await _db.OurPartners.FindAsync(id); if (ourPartner == null) { return(NotFound()); } return(View(ourPartner)); }
public async Task <IActionResult> DeletePost(int?id) { if (id == null) { return(NotFound()); } OurPartner ourPartner = await _db.OurPartners.FindAsync(id); if (ourPartner == null) { return(NotFound()); } RemoveImage(_env.WebRootPath, ourPartner.Image); _db.OurPartners.Remove(ourPartner); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Partner))); }
protected void Page_Load(object sender, EventArgs e) { ourPartner = ourPartnersRepository.GetOurPartners(GeneralExtensions.GetQueryStringId()); if (userExtensions.IsUserLoggedIn()) { repMemOurPartnerTitles.DataSource = ourPartner.OurPartnerItems.ConvertToLong().GetTaxonomyList(); repMemOurPartnerTitles.DataBind(); repMemOurPartnerItems.DataSource = ourPartner.OurPartnerItems.ConvertToLong().GetContentList(true); repMemOurPartnerItems.DataBind(); pnlMemberOurPartner.Visible = true; pnlOurPartner.Visible = false; } else { repOurPartners.DataSource = ourPartner.OurPartnerItems.ConvertToLong().GetContentList(); repOurPartners.DataBind(); pnlMemberOurPartner.Visible = false; pnlOurPartner.Visible = true; } }