public static Host GetHost(int id)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             Host host = entities.Hosts.First(p => p.HostID == id);
             return(host);
         }
     }
     catch (Exception ex) { return(null); }
 }
Beispiel #2
0
 public static Traveler GetTraveler(int id)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             Traveler traveler = entities.Travelers.Include(t => t.User).First(t => t.TravelerID == id);
             return(traveler);
         }
     }
     catch { return(null); }
 }
Beispiel #3
0
 public static User Login(User u)
 {
     try
     {
         using (YMprojectEntities1 ym = new YMprojectEntities1())
         {
             return(ym.Users.Where(user => user.UserName == u.UserName && user.UserPassword == u.UserPassword).FirstOrDefault());
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
 public static List <ServiceTypeList> GetServicesList()
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             return(entities.ServiceTypeLists.ToList());
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
 public static string GetServiceNameById(int id)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             return(entities.ServiceTypeLists.Where(s => s.ServiceTypeListID == id).First().ServiceTypeName);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #6
0
 public static bool UpdateTraveler(Traveler traveler)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             Traveler tt = entities.Travelers.First(t => t == traveler);
             tt = traveler;
             entities.SaveChanges();
         }
         return(true);
     }
     catch { return(false); }
 }
Beispiel #7
0
 public static bool IsExist(string userName)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             return(entities.Users.Any(u => u.UserName.Equals(userName)));
         }
     }
     catch (Exception e)
     {
         //print exception
         return(false);
     }
 }
Beispiel #8
0
        public static Suggestion UpdateSuggestion(Suggestion suggestion)
        {
            try
            {
                try
                {
                    using (YMprojectEntities1 entities = new YMprojectEntities1())
                    {
                        var ss = entities.Suggestions.First(s => s.SuggestionID == suggestion.SuggestionID);

                        DbEntityEntry <Suggestion> ee = entities.Entry(ss);
                        ee.CurrentValues.SetValues(suggestion);
                        entities.SaveChanges();
                        return(suggestion);
                    }
                }
                catch (Exception ex1)
                {
                    int id = suggestion.SuggestionID;
                    using (YMprojectEntities1 entities = new YMprojectEntities1())
                    {
                        //Suggestion ss;
                        var ss = entities.Suggestions.First(s => s.SuggestionID == suggestion.SuggestionID);
                        // ss = suggestion;
                    }
                    using (YMprojectEntities1 entities = new YMprojectEntities1())
                    {
                        suggestion.Host = null;
                        ManageSuggestion.DeleteSuggestion(id);
                    }
                    using (YMprojectEntities1 entities = new YMprojectEntities1())
                    {
                        Suggestion spdt = ManageSuggestion.SaveSuggestion(suggestion);
                        entities.SaveChanges();

                        // Suggestion pdt = entities.Suggestions.Where(spdt => id== spdt.SuggestionID).First();
                        return(spdt);
                    }
                }
            }



            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #9
0
 public static Traveler SaveTraveler(User traveler)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             entities.Users.Add(traveler);
             entities.SaveChanges();
             return(traveler.Traveler);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #10
0
 public static bool DeleteTraveler(Traveler traveler)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             entities.Travelers.Remove(traveler);
             entities.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #11
0
 public static Suggestion SaveSuggestion(Suggestion suggestion)
 {
     using (YMprojectEntities1 entities = new YMprojectEntities1())
     {
         try
         {
             entities.Suggestions.Add(suggestion);
             entities.SaveChanges();
             return(suggestion);
         }
         catch (Exception ex)
         {
             return(null);
         }
     }
 }
Beispiel #12
0
 public static bool DeleteHost(User userHost)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             entities.Users.Remove(userHost);
             entities.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #13
0
 public static Host UpdateHost(Host userHost)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             Host hh = entities.Hosts.First(h => h == userHost);
             if (hh != null)
             {
                 hh = userHost;
             }
             entities.SaveChanges();
             return(hh);
         }
     }
     catch { return(null); }
 }
