예제 #1
0
        public bool DeleteTripEntity(long id)
        {
            try
            {
                using (LocalTravelAppMSSQLDBContext localTravelAppMSSQLDBContext = new LocalTravelAppMSSQLDBContext())
                {
                    bool removedPerUser = CurrentUserEntity.UserEntity.TripEntities.
                                          Remove(CurrentUserEntity.UserEntity.TripEntities.ToList().Where(t => t.Id == id).FirstOrDefault());

                    TripEntity removedFromTrips = localTravelAppMSSQLDBContext.TripEntities.Remove(localTravelAppMSSQLDBContext.TripEntities.ToList().Where(t => t.Id == id).FirstOrDefault());

                    localTravelAppMSSQLDBContext.SaveChanges();

                    if (removedPerUser && removedFromTrips != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
예제 #2
0
 public UserEntity RegistrateUser(UserEntity userEntity)
 {
     try
     {
         using (LocalTravelAppMSSQLDBContext localTravelAppMSSQLDBContext = new LocalTravelAppMSSQLDBContext())
         {
             if (localTravelAppMSSQLDBContext.UserEntities.Where(u => u.UserName.Equals(userEntity.UserName)).
                 AsEnumerable().FirstOrDefault(u => u.UserName.Equals(userEntity.UserName)) != null)
             {
                 return(null);
             }
             UserEntity ue = localTravelAppMSSQLDBContext.UserEntities.Add(userEntity);
             ue.TripEntities = new HashSet <TripEntity>();
             localTravelAppMSSQLDBContext.SaveChanges();
             return(ue);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         System.Diagnostics.Debug.WriteLine(e);
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
예제 #3
0
 public UserEntity UpdateUserData(UserEntity user)
 {
     try
     {
         using (LocalTravelAppMSSQLDBContext localTravelAppMSSQLDBContext = new LocalTravelAppMSSQLDBContext())
         {
             localTravelAppMSSQLDBContext.UserEntities.AddOrUpdate(user);
             localTravelAppMSSQLDBContext.SaveChanges();
             return(user);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #4
0
 public bool AddTripEntity(TripEntity tripEntity)
 {
     try
     {
         using (LocalTravelAppMSSQLDBContext localTravelAppMSSQLDBContext = new LocalTravelAppMSSQLDBContext())
         {
             CurrentUserEntity.UserEntity.TripEntities.Add(tripEntity);
             localTravelAppMSSQLDBContext.TripEntities.Add(tripEntity);
             localTravelAppMSSQLDBContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #5
0
 public UserEntity FindUserByLogin(string Login)
 {
     try
     {
         using (LocalTravelAppMSSQLDBContext localTravelAppMSSQLDBContext = new LocalTravelAppMSSQLDBContext())
         {
             UserEntity ue = localTravelAppMSSQLDBContext.UserEntities.AsEnumerable().FirstOrDefault(u => u.UserName.Equals(Login));
             if (ue != null)
             {
                 ue.TripEntities = new HashSet <TripEntity>(localTravelAppMSSQLDBContext.TripEntities.
                                                            Where(t => t.UserEntityId == ue.Id));
             }
             return(ue);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }