예제 #1
0
 public List <AdViewModel> GetFilteredList(AdBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Ads
                .Select(rec => new AdViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Username = rec.User.Username,
             Price = rec.Price,
             Date = rec.Date,
             Address = rec.Address,
             Description = rec.Description,
             Type = rec.Type,
             SubType = rec.SubType,
             UserId = rec.UserId
         })
                .ToList());
     }
 }
예제 #2
0
 public AdViewModel GetElement(AdBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var user = context.Ads
                    .FirstOrDefault(rec => rec.Id == model.Id);
         return(user != null ?
                new AdViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Username = rec.User.Username,
             Price = rec.Price,
             Date = rec.Date,
             Address = rec.Address,
             Description = rec.Description,
             Type = rec.Type,
             SubType = rec.SubType,
             UserId = rec.UserId
         } :
                null);
     }
 }
예제 #3
0
 public void Insert(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         context.Balance.Add(CreateModel(model, new Balance()));
         context.SaveChanges();
     }
 }
예제 #4
0
 public void Insert(FavoritesBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         context.Favorites.Add(CreateModel(model, new Favorites()));
         context.SaveChanges();
     }
 }
예제 #5
0
 public void Update(FavoritesBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         var element = context.Favorites.FirstOrDefault(rec => rec.Id ==
                                                        model.Id);
         if (element == null)
         {
             throw new Exception("Сообщение не найдено");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
예제 #6
0
 public void Update(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         var element = context.Balance.FirstOrDefault(rec => rec.Id ==
                                                      model.Id);
         if (element == null)
         {
             throw new Exception("Баланс не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
예제 #7
0
 public List <BalanceViewModel> GetFullList()
 {
     using (var context = new AdBoardDatabase())
     {
         return(context.Balance.Select(rec => new BalanceViewModel
         {
             Id = rec.Id,
             CardFIO = rec.CardFIO,
             Username = context.Messages.Include(x => x.User).FirstOrDefault(x => x.UserId == x.UserId).User.Username,
             CardNumb = rec.CardFIO,
             CardDate = rec.CardFIO,
         })
                .ToList());
     }
 }
예제 #8
0
 public List <MessagesViewModel> GetFullList()
 {
     using (var context = new AdBoardDatabase())
     {
         return(context.Messages.Include(rec => rec.User).Select(rec => new MessagesViewModel
         {
             Id = rec.Id,
             Username = context.Messages.Include(x => x.User).FirstOrDefault(x => x.UserId == rec.UserId).User.Username,
             UserId = rec.UserId,
             Text = rec.Text,
             Date = rec.Date
         })
                .ToList());
     }
 }
예제 #9
0
 public List <FavoritesViewModel> GetFullList()
 {
     using (var context = new AdBoardDatabase())
     {
         return(context.Favorites.Include(rec => rec.User).Select(rec => new FavoritesViewModel
         {
             Id = rec.Id,
             Username = context.Favorites.Include(x => x.User).FirstOrDefault(x => x.UserId == rec.UserId).User.Username,
             UserId = rec.UserId,
             AdName = rec.AdName,
             Link = rec.Link
         })
                .ToList());
     }
 }
예제 #10
0
 public void Delete(FavoritesBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         Favorites element = context.Favorites.FirstOrDefault(rec => rec.Id ==
                                                              model.Id);
         if (element != null)
         {
             context.Favorites.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Сообщение не найдено");
         }
     }
 }
예제 #11
0
 public void Delete(BalanceBindingModel model)
 {
     using (var context = new AdBoardDatabase())
     {
         Balance element = context.Balance.FirstOrDefault(rec => rec.Id ==
                                                          model.Id);
         if (element != null)
         {
             context.Balance.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Клиент не найден");
         }
     }
 }
예제 #12
0
 public List <UsersViewModel> GetFullList()
 {
     using (var context = new AdBoardDatabase())
     {
         return(context.Users.Select(rec => new UsersViewModel
         {
             Id = rec.Id,
             Username = rec.Username,
             Login = rec.Login,
             Password = rec.Password,
             Phone = rec.Phone,
             IsAdmin = rec.IsAdmin,
             IsVerificated = rec.IsVerificated
         })
                .ToList());
     }
 }
예제 #13
0
 public List <BalanceViewModel> GetFilteredList(BalanceBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Balance
                .Select(rec => new BalanceViewModel
         {
             Id = rec.Id,
             CardFIO = rec.CardFIO,
             Username = rec.User.Username,
             CardNumb = rec.CardFIO,
             CardDate = rec.CardFIO,
         })
                .ToList());
     }
 }
예제 #14
0
 public List <AdViewModel> GetFullList()
 {
     using (var context = new AdBoardDatabase())
     {
         return(context.Ads.Select(rec => new AdViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Username = context.Messages.Include(x => x.User).FirstOrDefault(x => x.UserId == x.UserId).User.Username,
             Price = rec.Price,
             Date = rec.Date,
             Address = rec.Address,
             Description = rec.Description,
             Type = rec.Type,
             SubType = rec.SubType,
             UserId = rec.UserId
         })
                .ToList());
     }
 }
예제 #15
0
 public List <MessagesViewModel> GetFilteredList(MessagesBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Messages
                .Include(rec => rec.User)
                .Where(rec => rec.UserId == model.UserId)
                .Select(rec => new MessagesViewModel
         {
             Id = rec.Id,
             Username = rec.User.Username,
             UserId = rec.UserId,
             Text = rec.Text,
             Date = rec.Date
         })
                .ToList());
     }
 }
