Пример #1
0
        public void JoinTeam(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Join/Team/", "").Split('/');
            int      teamId     = int.Parse(parameters[0]);
            string   token      = parameters[1];


            var session = SessionManager.GetSession(token);

            var personDTO = RESTHelper.GetObject <PersonDTO>(context);

            if (session.user.People.Any(p => p.PersonId == personDTO.Id))
            {
                UnitOfWork unit = new UnitOfWork(session.context);

                var team   = unit.Teams.GetTeamWithMembers(teamId);
                var person = unit.People.Get(personDTO.Id.Value);

                if (team != null && !team.Members.Any(m => m.Id == person.Id))
                {
                    team.Members.Add(person);
                    unit.Complete();
                }



                MyResponder.RespondJson(context, team.ToDTO());
            }
        }
Пример #2
0
        public void GetChallengesForPatron(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/ChallengesForPatron/", "").Split('/');

            int    patronId = int.Parse(parameters[0]);
            int    personId = int.Parse(parameters[1]);
            string token    = parameters[2];


            var session = SessionManager.GetSession(token);

            session.context = new ProbnikContext();

            var result = new List <ChallengeDTO>();

            if (session.user.People.Any(p => p.Id == personId && p.ConnectionType == ConnectionType.PersonToOwner))
            {
                var unit = new UnitOfWork(session.context);
                if (unit.Patrons.Find(p => p.Person.Id == personId).Count() > 0)
                {
                    var patron     = unit.Patrons.GetPatronWithPerson(patronId);
                    var challenges = unit.Challanges.GetChallengesForPatron(patronId);
                    foreach (var challenge in challenges)
                    {
//                        challenge.Patron = patron;
                        result.Add(challenge.ToChallengeDTO());
                    }
                }
            }

            MyResponder.RespondJson(context, result);
        }
Пример #3
0
        public void GetMainPersonForUser(HttpListenerContext context)
        {
            string token   = context.Request.RawUrl.Replace("/Get/Person/", "");
            var    session = SessionManager.GetSession(token);

            UnitOfWork unit = new UnitOfWork(session.context);
            var        user = unit.Users.GetUserWithPeople(session.user.Id.Value);

            var conn = user.People.FirstOrDefault(c => c.ConnectionType == ConnectionType.PersonToOwner);

            if (conn == null)
            {
                var p   = new Person();
                var upc = new UserToPersonConnection();
                upc.Person         = p;
                upc.User           = user;
                upc.ConnectionType = ConnectionType.PersonToOwner;
                p.Users.Add(upc);

                unit.People.Add(p);
                unit.Complete();

                user = unit.Users.GetUserWithPeople(session.user.Id.Value);
                conn = user.People.FirstOrDefault(c => c.ConnectionType == ConnectionType.PersonToOwner);
            }


            var person    = unit.People.Get(conn.PersonId);
            var personDTO = person.ToPersonDTO();

            MyResponder.RespondJson(context, personDTO);
        }
Пример #4
0
        public void GetChallengesForTeam(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/Challenges/", "").Split('/');

            int    teamId = int.Parse(parameters[0]);
            string token  = parameters[1];

            var session = SessionManager.GetSession(token);

            var unit = new UnitOfWork(session.context);

            var team = unit.Teams.GetTeamWithMethodologies(teamId);


            var result = new List <ChallengeTypeDTO>();

            foreach (var methodology in team.Methodologies)
            {
                var challenges = unit.ChallangeTypes.GetChallangeTypesForMethodology(methodology.Id.Value);
                foreach (var challangeType in challenges)
                {
                    result.Add(challangeType.ToChallengeTypeDTO());
                }
            }

            MyResponder.RespondJson(context, result);
        }
Пример #5
0
        public void GetAllMethodologies(HttpListenerContext context)
        {
            string token   = context.Request.RawUrl.Replace("/Get/Methodologies/", "");
            var    session = SessionManager.GetSession(token);

            var methodologies = session.context.Methodologies.ToList();

            MyResponder.RespondJson(context, methodologies);
        }
Пример #6
0
        public void Login(HttpListenerContext context)
        {
            Console.WriteLine("URL: {0}", context.Request.RawUrl);

            var     userDTO = RESTHelper.GetObject <UserDTO>(context);
            Session session = new Session(userDTO.Login, userDTO.Password);

            var respondObject = new UserDTO(session.user);

            MyResponder.RespondJson(context, respondObject);
        }
Пример #7
0
        public void HandleGetGreetRequest(HttpListenerContext context)
        {
            Console.WriteLine("URL: {0}", context.Request.RawUrl);
            var user = new User();

            user.Login    = "******";
            user.Email    = "*****@*****.**";
            user.IsAdmin  = true;
            user.Password = "******";
            user.Id       = 1;



            var userDTO = new UserDTO(user);

            MyResponder.RespondJson(context, userDTO);
        }
