Exemplo n.º 1
0
        public static List <Friend> FindAllFriendsWithLending()
        {
            using (var db = new DBContext())
            {
                try
                {
                    List <Lending> lendingList = Lending.FindLendingOpened();
                    List <Friend>  friendList  = db.Friend.ToList();
                    List <Friend>  returnList  = new List <Friend>();

                    foreach (var item in friendList)
                    {
                        if (lendingList.Any(p => p.FriendId == item.ID))
                        {
                            returnList.Add(item);
                        }
                    }

                    return(returnList);
                }
                catch (Exception ex)
                {
                    //LogError.insertLog(new LogError(ex.Message, ex.StackTrace));
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public static List <Games> FindNoLendedGames()
        {
            using (var db = new DBContext())
            {
                try
                {
                    //List<Games> gamesList = db.Games.ToList();
                    //List<Games> gamesOut = new List<Games>();
                    //List<Games> returnList = new List<Games>();

                    //foreach (var item in gamesList)
                    //{
                    //    var a = lendingList.Where(p => p.GameId == item.ID).ToList();
                    //    if (lendingList.Contains(item))
                    //    {

                    //    }
                    //    returnList.Add();
                    //}

                    //foreach (var item in lendingList)
                    //{
                    //    gamesOut.Add(item.Games);
                    //}
                    //returnList = gamesList.Except(gamesOut).ToList();

                    //foreach (var item in lendingList)
                    //{

                    //    gamesOut.Add(item.Games);

                    //}
                    //foreach (var item in gamesList)
                    //{
                    //    if (!gamesOut.Contains(item))
                    //    {
                    //        returnList.Add(item);
                    //    }
                    //}

                    //return returnList;
                    var lendingList = Lending.FindLendingOpened().AsQueryable();
                    //var listGames = db.Games.Where(g => !lendingList.Any(l => l.GameId == g.ID)).ToList();

                    var listGames = db.Games
                                    .Where(g => !db.Lending.Any(l => l.GameId == g.ID && string.IsNullOrEmpty(l.DateReturned.Value.ToString())))
                                    .ToList();

                    return(listGames);
                }
                catch (Exception ex)
                {
                    //LogError.insertLog(new LogError(ex.Message, ex.StackTrace));
                    throw;
                }
            }
        }
Exemplo n.º 3
0
        public static Lending ExcludeLending(int id)
        {
            Lending returnLending = new Lending();

            returnLending = FindLending(id);

            ExcludeLending(returnLending);

            return(returnLending);
        }
Exemplo n.º 4
0
        public static Lending ExcludeLending(Lending lending)
        {
            using (var db = new DBContext())
            {
                //db.Lending.Remove(lending);
                db.Lending.Attach(lending);
                db.Entry(lending).State = EntityState.Deleted;

                db.SaveChanges();
                return(lending);
            }
        }
Exemplo n.º 5
0
 public static Lending FindLending(Lending lending)
 {
     using (var db = new DBContext())
     {
         try
         {
             return(db.Lending.Include("Friend").Include("Games").FirstOrDefault(p => p == lending));
         }
         catch (Exception ex)
         {
             //LogError.insertLog(new //LogError(ex.Message, ex.StackTrace));
             throw;
         }
     }
 }
Exemplo n.º 6
0
 public static void InsertLending(Lending lending)
 {
     using (var db = new DBContext())
     {
         try
         {
             db.Lending.Add(lending);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             //LogError.insertLog(new //LogError(ex.Message, ex.StackTrace));
             throw;
         }
     }
 }
Exemplo n.º 7
0
 public static Lending UpdateLendingItem(Lending lending)
 {
     using (var db = new DBContext())
     {
         try
         {
             db.Lending.Attach(lending);
             db.Entry(lending).State = EntityState.Modified;
             db.SaveChanges();
             return(lending);
         }
         catch (Exception ex)
         {
             //LogError.insertLog(new //LogError(ex.Message, ex.StackTrace));
             throw;
         }
     }
 }