//Get all the News on page load private void ViewNews() { NZEduEntities data = new NZEduEntities(); rptrNews.DataSource = data.NewsInfoes.ToList(); rptrNews.DataBind(); }
/// <summary> /// To Change admin Password /// </summary> public bool changepassword(LoginInfoData lidata) { NZEduEntities data = new NZEduEntities(); LoginInfo li = new LoginInfo(); bool ans = false; //Get loginInfo using old password li = (from l in data.LoginInfoes where l.UserID == lidata.Userid where l.Password == lidata.Oldpassword select l).FirstOrDefault(); if (li != null) { var info = from l in data.LoginInfoes where l.UserID == lidata.Userid select l; foreach (LoginInfo li1 in info) { li1.Password = lidata.Password; //set new password for the same } ans = true; } else if (li == null) { ans = false; } data.SaveChanges(); // ans save the changes return(ans); }
//Get all the Enquiries received private void BindEnquiry() { NZEduEntities data = new NZEduEntities(); rptrEnquiry.DataSource = data.Contacts.ToList(); // Get all the contacts / enquiries here rptrEnquiry.DataBind(); }
//Get all the banner images private void ViewBanner() { NZEduEntities data = new NZEduEntities(); rptrBanner.DataSource = data.BannerInfoes.ToList(); rptrBanner.DataBind(); }
//Get all Gallery images private void ViewImages() { NZEduEntities data = new NZEduEntities(); var img = from v in data.ImageInfoes select v; rptrGallery.DataSource = img.ToList(); rptrGallery.DataBind(); }
//Get one image Info public ImageInfo ViewPhoto1(int ImageID) { NZEduEntities data = new NZEduEntities(); ImageInfo i = new ImageInfo(); i = data.ImageInfoes.Single(c => c.ImageID == ImageID); // lamda expression return(i); }
//Get one Banner info from the supplied bannerId public BannerInfo ViewPhoto1(int BannerID) { NZEduEntities data = new NZEduEntities(); BannerInfo bt = new BannerInfo(); bt = data.BannerInfoes.Single(c => c.BannerID == BannerID); // lamda expression return(bt); }
//Get one enquiry public Contact ViewEnquiry(int id) { NZEduEntities data = new NZEduEntities(); Contact ct = new Contact(); ct = data.Contacts.Single(c => c.id == id); // lamda expression return(ct); }
//Get one News public NewsInfo ViewNews(int NewsID) { NZEduEntities data = new NZEduEntities(); NewsInfo bt = new NewsInfo(); bt = data.NewsInfoes.Single(c => c.NewsID == NewsID); // lamda expression return(bt); }
/// <summary> /// To perform admin Login /// </summary> public LoginInfo login(LoginInfoData liData) { NZEduEntities data = new NZEduEntities(); LoginInfo li = new LoginInfo(); // linq query li = (from login in data.LoginInfoes where login.UserName == liData.Username & login.Password == liData.Password select login).Single(); return(li); }
protected void rptrBanner_ItemCommand(object source, RepeaterCommandEventArgs e) { try { NZEduEntities data = new NZEduEntities(); if (e.CommandName.Equals("del")) // to delete any banner image { int BannerID = int.Parse(e.CommandArgument.ToString()); BannerInfo bt = new BannerInfoAction().ViewPhoto1(BannerID); // retrive the info for the banner if (bt != null) { data.BannerInfoes.Attach(bt); data.BannerInfoes.Remove(bt); // remove banner info from db data.SaveChanges(); string path = Server.MapPath("~/Image/Banner/" + bt.BannerSize.ToString() + bt.BannerName); if (File.Exists(path)) { File.Delete(path); //delete the image from path ViewBanner(); // bind the banners again lblmsg.Text = "Banner Deleted!"; } } } if (e.CommandName.Equals("delall")) // to delete all the banners at once { var dbBannerId = from b in data.BannerInfoes select b.BannerID; // Get all Banner Id(s) string path; foreach (var bid in dbBannerId) { BannerInfo bt = new BannerInfo(); bt = data.BannerInfoes.Single(c => c.BannerID == bid); // lamda expression path = Server.MapPath("~/Image/Banner/" + bt.BannerSize.ToString() + bt.BannerName); if (File.Exists(path)) { File.Delete(path); // remove images from the path } data.BannerInfoes.Attach(bt); data.BannerInfoes.Remove(bt); // remove banners info } data.SaveChanges(); ViewBanner(); // method calling } } catch (Exception ex) { Response.Write(ex.Message); } }
//Delete gallery images implementation here protected void rptrGallery_ItemCommand(object source, RepeaterCommandEventArgs e) { try { NZEduEntities data = new NZEduEntities(); if (e.CommandName.Equals("del")) // delete one image { int ImageID = int.Parse(e.CommandArgument.ToString()); ImageInfo bt = new ImageInfoAction().ViewPhoto1(ImageID); //method calling to get image info to delete if (bt != null) { data.ImageInfoes.Attach(bt); data.ImageInfoes.Remove(bt); data.SaveChanges(); string path = Server.MapPath("~/Image/Gallery/" + bt.ImageSize.ToString() + bt.ImageName); if (File.Exists(path)) { File.Delete(path); ViewImages(); } } } if (e.CommandName.Equals("delall")) // to delete all gallery images at once { var dbBannerId = from b in data.ImageInfoes select b.ImageID; // Get all image Id(s) string path; foreach (var Gid in dbBannerId) { ImageInfo bt = new ImageInfo(); bt = data.ImageInfoes.Single(c => c.ImageID == Gid); // lamda expression path = Server.MapPath("~/Image/Gallery/" + bt.ImageSize.ToString() + bt.ImageName); if (File.Exists(path)) { File.Delete(path); } data.ImageInfoes.Attach(bt); data.ImageInfoes.Remove(bt); } data.SaveChanges(); ViewImages(); } } catch (Exception ex) { Response.Write(ex.Message); } }
/// <summary> /// Edit and Delete News info /// </summary> protected void rptrNews_ItemCommand(object source, RepeaterCommandEventArgs e) { try { NZEduEntities n = new NZEduEntities(); if (e.CommandName.Equals("del")) //Delete one news { int NewsID = int.Parse(e.CommandArgument.ToString()); NewsInfo data = new NewsInfoAction().ViewNews(NewsID); // getting a News to delete if (data != null) { n.NewsInfoes.Attach(data); n.NewsInfoes.Remove(data); n.SaveChanges(); ViewNews(); lblmsg.Text = "New Deleted!"; } } if (e.CommandName.Equals("delall")) //Delete all news at once { var newsIds = from b in n.NewsInfoes select b.NewsID; // Get all news Id(s) foreach (var nid in newsIds) { NewsInfo bt = new NewsInfo(); bt = n.NewsInfoes.Single(c => c.NewsID == nid); // lamda expression n.NewsInfoes.Attach(bt); n.NewsInfoes.Remove(bt); } n.SaveChanges(); ViewNews(); } if (e.CommandName.Equals("edit")) //Edit News info { int NewsID = int.Parse(e.CommandArgument.ToString()); NewsInfo data = new NewsInfoAction().ViewNews(NewsID); // getting a News to delete if (data != null) { lblnewsid.Text = data.NewsID.ToString(); txtnewsup.Text = data.News; txtnewsheadup.Text = data.NewsHeadline; Panel1.Visible = true; } } } catch (Exception ex) { Response.Write(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { //Set text in title bar Literal lt = Page.Master.FindControl("ltTitle") as Literal; lt.Text = "Home | Auckland Education Society"; //Get all banner / slider images on page load NZEduEntities data = new NZEduEntities(); var ban = from b in data.BannerInfoes select b; rptrbanner.DataSource = ban.ToList(); rptrbanner.DataBind(); }
//Add news info public int AddNews(NewsInfoData Nidata) { NZEduEntities apData = new NZEduEntities(); NewsInfo data = new NewsInfo(); data.News = Nidata.News; data.NewsDate = Nidata.NewsDate; data.NewsHeadline = Nidata.NewsHeadline; apData.NewsInfoes.Add(data); int ans = apData.SaveChanges(); return(ans); }
protected void Page_Load(object sender, EventArgs e) { //Set text in title bar Literal lt = Page.Master.FindControl("ltTitle") as Literal; lt.Text = "Image Gallery | Auckland Education Society"; //Get all Galley images and info NZEduEntities data = new NZEduEntities(); var image = from i in data.ImageInfoes select i; rptrimg.DataSource = image.ToList(); rptrimg.DataBind(); }
//Add Banner / slider Image public int AddPhoto(BannerInfoData Bidata) { NZEduEntities apData = new NZEduEntities(); BannerInfo data = new BannerInfo(); data.BannerName = Bidata.BannerName; data.BannerExtension = Bidata.BannerName.Substring(Bidata.BannerName.LastIndexOf('.')); data.BannerSize = Bidata.BannerSize; data.BannerType = Bidata.BannerType; apData.BannerInfoes.Add(data); int ans = apData.SaveChanges(); return(ans); }
//Add Gallery images public int AddPhoto(ImageInfoData idata) { NZEduEntities apData = new NZEduEntities(); ImageInfo data = new ImageInfo(); data.ImageName = idata.ImageName; data.ImageExtension = idata.ImageName.Substring(idata.ImageName.LastIndexOf('.')); data.ImageSize = idata.ImageSize; data.ImageType = idata.ImageType; data.ImageDescription = idata.ImageDescription; apData.ImageInfoes.Add(data); int ans = apData.SaveChanges(); return(ans); }
//This method will send EnquiryInfo to Admin in admin panel public int AddContactInfo(ContactInfo ciData) { // bool ans = false; NZEduEntities data = new NZEduEntities(); Contact ni = new Contact(); ni.Name = ciData.Name; ni.Phone = ciData.Mobile; ni.Subject = ciData.Subject; ni.Message = ciData.Msg; data.Contacts.Add(ni); int ans = data.SaveChanges(); return(ans); }
//Update news info public int UpdateNews(NewsInfoData data) { NZEduEntities nidata = new NZEduEntities(); NewsInfo ni = new NewsInfo(); var nsd = from p in nidata.NewsInfoes where p.NewsID == data.NewsID select p; foreach (NewsInfo nifo in nsd) { nifo.NewsID = data.NewsID; nifo.NewsHeadline = data.NewsHeadline; nifo.News = data.News; nifo.NewsDate = data.NewsDate; } int ans = nidata.SaveChanges(); return(ans); }
//Delete Enquiry implementation protected void rptrEnquiry_ItemCommand(object source, RepeaterCommandEventArgs e) { try { NZEduEntities n = new NZEduEntities(); if (e.CommandName.Equals("del")) // delete one enquiry { int NewsID = int.Parse(e.CommandArgument.ToString()); Contact data = new ContactInfoAction().ViewEnquiry(NewsID); // getting a News to delete if (data != null) { n.Contacts.Attach(data); n.Contacts.Remove(data); n.SaveChanges(); BindEnquiry(); lblmsg.Text = "*Enquiry Deleted!"; } } if (e.CommandName.Equals("delall")) // delete all enquiries { var ctid = from b in n.Contacts select b.id; // Get all enquiry Id(s) foreach (var nid in ctid) { Contact bt = new Contact(); bt = n.Contacts.Single(c => c.id == nid); // lamda expression n.Contacts.Attach(bt); n.Contacts.Remove(bt); } n.SaveChanges(); BindEnquiry(); // method calling } } catch (Exception ex) { lblmsg.Text = ex.Message; } }