Пример #8
0
        public void UpdatePerson(HttpListenerContext context)
        {
            string token = context.Request.RawUrl.Replace("/Update/Person/", "");


            var session = SessionManager.GetSession(token);

            var personDTO = RESTHelper.GetObject <PersonDTO>(context);


            UnitOfWork unit = new UnitOfWork(session.context);

            if (personDTO.Id != null)
            {
                var person = unit.People.Get(personDTO.Id.Value);
                person.Name        = personDTO.Name;
                person.Surname     = personDTO.Surname;
                person.PESEL       = personDTO.PESEL;
                person.DateOfBirth = personDTO.DateOfBirth;

                unit.Complete();

                MyResponder.RespondJson(context, personDTO);
            }
            else
            {
                var user   = session.user;
                var person = personDTO.ToPerson();
                person.OwnerID = user.Id.Value;

                unit.People.Add(person);
                session.context.SaveChanges();
                person = unit.People.Find(p => p.OwnerID == user.Id).FirstOrDefault();


                var connection = new UserToPersonConnection(user.Id.Value, person.Id.Value, ConnectionType.PersonToOwner);

                person.Users.Add(connection);
                user.People.Add(connection);

                unit.Complete();

                personDTO = person.ToPersonDTO();
                MyResponder.RespondJson(context, personDTO);
            }
        }
Пример #9
0
        public void GetAllChallengeTypes(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/AllChallenges/", "").Split('/');

            string token = parameters[0];

            var session = SessionManager.GetSession(token);

            var unit = new UnitOfWork(session.context);

            var result = new List <ChallengeTypeDTO>();

            var challenges = unit.ChallangeTypes.GetAll().ToList();

            foreach (var challangeType in challenges)
            {
                result.Add(challangeType.ToChallengeTypeDTO());
            }

            MyResponder.RespondJson(context, result);
        }
Пример #10
0
        public void GetUserTeams(HttpListenerContext context)
        {
            string token = context.Request.RawUrl.Replace("/Get/UserTeams/", "");

            var session = SessionManager.GetSession(token);

            var unit = new UnitOfWork(session.context);

            var personId = session.user.People.FirstOrDefault(p => p.ConnectionType == ConnectionType.PersonToOwner).Id;

            var person = unit.People.GetPersonWithTeams(personId.Value);
            var teams  = person.Teams.ToList();

            var result = new List <TeamDTO>();

            foreach (var team in teams)
            {
                result.Add(team.ToDTO());
            }

            MyResponder.RespondJson(context, result);
        }
Пример #11
0
        public void GetTeamsByMethodology(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/Teams/", "").Split('/');

            string token         = parameters[0];
            int    methodologyId = int.Parse(parameters[1]);

            var session = SessionManager.GetSession(token);

            var unit = new UnitOfWork(session.context);

            var teams = unit.Teams.FindTeamsWithMembersAndPatrons(t => t.Methodologies.Any(m => m.Id == methodologyId)).ToList();

            var result = new List <TeamDTO>();

            foreach (var team in teams)
            {
                result.Add(team.ToDTO());
            }

            MyResponder.RespondJson(context, result);
        }
Пример #12
0
        public void GetPatronForPerson(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/Patron/", "").Split('/');

            int    personId = int.Parse(parameters[0]);
            string token    = parameters[1];


            var session = SessionManager.GetSession(token);

            PatronDTO result = null;

            if (session.user.People.Any(p => p.Id == personId && p.ConnectionType == ConnectionType.PersonToOwner))
            {
                var unit   = new UnitOfWork(session.context);
                var patron = unit.Patrons.Find(p => p.Person.Id == personId).FirstOrDefault();

                result = patron != null?patron.ToPatronDTO() : null;
            }

            MyResponder.RespondJson(context, result);
        }
Пример #13
0
        public void GetChallengeForPerson(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Get/ChallengeFor/", "").Split('/');

            int    challengeTypeId = int.Parse(parameters[0]);
            int    personId        = int.Parse(parameters[1]);
            string token           = parameters[2];

            var session = SessionManager.GetSession(token);

            session.context = new ProbnikContext();

            var result = new List <ChallengeDTO>();



            if (session.user.People.Any(p => p.Id == personId))
            {
                var unit       = new UnitOfWork(session.context);
                var challenges = unit.Challanges.FindFull(c => c.Owner.Id == personId &&
                                                          c.Task.ChallangeTypeId == challengeTypeId).ToList();
                if (challenges.Count > 0)
                {
                    var patronId = challenges[0].PatronId;
                    if (patronId.HasValue)
                    {
                        unit.Patrons.GetPatronWithPerson(patronId.Value);
                    }
                    foreach (var challenge in challenges)
                    {
                        result.Add(challenge.ToChallengeDTO());
                    }
                }
            }

            MyResponder.RespondJson(context, result);
        }
Пример #14
0
        public void SaveChallenge(HttpListenerContext context)
        {
            string[] parameters = context.Request.RawUrl.Replace("/Save/Challenge/", "").Split('/');
            string   token      = parameters[0];


            var session = SessionManager.GetSession(token);

            var unit = new UnitOfWork(session.context);

            var personChallengesDTO = RESTHelper.GetObject <ChallengeDTO[]>(context).ToList();
            var ChallengeTypeId     = personChallengesDTO.First().Task.ChallangeTypeId;

            if (personChallengesDTO.All(c => c.Id.HasValue))
            {
                SaveChanges(session, unit, personChallengesDTO);
                MyResponder.RespondJson(context, personChallengesDTO);
            }
            else
            {
                var resultDTO = CreateChallenges(personChallengesDTO, unit);
                MyResponder.RespondJson(context, resultDTO);
            }
        }