예제 #16
0
 public BalanceViewModel GetElement(BalanceBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var user = context.Balance
                    .FirstOrDefault(rec => rec.Id == model.Id);
         return(user != null ?
                new BalanceViewModel
         {
             Id = rec.Id,
             CardFIO = rec.CardFIO,
             Username = rec.User.Username,
             CardNumb = rec.CardFIO,
             CardDate = rec.CardFIO,
         } :
                null);
     }
 }
예제 #17
0
 public MessagesViewModel GetElement(MessagesBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var message = context.Messages
                       .FirstOrDefault(rec => rec.Id == model.Id);
         return(message != null ?
                new MessagesViewModel
         {
             Id = message.Id,
             Username = context.Messages.Include(x => x.User).FirstOrDefault(x => x.UserId == x.UserId).User.Username,
             UserId = message.UserId,
             Text = message.Text,
             Date = message.Date
         } :
                null);
     }
 }
예제 #18
0
 public FavoritesViewModel GetElement(FavoritesBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var message = context.Favorites
                       .FirstOrDefault(rec => rec.Id == model.Id);
         return(message != null ?
                new FavoritesViewModel
         {
             Id = rec.Id,
             Username = context.Favorites.Include(x => x.User).FirstOrDefault(x => x.UserId == rec.UserId).User.Username,
             UserId = rec.UserId,
             AdName = rec.AdName,
             Link = rec.Link
         } :
                null);
     }
 }
예제 #19
0
 public List <FavoritesViewModel> GetFilteredList(FavoritesBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Favorites
                .Include(rec => rec.User)
                .Where(rec => rec.UserId == model.UserId)
                .Select(rec => new FavoritesViewModel
         {
             Id = rec.Id,
             Username = context.Favorites.Include(x => x.User).FirstOrDefault(x => x.UserId == rec.UserId).User.Username,
             UserId = rec.UserId,
             AdName = rec.AdName,
             Link = rec.Link
         })
                .ToList());
     }
 }
예제 #20
0
 public List <UsersViewModel> GetFilteredList(UsersBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         return(context.Users
                .Where(rec => rec.Login == model.Login && rec.Password == model.Password)
                .Select(rec => new UsersViewModel
         {
             Id = rec.Id,
             Username = rec.Username,
             Login = rec.Login,
             Password = rec.Password,
             Phone = rec.Phone,
             IsAdmin = rec.IsAdmin,
             IsVerificated = rec.IsVerificated
         })
                .ToList());
     }
 }
예제 #21
0
 public UsersViewModel GetElement(UsersBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AdBoardDatabase())
     {
         var user = context.Users
                    .FirstOrDefault(rec => rec.Login == model.Login || rec.Id == model.Id);
         return(user != null ?
                new UsersViewModel
         {
             Id = user.Id,
             Username = user.Username,
             Login = user.Login,
             Password = user.Password,
             Phone = user.Phone,
             IsAdmin = user.IsAdmin,
             IsVerificated = user.IsVerificated
         } :
                null);
     }
 }