Exemplo n.º 1
0
        public void GetPersonAndDormIdByEmail(string email, out int personId, out int dormId)
        {
            int _personId = Mails.GetAll().Where(x => x.email == email).Select(x => x.person_id).SingleOrDefault();

            personId = _personId;
            dormId   = Agreements.GetAll().Where(x => (x.person_id == _personId)).Select(x => x.dorm_id).SingleOrDefault();
        }
Exemplo n.º 2
0
        public bool PersonExists(RegistrationData registrationData)
        {
            int roomTypeId, dormId;

            roomTypeId = RoomTypes.GetRoomTypeId(registrationData.RoomType);
            dormId     = Dormitories.GetDormIdByName(registrationData.DormitoryName);
            int count = Persons.GetAll().Join(
                Agreements.GetAll(),
                p => p.id_person,
                a => a.person_id,
                (p, a) => new KeyValuePair <Person, Agreement>(p, a)).Where(
                x => (x.Key.surname == registrationData.Surname) &&
                (x.Key.name == registrationData.Name) &&
                (x.Key.is_living == true) &&
                (x.Value.room_id == roomTypeId) &&
                (x.Value.room_number == registrationData.RoomNumber) &&
                (x.Value.dorm_id == dormId)).Select(res => res.Key.id_person).ToList().Count();

            if (count == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 public IEnumerable <Person> GetPeopleLivingInRoom(int dormId, int room)
 {
     return(Persons.GetAll().Join(Agreements.GetAll(),
                                  person => person.id_person,
                                  agreement => agreement.person_id,
                                  (person, agreement) => new KeyValuePair <Person, Agreement>(person, agreement)
                                  ).Where(res => res.Key.is_living == true && (res.Value.room_number == room) && (res.Value.dorm_id == dormId)
                                          ).Select(res => res.Key).ToList());
 }
Exemplo n.º 4
0
        public AccountData GetSuitableTariff(int person_id, int dormId)
        {
            try
            {
                bool    is_student, on_budget;
                bool?   on_budgetNull;
                int     roomId;
                decimal amount, price;

                is_student = Persons.GetAll()
                             .Where(per => per.id_person == person_id)
                             .Select(per => per.is_student)
                             .ToList().Last();

                on_budgetNull = Persons.GetAll()
                                .Where(per => per.id_person == person_id)
                                .Select(per => per.on_budget)
                                .ToList()
                                .Last();

                on_budget = on_budgetNull.HasValue ? on_budgetNull.Value : false;

                roomId = Agreements.GetAll()
                         .Where(
                    agr => (agr.person_id == person_id) && (agr.dorm_id == dormId) && (agr.is_active == true))
                         .Select(agr => agr.room_id)
                         .ToList()
                         .Last();

                price = Prices.GetAll()
                        .Where(
                    p => (p.is_student == is_student &&
                          p.on_budget == on_budget && p.is_active == true &&
                          p.dorm_id == dormId && p.room_id == roomId)).
                        Select(p => p.price)
                        .ToList()
                        .Last();

                amount = Accounts.GetAll()
                         .Where(account => account.id_person == person_id)
                         .Select(account => account.sum)
                         .ToList()
                         .Last();

                return(new AccountData
                {
                    IsStudent = is_student,
                    IsBudget = on_budget,
                    AccountAmount = amount,
                    PricePerMonth = price
                });
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); return(new AccountData()); }
        }
Exemplo n.º 5
0
        public void MovePersonOut(PersonData person, string admin_name, int dorm_id)
        {
            Persons.GetAll().Where(p => p.id_person == GetPersonId(person)).ToList().ForEach(x => { x.is_living = false; });
            Agreements.GetAll().Where(a => a.person_id == GetPersonId(person)).ToList().ForEach(x => { x.is_active = false; });

            History.Add(new History
            {
                admin_name  = admin_name,
                dorm_id     = dorm_id,
                description = person.SurName + " " + person.Name + " " + "выселен(-а) из " + person.Room,
                moveOutFlag = true
            });
        }
Exemplo n.º 6
0
 public string GetRoomType(int person_id)
 {
     try
     {
         return(RoomTypes.GetAll().Join(
                    Agreements.GetAll(),
                    r => r.id_type,
                    a => a.room_id,
                    (r, a) => new KeyValuePair <RoomType, Agreement>(r, a))
                .Where(res => res.Value.person_id == person_id)
                .Select(res => res.Key.name).ToList().Last());
     }
     catch { return("..."); }
 }
Exemplo n.º 7
0
        public string GetRoomGender(int dormId, int roomNumber, int roomTypeId)
        {
            List <bool> isMale;

            isMale = Persons.GetAll()
                     .Join(
                Agreements.GetAll(),
                person => person.id_person,
                agreement => agreement.person_id,
                (person, agreement) => new KeyValuePair <Person, Agreement>(person, agreement)
                )
                     .Where(res =>
                            (res.Key.is_living == true) && (res.Value.room_id == roomTypeId) &&
                            (res.Value.is_active == true) && (res.Value.room_number == roomNumber) &&
                            (res.Value.dorm_id == dormId))
                     .Select(res => res.Key.is_male)
                     .ToList();
            if (isMale.Count != 0)
            {
                bool first = isMale.First(); //true, if there is a man in room
                bool q     = true;           //true, if all the elements the same
                foreach (bool item in isMale)
                {
                    if (item != first)
                    {
                        q = false;
                        break;
                    }
                }

                if (!q)
                {
                    return("М/Ж");
                }
                else if (first)
                {
                    return("М");
                }
                else
                {
                    return("Ж");
                }
            }
            else
            {
                return("-");
            }
        }
Exemplo n.º 8
0
 public IEnumerable <int> GetLivingRooms(int floor, int dormId)
 {
     return
         (Persons.GetAll()
          .Join(
              Agreements.GetAll(),
              person => person.id_person,
              agreement => agreement.person_id,
              (person, agreement) => new KeyValuePair <Person, Agreement>(person, agreement)
              )
          .Where(res =>
                 (res.Key.is_living == true) && (res.Value.floor_number == floor) &&
                 (res.Value.is_active == true) && (res.Value.dorm_id == dormId))
          .Select(res => res.Value.room_number)
          .Distinct()
          .ToList());
 }
Exemplo n.º 9
0
 public int GetPersonId(PersonData person)
 {
     try
     {
         return(Persons.GetAll().Join(
                    Agreements.GetAll(),
                    p => p.id_person,
                    a => a.person_id,
                    (p, a) => new KeyValuePair <Person, Agreement>(p, a)).Where(
                    x => (x.Key.surname == person.SurName) &&
                    (x.Key.name == person.Name) &&
                    (x.Key.is_living == true) &&
                    (x.Value.room_number == person.Room) &&
                    (x.Value.dorm_id == person.DormID)).Select(res => res.Key.id_person).ToList().SingleOrDefault());
     }
     catch { return(0); }
 }
Exemplo n.º 10
0
        public void ChangeRoom(PersonData person, NewPlace place, string admin_name, int dorm_id)
        {
            Agreements.GetAll().Where(a => a.person_id == GetPersonId(person)).ToList().
            ForEach(x =>
            {
                x.floor_number = place.NewFloor;
                x.room_number  = place.NewRoom;
                x.room_id      = place.NewRoomTypeId;
            });

            History.Add(
                new History
            {
                admin_name  = admin_name,
                dorm_id     = dorm_id,
                description = person.SurName + " " + person.Name + " " + "переехал(-а) из " + person.Room
                              + " в " + place.NewRoom,
                changeRoomFlag = true
            });
        }
Exemplo n.º 11
0
 public PersonData GetPersonDataById(int personId)
 {
     try
     {
         return(new PersonData
         {
             Name = Persons.GetAll().Where(x => x.id_person == personId).Select(x => x.name).LastOrDefault(),
             SurName = Persons.GetAll().Where(x => x.id_person == personId).Select(x => x.surname).LastOrDefault(),
             DormID = Agreements.GetAll().Where(x => x.person_id == personId).Select(x => x.dorm_id).LastOrDefault(),
             Room = Agreements.GetAll().Where(x => x.person_id == personId).Select(x => x.room_number).LastOrDefault(),
             RoomType = Agreements.GetAll().Where(x => x.person_id == personId).Select(x => x.room_id).LastOrDefault(),
             Floor = Agreements.GetAll().Where(x => x.person_id == personId).Select(x => x.floor_number).LastOrDefault()
         });
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         return(new PersonData {
         });
     }
 }
Exemplo n.º 12
0
 public bool DebitAccount(int dormId, int floor, string Admin)
 {
     try
     {
         List <int> personIds = Persons.GetAll().Join(
             Agreements.GetAll(),
             person => person.id_person,
             agreement => agreement.person_id,
             (person, agreement) => new KeyValuePair <Person, Agreement>(person, agreement))
                                .Where(res => (res.Value.is_active == true) && (res.Value.dorm_id == dormId) &&
                                       (res.Value.floor_number == floor) && (res.Key.is_living == true))
                                .Select(res => res.Key.id_person)
                                .ToList();
         foreach (var personId in personIds)
         {
             Accounts.GetAll().
             Where(ac => ac.id_person == personId).
             Select(ac => ac).
             ToList().
             ForEach(ac => ac.sum -= GetSuitableTariff(personId, dormId).PricePerMonth);
         }
         History.Add(new History
         {
             admin_name       = Admin,
             debitAccountFlag = true,
             dorm_id          = dormId,
             description      = DateTime.Now.Date.ToShortDateString() +
                                ". Списание со счетов суммы, должной к уплате, проживающих " + floor + " этажа"
         });
         return(true);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         return(false);
     }
 }