public ActionResult Index(IEnumerable<HttpPostedFileBase> PDF) { ViewBag.MainNav = Navigator.Main.DONATE; if (ModelState.IsValid) { SectionVariable donate_pdf = variabeService.GetVariableByKey("DonatePDF"); if (PDF != null && PDF.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (donate_pdf != null) fs.DeleteFile(donate_pdf.Value); string file_url = fs.SaveFiles(PDF); if(variabeService.AddUpdateVariable("DonatePDF", file_url) > 0) { TempData["SuccessMessage"] = "File Updated Successfully"; return RedirectToAction("Index"); } else TempData["ErrorMessage"] = "File Failed to Updated"; } } return View(); }
public bool DeleteExpert(int id) { Expert a = DbContext.Experts.Where(aa => aa.ID == id).FirstOrDefault(); if (a == null) return false; try { if (a.ResumeURL != null && a.ResumeURL != "") { FilesService fs = new FilesService(); fs.DeleteFile(a.ResumeURL); } DbContext.Experts.Remove(a); DbContext.SaveChanges(); return true; } catch (Exception ex) { return false; } }
public int UpdateKeyIssue(KeyIssue keyissue, List<string> ArabicTags, List<string> EnglishTags, IEnumerable<HttpPostedFileBase> Images = null, IEnumerable<HttpPostedFileBase> Files = null,List<int> Countries = null) { KeyIssue A = DbContext.KeyIssues.Where(a => a.ID == keyissue.ID).Include(a => a.Tags).Include(a=> a.Countries).FirstOrDefault(); if (A == null) return -1; A.AuthorID = keyissue.AuthorID; A.Description = keyissue.Description; A.FeatureVideoLink = keyissue.FeatureVideoLink; A.FriendlyURL = keyissue.FriendlyURL; A.IsOnline = keyissue.IsOnline; A.MetaDescription = keyissue.MetaDescription; A.MetaTitle = keyissue.MetaTitle; A.PublishDate = keyissue.PublishDate; A.SourceID = keyissue.SourceID; A.Title = keyissue.Title; A.TopicID = keyissue.TopicID; A.IsFeatured = keyissue.IsFeatured; A.InScroller = keyissue.InScroller; A.TypeID = keyissue.TypeID; A.OriginalId = keyissue.OriginalId; A.Language = keyissue.Language; A.IsHomeVideoFeatured = keyissue.IsHomeVideoFeatured; try { foreach (Tag tag in A.Tags.ToList()) DbContext.Tags.Remove(tag); A.Tags = new List<Tag>(); if (ArabicTags != null) foreach (string t in ArabicTags) A.Tags.Add(new Tag() { Name = t, Language = "ar" }); if (EnglishTags != null) foreach (string t in EnglishTags) A.Tags.Add(new Tag() { Name = t, Language = "en" }); DbContext.SaveChanges(); foreach (Country country in A.Countries.ToList()) A.Countries.Remove(country); if (Countries != null) { A.Countries = new List<Country>(); foreach (int c in Countries) { Country country = DbContext.Countries.Where(cc => cc.ID == c).FirstOrDefault(); if (country != null) A.Countries.Add(country); } } DbContext.SaveChanges(); if (A.ID > 0 && Images != null && Images.Where(i => i != null).Count() > 0) { if (A.FeatureImageURL != null && A.FeatureImageURL != "") { ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.FeatureImageURL)); foreach (ImageSize IS in LogiConfig.KeyIssuesImageSizes) ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + A.FeatureImageURL), IS.Width.ToString(), IS.Height.ToString()); } AddKeyIssueImages(A.ID, Images); } if (Files != null && Files.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (A.FileURL != null && A.FileURL != "") { fs.DeleteFile(A.FileURL); } string file_url = fs.SaveFiles(Files); A.FileURL = file_url; DbContext.SaveChanges(); } return A.ID; } catch (Exception ex) { return -1; } }
public bool DeleteVacancyApplication(int id) { VacancyApplication va = DbContext.VacancyApplications.Where(v => v.ID == id).FirstOrDefault(); if (va == null) return false; try { if(va.ResumeURL !=null && va.ResumeURL != "" ) { FilesService fs = new FilesService(); fs.DeleteFile(va.ResumeURL); } DbContext.VacancyApplications.Remove(va); DbContext.SaveChanges(); return true; }catch(Exception ex) { return false; } }
public ActionResult Index(IEnumerable<HttpPostedFileBase> registration, IEnumerable<HttpPostedFileBase> giftAcceptance, IEnumerable<HttpPostedFileBase> bylaws, IEnumerable<HttpPostedFileBase> whitepaper, IEnumerable<HttpPostedFileBase> whitepaperAr) { ViewBag.MainNav = Navigator.Main.ABOUT; ViewBag.SubNav = Navigator.Sub.OFFICIALDOC; if (ModelState.IsValid) { try { SectionVariable R_pdf = variabeService.GetVariableByKey("RegistrationPDF"); if (registration != null && registration.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (R_pdf != null) fs.DeleteFile(R_pdf.Value); string file_url = fs.SaveFiles(registration); variabeService.AddUpdateVariable("RegistrationPDF", file_url); } SectionVariable B_pdf = variabeService.GetVariableByKey("ByLawsPDF"); if (bylaws != null && bylaws.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (B_pdf != null) fs.DeleteFile(B_pdf.Value); string file_url = fs.SaveFiles(bylaws); variabeService.AddUpdateVariable("ByLawsPDF", file_url); } SectionVariable W_pdf = variabeService.GetVariableByKey("WhitePaperPDF"); if (whitepaper != null && whitepaper.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (W_pdf != null) fs.DeleteFile(W_pdf.Value); string file_url = fs.SaveFiles(whitepaper); variabeService.AddUpdateVariable("WhitePaperPDF", file_url); } SectionVariable W_pdf_ar = variabeService.GetVariableByKey("WhitePaperPDFAr"); if (whitepaperAr != null && whitepaperAr.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (W_pdf_ar != null) fs.DeleteFile(W_pdf_ar.Value); string file_url = fs.SaveFiles(whitepaperAr); variabeService.AddUpdateVariable("WhitePaperPDFAr", file_url); } SectionVariable A_pdf = variabeService.GetVariableByKey("GiftAcceptancePolicy"); if (giftAcceptance != null && giftAcceptance.Where(f => f != null).Count() > 0) { FilesService fs = new FilesService(); if (A_pdf != null) fs.DeleteFile(A_pdf.Value); string file_url = fs.SaveFiles(giftAcceptance); variabeService.AddUpdateVariable("GiftAcceptancePolicy", file_url); } TempData["SuccessMessage"] = "Files Updated Successfully"; return RedirectToAction("Index"); } catch(Exception ex) { TempData["ErrorMessage"] = "Files Failed to Updated"; } } return View(); }