Beispiel #14
0
 public static Host SaveHost(User userhost)
 {
     try
     {
         int x;
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             entities.Users.Add(userhost);
             entities.SaveChanges();
             x = userhost.UserId;
             return(userhost.Host);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #15
0
 public static List <Suggestion> GetSuggestions(int id)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             List <Suggestion> suggestions = entities.Suggestions
                                             .Include(ss => ss.bookedDates)
                                             .Include(ss => ss.ageRange)
                                             .Include(ss => ss.Address)
                                             .Include(ss => ss.ServiceTypesToSuggestions)
                                             .Include(ss => ss.HoursRange)
                                             .Where(s => s.hostId == id).ToList();
             return(suggestions);
         }
     }
     catch (Exception ex) { return(null); }
 }
Beispiel #16
0
        public static bool DeleteSuggestion(int id)
        {
            using (YMprojectEntities1 entities = new YMprojectEntities1())
            {
                try
                {
                    Suggestion suggestion = entities.Suggestions.Where(s => s.SuggestionID == id)
                                            .Include(ss => ss.ServiceTypesToSuggestions)
                                            .Include(ss => ss.bookedDates)
                                            .First();
                    if (suggestion.Address != null)
                    {
                        entities.Addresses.Remove(suggestion.Address);
                    }
                    if (suggestion.ageRange != null)
                    {
                        entities.ageRanges.Remove(suggestion.ageRange);
                    }
                    if (suggestion.HoursRange != null)
                    {
                        entities.HoursRanges.Remove(suggestion.HoursRange);
                    }
                    if (suggestion.ServiceTypesToSuggestions != null)
                    {
                        entities.ServiceTypesToSuggestions.RemoveRange(suggestion.ServiceTypesToSuggestions);
                    }
                    if (suggestion.bookedDates != null)
                    {
                        entities.bookedDates.RemoveRange(suggestion.bookedDates);
                    }

                    // suggestion.ServiceTypesToSuggestions.Clear();

                    entities.Suggestions.Remove(suggestion);
                    entities.SaveChanges();

                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
Beispiel #17
0
 public static Suggestion GetSuggestion(int id)
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             Suggestion suggestion = entities.Suggestions
                                     .Include(ss => ss.bookedDates)
                                     .Include(ss => ss.ageRange)
                                     .Include(ss => ss.Address)
                                     .Include(ss => ss.ServiceTypesToSuggestions)
                                     .Include(ss => ss.HoursRange)
                                     .First(s => s.SuggestionID == id);
             int trygit = 1;
             return(suggestion);
         }
     }
     catch { return(null); }
 }
Beispiel #18
0
 public static List <Suggestion> GetSuggestionsAll()
 {
     try
     {
         using (YMprojectEntities1 entities = new YMprojectEntities1())
         {
             List <Suggestion> suggestions = entities.Suggestions
                                             .Include(ss => ss.bookedDates)
                                             .Include(ss => ss.ageRange)
                                             .Include(ss => ss.Address)
                                             .Include(ss => ss.ServiceTypesToSuggestions)
                                             .Include(ss => ss.HoursRange)
                                             .Include(ss => ss.SuggestionTravelers)
                                             .ToList();
             return(suggestions);
         }
     }
     catch { return(null); }
 }
Beispiel #19
0
 public static User Login(User u)
 {
     try
     {
         using (YMprojectEntities1 ym = new YMprojectEntities1())
         {
             User uu = null;
             uu = ym.Users.Where(user => user.UserName == u.UserName && user.UserPassword == u.UserPassword).First();
             if (uu == null)
             {
                 throw new Exception("user name or password are incorect");
             }
             return(uu);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Beispiel #20
0
 public static SuggestionTraveler SaveSuggestionTraveler(SuggestionTraveler suggestionTraveler)
 {
     using (YMprojectEntities1 entities = new YMprojectEntities1())
     {
         try
         {
             SuggestionTraveler st = entities.SuggestionTravelers.FirstOrDefault(s => s.SuggestionId == suggestionTraveler.SuggestionId && s.TravelerId == suggestionTraveler.TravelerId);
             if (st == null)
             {
                 entities.SuggestionTravelers.Add(suggestionTraveler);
             }
             else
             {
                 st.Status = suggestionTraveler.Status;
             }
             entities.SaveChanges();
             return(suggestionTraveler);
         }
         catch (Exception ex)
         {
             return(null);
         }
     }
 }