/// <summary> /// Получение модели лодки из БД по названию /// </summary> /// <param name="name"></param> /// <returns></returns> public BoatModel GetByName(string name) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.BoatModels.FirstOrDefault(x => x.Name == name)); } }
/// <summary> /// Получить все заявки для лодки /// </summary> /// <param name="boat_id"></param> /// <returns></returns> public IEnumerable <Message> GetAllByBoat(int boat_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Messages.Where(x => x.BoatId == boat_id && x.Type.Equals("message")).ToList()); } }
/// <summary> /// Получение модели лодки из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public BoatModel GetById(int id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.BoatModels.FirstOrDefault(x => x.Id == id)); } }
/// <summary> /// Получение лодок из БД для указанного пользователя /// </summary> /// <returns></returns> public IEnumerable <Boat> Boat_GetByUserId(int owner_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Boats.Where(x => x.OwnerId == owner_id).ToList()); } }
/// <summary> /// Получение всех новостей из БД /// </summary> /// <returns></returns> public IEnumerable <News> GetAll() { using (TripleBDbContext db = new TripleBDbContext()) { return(db.News.ToList()); } }
/// <summary> /// Возвращает последнюю лодку из списка /// </summary> /// <returns></returns> public Boat Boat_GetLast() { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Boats.ToList().Last()); } }
/// <summary> /// Получение всех лодок из БД /// </summary> /// <returns></returns> public IEnumerable <Boat> Boat_GetAll(string kind) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Boats.Where(x => x.Kind.Equals(kind)).ToList()); } }
/// <summary> /// Получение аккаунта из БД по электронному адресу /// </summary> /// <param name="email"></param> /// <returns></returns> public Account GetByEmail(string email) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Accounts.FirstOrDefault(x => x.Email == email)); } }
/// <summary> /// Получение аккаунта из БД по логину /// </summary> /// <param name="id"></param> /// <returns></returns> public Account GetByLogin(string login) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Accounts.FirstOrDefault(x => x.Login == login)); } }
/// <summary> /// Получение аккаунта из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public Account GetById(int id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Accounts.FirstOrDefault(x => x.Id == id)); } }
/// <summary> /// Получение заявки из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public Message GetById(int id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Messages.FirstOrDefault(x => x.Id == id)); } }
/// <summary> /// Получение всех моделей лодок из БД /// </summary> /// <returns></returns> public IEnumerable <BoatModel> Read() { using (TripleBDbContext db = new TripleBDbContext()) { return(db.BoatModels.ToList()); } }
/// <summary> /// Получение текстового блока из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public TextBlock Read(int id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.NewsTexts.FirstOrDefault(x => x.Id == id)); } }
/// <summary> /// Получение всех заявок из БД /// </summary> /// <returns></returns> public IEnumerable <Message> Read() { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Messages.ToList()); } }
/// <summary> /// Получить все исходящие заявки от пользователя /// </summary> /// <param name="user_id"></param> /// <returns></returns> public IEnumerable <Message> GetAllOutbox(int user_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Messages.Where(x => x.FromId == user_id && x.Type.Equals("recall")).ToList()); } }
/// <summary> /// Получение всех договоров аренды из БД /// </summary> /// <returns></returns> public IEnumerable <Rent> Read() { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Rents.ToList()); } }
/// <summary> /// Получение договора аренды из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public Rent Read(int id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Rents.FirstOrDefault(x => x.Id == id)); } }
/// <summary> /// Получение всех договоров аренды для указанной лодки /// </summary> /// <returns></returns> public IEnumerable <Rent> GetByOwnerId(int owner_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Rents.Where(x => x.RecallId == owner_id).ToList()); } }
/// <summary> /// Получение изображения из БД по Id /// </summary> /// <param name="id"></param> /// <returns></returns> public Image GetFirstByOwnerId(int owner_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.Images.Where(x => x.OwnerId == owner_id).FirstOrDefault()); } }
/// <summary> /// Получение всех текстовых блоков из БД /// </summary> /// <returns></returns> public IEnumerable <TextBlock> GetByOwnerId(int owner_id) { using (TripleBDbContext db = new TripleBDbContext()) { return(db.NewsTexts.Where(x => x.OwnerId == owner_id).ToList()); } }
/// <summary> /// Получение всех изображений из БД /// </summary> /// <returns></returns> public IEnumerable <Image> GetAllByOwnerId(int owner_id) { using (TripleBDbContext db = new TripleBDbContext()) { var result = db.Images.Where(x => x.OwnerId == owner_id).ToList(); return(result); } }
/// <summary> /// Обновление данных текстового блока в БД /// </summary> /// <param name="textblock"></param> public void Update(TextBlock textblock) { using (TripleBDbContext db = new TripleBDbContext()) { if (textblock != null) { db.NewsTexts.Update(textblock); db.SaveChanges(); } } }
/// <summary> /// Обновление данных договора аренды в БД /// </summary> /// <param name="rent"></param> public void Update(Rent rent) { using (TripleBDbContext db = new TripleBDbContext()) { if (rent != null) { db.Rents.Update(rent); db.SaveChanges(); } } }
/// <summary> /// Обновление данных модели лодки в БД /// </summary> /// <param name="boatmodel"></param> public void Update(BoatModel boatmodel) { using (TripleBDbContext db = new TripleBDbContext()) { if (boatmodel != null) { db.BoatModels.Update(boatmodel); db.SaveChanges(); } } }
/// <summary> /// Добавление аккаунта в БД /// </summary> /// <param name="account"></param> public void Create(Account account) { using (TripleBDbContext db = new TripleBDbContext()) { if (account != null) { db.Accounts.Add(account); db.SaveChanges(); } } }
/// <summary> /// Обновление данных заявки в БД /// </summary> /// <param name="recall"></param> public void Update(Message recall) { using (TripleBDbContext db = new TripleBDbContext()) { if (recall != null) { db.Messages.Update(recall); db.SaveChanges(); } } }
/// <summary> /// Добавление изображения в БД /// </summary> /// <param name="image"></param> public void Create(Image image) { using (TripleBDbContext db = new TripleBDbContext()) { if (image != null) { db.Images.Add(image); db.SaveChanges(); } } }
/// <summary> /// Удаление заявки из БД /// </summary> /// <param name="id"></param> public void Delete(int id) { using (TripleBDbContext db = new TripleBDbContext()) { Message recall = db.Messages.FirstOrDefault(x => x.Id == id); if (recall != null) { db.Messages.Remove(recall); db.SaveChanges(); } } }
/// <summary> /// Удаление договора аренды из БД /// </summary> /// <param name="id"></param> public void Delete(int id) { using (TripleBDbContext db = new TripleBDbContext()) { Rent rent = db.Rents.FirstOrDefault(x => x.Id == id); if (rent != null) { db.Rents.Remove(rent); db.SaveChanges(); } } }
/// <summary> /// Добавление заявки в БД /// </summary> /// <param name="recall"></param> public int Create(Message recall) { using (TripleBDbContext db = new TripleBDbContext()) { if (recall != null) { db.Messages.Add(recall); db.SaveChanges(); } } return(recall.Id); }