Example #1
0
        public async Task <ActionResult <IEnumerable <AnswerModel> > > GetAnswers()
        {
            var answers = await _userFormDomain.Get();

            var a = answers.Select(answer => _mapper.Map <BLL.ViewModels.User_form, AnswerModel>(answer));

            return(Ok(a));
        }
        public async Task <IEnumerable <BLL.ViewModels.Form> > GetAnsweredForms()
        {
            var answeredForms = new List <BLL.ViewModels.Form>();
            var userId        = User.Claims.First(c => c.Type == "UserID").Value;
            var answers       = await _userFormDomain.Get(userId);

            foreach (var answer in answers)
            {
                var answerForm = await _formDomain.Get(answer.Form_id);

                if (answerForm != null)
                {
                    answeredForms.Add(answerForm);
                }
            }

            return(answeredForms);
        }
Example #3
0
        public async Task <ActionResult <List <string> > > Get(PostFormModel formModel)
        {
            if (string.IsNullOrEmpty(formModel.url) ||
                formModel.url.Length != 6)
            {
                return(BadRequest());
            }
            var form = await _form.Get(formModel.url);

            var uId  = User.Claims.First(c => c.Type == "UserID").Value;
            var user = await _user.GetId(uId);

            var uf = await _uf.Get(user.Id, form.Id);

            if (uf == null)
            {
                return(NotFound());
            }
            if (!uf.Can_edit)
            {
                return(BadRequest());
            }
            var str = new List <string> {
                form.Name, !form.Anonym ? "Public" : "Anonym", form.Jform
            };
            var answers = await _uf.Get(form.Id);

            foreach (var asnw in answers)
            {
                if (!form.Anonym)
                {
                    var u = await _user.GetId(asnw.User_id);

                    str.Add(u != null ? u.FullName : "");
                }

                str.Add(asnw.jsonAnswer);
            }

            return(str);
        }