Esempio n. 1
0
 public List <Guid> GetAllPeopleID()
 {
     using (var context = new UniBinderEF())
     {
         return(context.People.Select(x => x.ID).ToList());
     }
 }
Esempio n. 2
0
 public int PeopleNumber()
 {
     using (var context = new UniBinderEF())
     {
         return((from people in context.People select people).Count());
     }
 }
Esempio n. 3
0
 public List <string> SubjectList()
 {
     using (var context = new UniBinderEF())
     {
         return(context.Subjects.Select(x => x.Name).ToList());
     }
 }
Esempio n. 4
0
 public List <PersonSubject> PersonSubjects()
 {
     using (var context = new UniBinderEF())
     {
         var personSubjects = (from x in context.PersonSubjects select x).ToList();
         return(personSubjects);
     }
 }
Esempio n. 5
0
 public void RemoveMatch(Guid id2)
 {
     using (var context = new UniBinderEF())
     {
         var match = context.MatchedPeoples.Where(x => x.SecondPersonID == id2).FirstOrDefault();
         context.Entry(match).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
Esempio n. 6
0
 public List <string> SubjectsPersonHas(Guid personID)
 {
     using (var context = new UniBinderEF())
     {
         var subjects = context.PersonSubjects.Where(subject => subject.PersonID == personID)
                        .Select(subject => subject.Name).ToList();
         return(subjects);
     }
 }
Esempio n. 7
0
 public Person GetPeopleByID(Guid guid)
 {
     //List<Person> people = new List<Person>();
     using (var context = new UniBinderEF())
     {
         var person = context.People.Where(x => x.ID == guid).FirstOrDefault();
         return(person);
     }
 }
Esempio n. 8
0
 public void AddNewMatch(Guid victimID, string checkID)
 {
     using (var context = new UniBinderEF())
     {
         context.MatchedPeoples.Add(new MatchedPeople {
             FirstPersonID = new Guid(checkID), SecondPersonID = victimID, Id = Guid.NewGuid()
         });
         context.SaveChanges();
     }
 }
Esempio n. 9
0
 private void AddSubjects(PersonSubject personSubject)
 {
     using (var context = new UniBinderEF())
     {
         if (!context.PersonSubjects.ToList().Exists(x => x.PersonID == personSubject.PersonID && x.Name == personSubject.Name))
         {
             context.PersonSubjects.Add(personSubject);
             context.SaveChanges();
         }
     }
 }
Esempio n. 10
0
        public List <Guid?> MatchList(Guid userID)
        {
            var matches = new List <Guid?>();

            using (var context = new UniBinderEF())
            {
                var allMatches = context.MatchedPeoples.Where(match => match.FirstPersonID == userID).Select(match => match.SecondPersonID).ToList();
                matches = allMatches;
                return(matches);
            }
        }
Esempio n. 11
0
        public IEnumerable PeopleWithSameSubjects(Guid personID)
        {
            var IDMatchedBySubjects = new List <Guid?>();
            var matches             = MatchList(personID);

            using (var context = new UniBinderEF())
            {
                var subjects = context.PersonSubjects.Where(personSubject => personSubject.PersonID == personID)
                               .Select(personSubject => personSubject.Name).ToList();

                var query = (from c in context.People
                             join b in context.PersonSubjects on new { ID = c.ID } equals new { ID = b.PersonID }
                             where
                             c.ID != new Guid(personID.ToString()) &&
                             (from PersonSubjects in context.PersonSubjects
                              where
                              PersonSubjects.PersonID == new Guid(personID.ToString())
                              select new
                {
                    PersonSubjects.Name
                }).Contains(new { Name = b.Name }) &&
                             !
                             (from x in context.MatchedPeoples
                              join z in context.People on new { FirstPersonID = (Guid)x.FirstPersonID } equals new { FirstPersonID = z.ID }
                              where
                              x.FirstPersonID == z.ID
                              select new
                {
                    x.SecondPersonID
                }).Contains(new { SecondPersonID = (Guid?)c.ID })
                             select new
                {
                    c.ID
                }).Distinct().ToList();

                if (!subjects.Any())
                {
                    return(null);
                }
                IEnumerable ts = query;
                return(ts);
                //foreach (var subjectName in subjects)
                //{
                //    var PeopleWithSameSubject = context.PersonSubjects.Where(personSubject => personSubject.Name == subjectName && personSubject.PersonID != personID)
                //                                                      .Select(personSubject => personSubject.PersonID).ToList();
                //    foreach (var item in PeopleWithSameSubject)
                //    {
                //        if (IDMatchedBySubjects.Contains(item) || matches.Contains(item)) continue;
                //        IDMatchedBySubjects.Add(item);
                //    }
                //}
            }
        }
Esempio n. 12
0
        public IHttpActionResult UpdateUser([FromBody] Person updatedUser)
        {
            if (updatedUser == null)
            {
                return(BadRequest());
            }
            var currentUser = GetCurrentUser(updatedUser);

            if (currentUser == null)
            {
                return(NotFound());
            }

            Person user = new Person()
            {
                Name    = updatedUser.Name, Password = updatedUser.Password,
                Surname = updatedUser.Surname, Email = updatedUser.Email, ID = updatedUser.ID, SubjectList = updatedUser.SubjectList
            };


            if (user.SubjectList == null)
            {
                using (var db = new UniBinderEF())
                {
                    db.People.Attach(user);
                    if (user.Password != null)
                    {
                        db.Entry(user).Property(x => x.Password).IsModified = true;
                    }
                    db.Entry(user).Property(x => x.Name).IsModified    = true;
                    db.Entry(user).Property(x => x.Surname).IsModified = true;
                    db.Entry(user).Property(x => x.Email).IsModified   = true;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(BadRequest());
                    }
                }
                return(Ok());
            }

            else
            {
                userDataInserter.LinkSubjectsToPersonDataTable(user);
                //userDataInserter.LinkSubjectsToPersonWithDel(user); //slower by 1.5 sec
                return(Ok());
            }
        }
Esempio n. 13
0
 public IHttpActionResult Registration(Person person)
 {
     using (var context = new UniBinderEF())
     {
         var people = context.People.ToList();
         if (people.Exists(x => x.Username.Equals(person.Username, StringComparison.InvariantCultureIgnoreCase)))
         {
             return(BadRequest());
         }
         if (people.Exists(x => x.Email.Equals(person.Email, StringComparison.InvariantCultureIgnoreCase)))
         {
             return(Conflict());
         }
         //CreateUniqueId(person);
         //userDataInserter.LinkSubjectsToPerson(person);
         return(AddToDB(person));
     }
 }
Esempio n. 14
0
        public IHttpActionResult CheckUniqueData(string username, string email)
        {
            using (var context = new UniBinderEF())
            {
                var people = context.People.ToList();
                if (people.Exists(x => x.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(BadRequest());
                }

                var checkEmail = people.Where(x => x.Email.ToLower() == email.ToLower()).FirstOrDefault();
                if (checkEmail != null)
                {
                    return(Conflict());
                }
                //if (people.Exists(x => x.Email.Equals(email, StringComparison.InvariantCultureIgnoreCase))) return Conflict();
                return(Ok());
            }
        }
Esempio n. 15
0
        public bool UpdatePersonInfo(Person p)
        {
            using (var context = new UniBinderEF())
            {
                var person = context.People.SingleOrDefault(x => x.ID == p.ID);
                if (person != null)
                {
                    person.ImageLink   = p.ImageLink;
                    person.Name        = p.Name;
                    person.Surname     = p.Surname;
                    person.Username    = p.Username;
                    person.Age         = p.Age;
                    person.SubjectList = p.SubjectList;

                    LinkSubjectsToPersonWithDel(person);
                    context.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 16
0
        public List <Person> ReadUserData()
        {
            List <Person> PersonList = new List <Person>();

            using (var context = new UniBinderEF())
            {
                var users         = (from a in context.People select a).ToList();
                var usersSubjects = (from a in context.PersonSubjects select a).ToList();
                var matchedPeople = (from a in context.MatchedPeoples select a).ToList();

                var groupJoin = users.GroupJoin(usersSubjects,
                                                person =>
                {
                    if (person is null)
                    {
                        throw new ArgumentNullException(nameof(person));
                    }

                    return(person.ID);
                },
                                                sub => sub.PersonID,
                                                (person, subjectGroup) => new
                {
                    subjectsList = subjectGroup,
                    person.ID,
                    person.Username,
                    person.Password,
                    person.Name,
                    person.Surname,
                    person.Email,
                    person.Role,
                    person.Likes,
                    person.Dislikes,
                    person.ImageLink,
                });

                foreach (var p in groupJoin)
                {
                    var person = new Person
                    {
                        ID          = p.ID,
                        Username    = p.Username,
                        Password    = p.Password,
                        Name        = p.Name,
                        Surname     = p.Surname,
                        Email       = p.Email,
                        Role        = p.Role,
                        Likes       = p.Likes,
                        Dislikes    = p.Dislikes,
                        ImageLink   = p.ImageLink,
                        SubjectList = new List <Subject>()
                    };

                    foreach (var sub in p.subjectsList)
                    {
                        var subject = new Subject
                        {
                            Name = sub.Name
                        };
                        person.SubjectList.Add(subject);
                    }

                    foreach (var per in PersonList)
                    {
                        per.Matches = (from a in matchedPeople
                                       where per.ID.Equals(a.FirstPersonID) || per.ID.Equals(a.SecondPersonID)
                                       select(Guid) a.SecondPersonID).ToList();
                    }

                    PersonList.Add(person);
                }
            }
            return(PersonList);
        }
Esempio n. 17
0
 public PersonRepository()
 {
     _dbContext = new UniBinderEF();
 }