/// <summary> /// Метод добавляет в базу данных объект типа LocationArea /// </summary> /// <param name="location_area">Объект типа LocationArea</param> public static void Add(LocationArea location_area) { location_area _location_area = new location_area(); _location_area.id_account = location_area.id_account; _location_area.name = location_area.name; _location_area.lattitude = location_area.lattitude; _location_area.longtitude = location_area.longtitude; _location_area.radius = location_area.radius; _location_area.id = location_area.id; _location_area.time_of_marking = location_area.time_of_marking; using (CustomSuzyEntities db = new CustomSuzyEntities()) { db.location_area.Add(_location_area); db.SaveChanges(); } }
/// <summary> /// Убрать подпись на аккаунт /// </summary> public void UnFollowing(int accountId) { if (this.id > 0 && this.id != accountId) { using (CustomSuzyEntities db = new CustomSuzyEntities()) { var subs = from sub in db.subscribers where sub.id_leader == accountId && sub.id_subscriber == this.id select sub; if (subs.Any()) { db.subscribers.Remove(subs.First()); db.SaveChanges(); } } } }
/// <summary> /// Save Avatar (only File name) /// </summary> public void SaveAvatar(String Path) { avatar avatar = new avatar(); avatar.avatar_src = Path; using (CustomSuzyEntities db = new CustomSuzyEntities()) { db.avatars.Add(avatar); db.SaveChanges(); } this.id_avatar = avatar.id; Save(); }
/// <summary> /// Этот метод сохраняет наш Account в БД /// </summary> public void Save() { using (CustomSuzyEntities db = new CustomSuzyEntities()) { //Проверяю нет ли такого имени или емейла var account = db.accounts.Find(id); var aEmail = from a in db.accounts where a.email == this.email && a.id != this.id select a; var aName = from a in db.accounts where a.name == name && a.id != this.id select a; if ((!string.IsNullOrEmpty(this.email) && aEmail.Any()) || (!string.IsNullOrEmpty(this.name) && aName.Any())) { } else { account.name = this.name; account.password = this.password; account.email = this.email; account.id_avatar = this.id_avatar; account.ban = this.ban; account.admin = this.admin; db.SaveChanges(); } } }
///// <summary> ///// Проверяет, есть ли подписчиком аккаунт ///// </summary> //public bool IsFollowing(int accountId) //{ // using (CustomSuzyEntities db = new CustomSuzyEntities()) // { // var subs = from sub in db.subscribers // where sub.id_leader == accountId && // sub.id_subscriber == this.id // select sub; // return subs.Any(); // } //} /// <summary> /// Подпись на аккаунт /// </summary> /// <param name="location_area">Аккаунт на который подписываемся</param> public void Following(int accountId) { if (this.id > 0 && this.id != accountId) { using (CustomSuzyEntities db = new CustomSuzyEntities()) { var subs = from sub in db.subscribers where sub.id_leader == accountId && sub.id_subscriber == this.id select sub; if (!subs.Any()) { db.subscribers.Add(new subscriber() { id_leader = accountId, id_subscriber = this.id }); db.SaveChanges(); } } } }
/// <summary> /// Этот метод сохраняет нашу Локацию в БД /// </summary> public void Save() { using (CustomSuzyEntities db = new CustomSuzyEntities()) { var location_area = db.location_area.Find(id); location_area.id = this.id; location_area.name = this.name; location_area.lattitude = this.lattitude; location_area.longtitude = this.longtitude; location_area.radius = this.radius; location_area.id_account = this.id_account; location_area.time_of_marking = this.time_of_marking; db.SaveChanges(); } }