Beispiel #1
0
        public List<FormDTO> GetUserForms(string username)
        {
            //returnez toate formurile unui user
            int userID = _dataAccess.UserRepository.FindFirstBy(user => user.Username == username).UserID;
            List<Form> formList = _dataAccess.FormRepository.FindAllBy(form => form.UserID == userID).ToList();
            List<FormDTO> formDtoList = new List<FormDTO>();
            FormDTO formDTO;

            foreach (Form f in formList)
            {
                formDTO = new FormDTO();
                formDTO.Title = f.Title;
                formDTO.State = f.State;
                formDTO.CreatedDate = f.CreatedDate.ToString();
                formDTO.Deadline = f.Deadline.ToString();
                formDTO.Category = _dataAccess.CategoryRepository.FindFirstBy(category => category.CategoryID == f.CategoryID).Name;
                formDTO.Username = _dataAccess.UserRepository.FindFirstBy(user => user.UserID == f.UserID).Username;
                formDTO.Id = f.FormID;
                formDtoList.Add(formDTO);
            }

            return formDtoList;
        }
Beispiel #2
0
        public List<FormDTO> GetVotedForms(string username)
        {
            //returneaza toate formurile votate de catre un user
            int userID = _dataAccess.UserRepository.FindFirstBy(user => user.Username == username).UserID;
            List<Form> formList=new List<Form>();
            List<VotedForms> votedFormsList = _dataAccess.VotedFormsRepository.FindAllBy(voted=>voted.UserID == userID).ToList();
            List<FormDTO> formDtoList = new List<FormDTO>();
            FormDTO formDTO;
            Form form;

            foreach (VotedForms votedForm in votedFormsList)
            {
                form = _dataAccess.FormRepository.FindFirstBy(f => f.FormID == votedForm.FormID);
                formList.Add(form);
            }

            foreach (Form f in formList)
            {
                formDTO = new FormDTO();
                formDTO.Title = f.Title;
                formDTO.State = f.State;
                formDTO.CreatedDate = f.CreatedDate.ToString();
                formDTO.Deadline = f.Deadline.ToString();
                formDTO.Category = _dataAccess.CategoryRepository.FindFirstBy(category => category.CategoryID == f.CategoryID).Name;
                formDTO.Username = _dataAccess.UserRepository.FindFirstBy(user => user.UserID == f.UserID).Username;
                formDTO.Id = f.FormID;
                formDTO.Voted = true;

                formDtoList.Add(formDTO);
            }

            return formDtoList;
        }
Beispiel #3
0
        public List<FormDTO> GetCategoryForms(int categoryID, string token)
        {
            //returneaza toate formurile dintr-o categorie
            List<Form> formList = _dataAccess.FormRepository.FindAllBy(f=>f.CategoryID == categoryID).ToList();
            List<FormDTO> formDtoList = new List<FormDTO>();
            FormDTO formDTO;

            int userID = _dataAccess.TokenRepository.FindFirstBy(user => user.TokenString == token).UserID;

            foreach (Form f in formList)
            {
                formDTO = new FormDTO();
                formDTO.Title = f.Title;
                formDTO.State = f.State;
                formDTO.CreatedDate = f.CreatedDate.ToString();
                formDTO.Deadline = f.Deadline.ToString();
                formDTO.Category = _dataAccess.CategoryRepository.FindFirstBy(category => category.CategoryID == f.CategoryID).Name;
                formDTO.Username = _dataAccess.UserRepository.FindFirstBy(user => user.UserID == f.UserID).Username;
                formDTO.Id = f.FormID;
                formDTO.Voted = true;

                try
                {
                    userID = _dataAccess.VotedFormsRepository.FindFirstBy(voted => voted.FormID == f.FormID && voted.UserID == userID).UserID;
                }
                catch
                {
                    //daca userul a votat sondajul deja, nu il va mai putea vota
                    formDTO.Voted = false;
                }

                formDtoList.Add(formDTO);
            }

            return formDtoList;
        }