Пример #1
0
        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));
        }
Пример #2
0
        public static List <string> RetrieveCategories()
        {
            dbEntities db         = new dbEntities();
            var        categories = (from c in db.Sites select c.Category).Distinct().ToList();

            return(categories);
        }
Пример #3
0
        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
        }
Пример #4
0
        public static List <DateTime> GetDates()
        {
            dbEntities db    = new dbEntities();
            var        dates = (from c in db.Calendar select c.Date).ToList <DateTime>();

            return(dates);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        //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");
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        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
        }
Пример #17
0
        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);
        }
Пример #18
0
        //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);
        }
Пример #19
0
        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);
        }