public ICollection<AffinityType> GetAllAffinityTypes() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { return context.AffinityTypes .ToList(); } }
public ICollection<Admin> GetAllAdmins() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { return context.Admins .ToList(); } }
public bool IsThisAnyonesUsernameAndPassword(string username, string password) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { var hashedPassword = sha256_hash(password); return (context.Admins.Any(x => x.Username == username && x.Password == hashedPassword)) || (context.SocialGroups.Any(x => x.EmailAddress == username && x.Password == hashedPassword)); } }
public ICollection<City> GetAllCities() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { return context.Cities .ToList(); } }
public SocialGroup GetUserWithThisId(int id) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { return context.SocialGroups .Include("City") .Include("AffinityType") .FirstOrDefault(x => x.Id == id); } }
public ICollection<SocialGroup> GetAllGroups() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { return context.SocialGroups .Include("City") .Include("AffinityType") .ToList(); } }
public ActionResult Index() { ViewBag.Title = "Home Page"; using (var context = new JoinINN.Infrastructure.GroupsDb()) { context.Visitors.First().NumberOfVisits++; context.SaveChanges(); } return View(); }
public SocialGroup GetLogedUser() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { var logedInUserByUsername = loginService.TryGetSignedInUserId(); var me = context.SocialGroups .Include("AffinityType") .FirstOrDefault(x => x.EmailAddress == logedInUserByUsername); return me; } }
public string WhatIsMyRole(string usernameOfLogedInUser) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { if (context.Admins.Any(x => x.Username == usernameOfLogedInUser)) { return "admin"; } else { return "user"; } } }
public Informations GetAllInformationsForAdmin() { using (var context = new JoinINN.Infrastructure.GroupsDb()) { var newInf = new Informations( context.SocialGroups.Count(), context.Visitors.First().NumberOfVisits, context.Admins.Count(), context.SocialGroups.Count(), context.SocialGroups.Count(x => x.CityId == 1), context.SocialGroups.Count(x => x.CityId == 2) ); return newInf; } }
public bool AdminDeleteUser(int id) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { try { var groupToDelete = context.SocialGroups.FirstOrDefault(x => x.Id == id); context.SocialGroups.Remove(groupToDelete); context.SaveChanges(); return true; } catch (Exception e) { return false; } } }
public bool AddNewGroup(SocialGroup socGroup) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { try { socGroup.AffinityType = context.AffinityTypes.FirstOrDefault(x => x.Id == socGroup.AffinityType_Id); socGroup.City = context.Cities.FirstOrDefault(x => x.Id == socGroup.CityId); context.SocialGroups.Add(socGroup); context.SaveChanges(); return true; } catch (DbEntityValidationException dbEx) { return false; } } }
public void EditUser(SocialGroup socGroup) { using (var context = new JoinINN.Infrastructure.GroupsDb()) { try { var existingSocGroup = context.SocialGroups.FirstOrDefault(x => x.Id == socGroup.Id); existingSocGroup.AffinityType = context.AffinityTypes.FirstOrDefault(x => x.Id == socGroup.AffinityType_Id); existingSocGroup.Password = socGroup.Password; existingSocGroup.Name = socGroup.Name; existingSocGroup.OfficialWebUrl = socGroup.OfficialWebUrl; existingSocGroup.FacebookPageUrl = socGroup.FacebookPageUrl; existingSocGroup.photoUrl = socGroup.photoUrl; existingSocGroup.ContactNumber = socGroup.ContactNumber; existingSocGroup.Description = socGroup.Description; context.SaveChanges(); } catch (DbEntityValidationException dbEx) { } } }