internal static void DeleteContent(ManageModel model) { using (VoteNaijaDBContext db = new VoteNaijaDBContext()) { try { var id = Convert.ToInt32(model.Title); var data = from x in db.Contents where x.ContentID == id select x; try { var data1 = from x in db.VoteSections where x.ContentID == id select x; foreach (var z in data1) { db.VoteSections.Remove(z); } db.SaveChanges(); } catch { } foreach (var y in data) { db.Contents.Remove(y); } db.SaveChanges(); } catch { } } }
internal static void PostArticles(ManageModel model) { VoteNaijaDBContext db = new VoteNaijaDBContext(); var file = model.File; if (file != null) { var ImageName = Path.GetFileName(file.FileName); string physicalPath = HttpContext.Current.Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); var groupId = Convert.ToInt32(model.subGroupName); db.Contents.Add(new Content { Authur = model.Author, Date = DateTime.Now, Title = model.Title, ContentResult = model.Content, GroupID = groupId, ImageUrl = ImageName, Summary = model.Summary }); db.SaveChanges(); } else if (model != null) { var groupId = Convert.ToInt32(model.subGroupName); db.Contents.Add(new Content { Authur = model.Author, Date = DateTime.Now, Title = model.Title, ContentResult = model.Content, GroupID = groupId, Summary = model.Summary }); db.SaveChanges(); } }
internal static void AddVote(int voteId, int UserId, int contentId) { VoteNaijaDBContext db = new VoteNaijaDBContext(); var data = from v in db.VoteSections where v.VoteSectionID == voteId select v; var data2 = from v in db.Contents where v.ContentID == contentId select v; foreach (var d in data) { d.Votes++; } foreach (var d in data2) { List <int> x = new List <int>(); if (d.UserIDs != null) { x = d.UserIDs.DeserializeList <int>(); } x.Add(UserId); d.UserIDs = x.SerializeList(); } db.SaveChanges(); }
internal static void DeleteGroup(ManageModel model) { using (VoteNaijaDBContext db = new VoteNaijaDBContext()) { try { var id = Convert.ToInt32(model.subGroupName); var data = from x in db.Groups where x.GroupID == id select x; try { var data2 = from x in db.Contents where x.GroupID == id select x; foreach (var u in data2) { try { var data1 = from x in db.VoteSections where x.ContentID == u.ContentID select x; foreach (var z in data1) { db.VoteSections.Remove(z); } db.SaveChanges(); } catch { } db.Contents.Remove(u); } db.SaveChanges(); } catch { } foreach (var y in data) { db.Groups.Remove(y); } db.SaveChanges(); } catch (Exception ex) { } } }
internal static void AddGroup(ManageModel model) { if (model != null) { using (VoteNaijaDBContext db = new VoteNaijaDBContext()) { if (model.groupName == "Vote") { db.Groups.Add(new Group { GroupName = model.groupName, SubGroupName = model.subGroupName, IsPoll = true }); } else { db.Groups.Add(new Group { GroupName = model.groupName, SubGroupName = model.subGroupName, IsPoll = false }); } db.SaveChanges(); } } }
internal static void PostVoteSections(ManageModel model, IEnumerable <VotingModel> voteSections) { using (VoteNaijaDBContext db = new VoteNaijaDBContext()) { if (model != null) { var groupId = Convert.ToInt32(model.subGroupName); Content content1 = new Content { Date = DateTime.Now, Title = model.Title, GroupID = groupId, Days = model.Days }; if (voteSections != null) { foreach (var m in voteSections) { if (m.File != null) { var ImageName = Path.GetFileName(m.File.FileName); string physicalPath = HttpContext.Current.Server.MapPath("~/Images/" + ImageName); m.File.SaveAs(physicalPath); db.VoteSections.Add(new VoteSection { Content = content1, Section = m.voteTitle, ImageUrl = ImageName }); } else { db.VoteSections.Add(new VoteSection { Content = content1, Section = m.voteTitle }); } db.SaveChanges(); } } } } }