public static CommonClient GetUserByEmail(string email) { dbEntities db = new dbEntities(); Clients client = (from c in db.Clients where c.Email == email select c).FirstOrDefault(); return(Mapper.UserToCommon(client)); }
public static List <string> RetrieveCategories() { dbEntities db = new dbEntities(); var categories = (from c in db.Sites select c.Category).Distinct().ToList(); return(categories); }
public static Boolean Register(CommonClient user) { dbEntities db = new dbEntities(); if (UserExists(user)) { return(false); //* If user exists-do not register again. } Clients client = Mapper.UserToDB(user); try { byte[] salt = Hash.GenerateSalt(); string hashedPwd = Hash.ComputeHash(client.HashedPassword, salt); client.HashedPassword = hashedPwd; client.Salt = Convert.ToBase64String(salt); db.Clients.Add(client); db.SaveChanges(); } catch (DbEntityValidationException dbEx) { Debug.WriteLine(dbEx.Message); } return(true);//* User added succeessfully }
public static List <DateTime> GetDates() { dbEntities db = new dbEntities(); var dates = (from c in db.Calendar select c.Date).ToList <DateTime>(); return(dates); }
public static List <CommonSite> RetrieveSitesBySearch(Search paramsList) { dbEntities db = new dbEntities(); List <Sites> sites = new List <Sites>(); if (paramsList.Area != "none" && paramsList.Category != "none") { sites = (from s in db.Sites where s.Area == paramsList.Area && s.Category == paramsList.Category select s).ToList <Sites>(); } else if (paramsList.Area != "none") { sites = (from s in db.Sites where s.Area == paramsList.Area select s).ToList <Sites>(); } else if (paramsList.Category != "none") { sites = (from s in db.Sites where s.Category == paramsList.Category select s).ToList <Sites>(); } List <Sites> retrievedSites = new List <Sites>(); List <CommonSite> siteList = new List <CommonSite>(); retrievedSites.AddRange(sites); foreach (Sites site in retrievedSites) { siteList.Add(Mapper.SiteToCommon(site)); } return(siteList); }
public static CommonClient GetUserById(int id) { dbEntities db = new dbEntities(); Clients client = (from c in db.Clients where c.ClientId == id select c).FirstOrDefault(); CommonClient commonClient = Mapper.UserToCommon(client); return(commonClient); }
public static List <CommonEquipment> GetEquipment() { dbEntities db = new dbEntities(); List <Equipment> eq = (from e in db.Equipment select e).ToList(); List <CommonEquipment> ceq = new List <CommonEquipment>(); foreach (var e in eq) { ceq.Add(Mapper.EquipmentToCommon(e)); } return(ceq); }
public static IEnumerable <CommonTrip> RetrieveTripsByClient(string email) { dbEntities db = new dbEntities(); int clientId = DataUser.GetUserByEmail(email).ClientId; var trips = (from t in db.Trips where t.ClientId == clientId select t).ToList <Trips>(); List <CommonTrip> clientTrips = new List <CommonTrip>(); foreach (Trips t in trips) { clientTrips.Add(Mapper.TripToCommon(t)); } return(clientTrips); }
public static List <CommonSite> RetrieveSitesByCategory(string category) { dbEntities db = new dbEntities(); var sites = (from s in db.Sites where s.Category == category select s).ToList <Sites>(); List <Sites> retrievedSites = new List <Sites>(); List <CommonSite> siteList = new List <CommonSite>(); retrievedSites.AddRange(sites); foreach (Sites site in retrievedSites) { siteList.Add(Mapper.SiteToCommon(site)); } return(siteList); }
public static Boolean AddSite(CommonSite site) { dbEntities db = new dbEntities(); try { Sites newSite = Mapper.SiteToDB(site); db.Sites.Add(newSite); db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public static Boolean SaveAddressAndNum(Data data) { dbEntities db = new dbEntities(); Clients client = (from c in db.Clients where c.Email == data.Email select c).FirstOrDefault(); try { client.NumPeople = data.NumOfPeople.ToString(); client.LeavingAddress = data.Address; db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
//static dbEntities db = new dbEntities(); public static String GetEquipmentNameById(int equipmentId) { dbEntities db = new dbEntities(); try { string equipment = (from e in db.Equipment where e.EquipmentId == equipmentId select e.Name).FirstOrDefault(); if (equipment != null) { return(equipment); } } catch (Exception e) { Debug.WriteLine(e.Message + " " + e.StackTrace); } return("equipment not found"); }
public static int GetEquipmentIdByName(string equipmentName) { dbEntities db = new dbEntities(); try { Equipment equipment = (from e in db.Equipment where e.Name == equipmentName select e).FirstOrDefault(); if (equipment != null) { return(equipment.EquipmentId); } } catch (Exception e) { Debug.WriteLine(e.Message + " " + e.StackTrace); } return(-1); }
public static Boolean UserExists(CommonClient user) { dbEntities db = new dbEntities(); try { var result = (from c in db.Clients where c.Email == user.Email select c).FirstOrDefault(); //* Try to select this user from db. if (result != null) { return(true); //* User exists } } catch (Exception e) { Debug.WriteLine(e.Message + " " + e.StackTrace);//* maybe rather throw back... } return(false); }
public static List <CommonSite> RetrieveSitesByArea(string area) { dbEntities db = new dbEntities(); List <Sites> retrievedSites = new List <Sites>(); List <CommonSite> siteList = new List <CommonSite>(); //using ( dbEntities db = new dbEntities() ) //{ // var sites = (from s in db.Sites where s.Area == area select s).ToList<Sites>(); // retrievedSites.AddRange(sites); //} var sites = (from s in db.Sites where s.Area == area select s).ToList <Sites>(); retrievedSites.AddRange(sites); foreach (Sites site in retrievedSites) { siteList.Add(Mapper.SiteToCommon(site)); } return(siteList); }
public static Boolean Login(string email, string password) { dbEntities db = new dbEntities(); try { Clients cl = (from c in db.Clients where c.Email == email select c).FirstOrDefault(); if (cl != null) { if (Hash.VerifyPassword(password, cl.HashedPassword, cl.Salt) == true) { return(true); } } } catch (Exception e) { Debug.WriteLine(e.Message + " " + e.StackTrace); } return(false);//* either email/pswd are incorrect / user doesn't exist }
public static ICollection <CommonSite> RetrieveSitesById(int[] id) { dbEntities db = new dbEntities(); List <Sites> retrievedSites = new List <Sites>(); if (id != null) { foreach (int i in id) { var site = (from s in db.Sites where s.SiteId == i select s).FirstOrDefault(); retrievedSites.Add(site); } List <CommonSite> siteList = new List <CommonSite>(); foreach (Sites site in retrievedSites) { siteList.Add(Mapper.SiteToCommon(site)); } return(siteList); } return(null); }
//static dbEntities db = new dbEntities(); public static Boolean AddTrip(CommonTrip trip) { dbEntities db = new dbEntities(); Trips newTrip = Mapper.TripToDB(trip); //newTrip.Date.AddHours(3); try { db.Trips.Add(newTrip); db.Calendar.Add(new Calendar { Date = trip.Date, DayStatus = "booked" }); db.SaveChanges(); return(true); } catch (DbEntityValidationException dbEx) { Debug.WriteLine(dbEx.Message); } return(false); }
public static List <CommonTrip> viewTrips(DateTime[] dates) { dbEntities db = new dbEntities(); List <CommonTrip> result = new List <CommonTrip>(); if (dates.Length == 2) { DateTime beginDate = dates[0].Date; DateTime endDate = dates[1].Date; var trips = (from t in db.Trips where t.Date >= beginDate && t.Date <= endDate select t).ToList <Trips>(); foreach (Trips t in trips) { result.Add(Mapper.TripToCommon(t)); } return(result); } DateTime date = dates[0].Date; var trip = (from t in db.Trips where t.Date == date select t).FirstOrDefault(); result.Add(Mapper.TripToCommon(trip)); return(result); }