Example #1
0
        public long Create(NewFormViewModel data)
        {
            var parentFolder = dbContext.Files
                               .Where(x => x.FormId == null)
                               .SingleOrDefault(x => x.Id == data.ParentId);
            var parentFolderIsRoot = data.ParentId == 0;

            if (parentFolder == null && parentFolderIsRoot == false)
            {
                var existError = new Exception("Folder 'Rodzic' nie istnieje");
                throw existError;
            }

            if (string.IsNullOrWhiteSpace(data.Name))
            {
                var nameError = new Exception("Nazwa nie może być pusta");
                throw nameError;
            }

            var newFile = new File
            {
                ParentId = data.ParentId == 0 ? null : data.ParentId,
                Name     = data.Name,
                Form     = new Form()
            };

            dbContext.Files.Add(newFile);
            dbContext.SaveChanges();

            return(newFile.Form.Id);
        }
Example #2
0
 public void Setup()
 {
     _pageService = new Mock <IPageService>();
     _dialog      = new Mock <IUserDialogs>();
     _form        = new NewFormViewModel(_dialog.Object, _pageService.Object);
     viewModel    = new NewDiscursiveQuestionViewModel(_pageService.Object, _dialog.Object, _form);
 }
Example #3
0
        public ActionResult Create(NewFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var vm = new NewFormViewModel
                {
                    MembershipTypes = _context.membershipTypes.ToList()
                };
                return(View("create", vm));
            }

            if (viewModel.Id <= 0)
            {
                var customer = new Customer
                {
                    DateOfBirth      = viewModel.DateOfBirth,
                    IsSubcribed      = viewModel.IsSubcribed,
                    MembershipTypeId = viewModel.membershipTypesId,
                    Name             = viewModel.FirstName + " " + viewModel.LastName
                };
                _context.Customer.Add(customer);
                _context.SaveChanges();
            }
            else
            {
                var edit = _context.Customer.Single(c => c.Id == viewModel.Id);
                edit.IsSubcribed      = viewModel.IsSubcribed;
                edit.MembershipTypeId = viewModel.membershipTypesId;
                edit.Name             = viewModel.FirstName + " " + viewModel.LastName;
                edit.DateOfBirth      = viewModel.DateOfBirth;
                _context.SaveChanges();
            }
            return(RedirectToAction("custIndex"));
        }
Example #4
0
        public async Task <FormObjectViewModel> CreateForm(NewFormViewModel form)
        {
            ObjectId formId = ObjectId.GenerateNewId();
            List <FieldViewModel> fields = new List <FieldViewModel>();

            foreach (var field in form.fields)
            {
                string fieldType = field.fieldType;
                if (!TypeConstants.IsValidFieldType(fieldType))
                {
                    throw new Exception("Invalid Field Type");
                }

                FieldViewModel fieldViewModel = new FieldViewModel
                {
                    Id        = ObjectId.GenerateNewId(),
                    formId    = formId,
                    fieldType = field.fieldType,
                    index     = field.index,
                    title     = field.title,
                    createdAt = DateTime.UtcNow
                };

                if (fieldType == TypeConstants.CHECKBOX_INPUT || fieldType == TypeConstants.DROP_DOWN_INPUT ||
                    fieldType == TypeConstants.RADIO_INPUT)
                {
                    var values = Constants.ConvertJsonObject(field.value);
                    fieldViewModel.value = values;
                }
                else
                {
                    fieldViewModel.value = field.value;
                }

                fields.Add(fieldViewModel);
            }

            if (fields.Count != 0)
            {
                await fieldCollection.InsertManyAsync(fields);
            }

            IEnumerable <ObjectId> fieldIds = from _ in fields
                                              select _.Id;

            FormViewModel formViewModel = new FormViewModel
            {
                Id        = formId,
                createdAt = DateTime.UtcNow,
                createdBy = form.createdBy,
                formTitle = form.title,
                fields    = fieldIds.ToList()
            };

            await formCollection.InsertOneAsync(formViewModel);

            return(FormUtils.CombineFormAndFields(formViewModel, fields));
        }
Example #5
0
 public NewMultipleQuestionPage(bool option, NewFormViewModel formViewModel)
 {
     _viewModel = new NewMultipleQuestionViewModel(option,
                                                   new PageService(),
                                                   UserDialogs.Instance,
                                                   formViewModel);
     BindingContext = _viewModel;
     InitializeComponent();
 }
Example #6
0
        public ActionResult Create()
        {
            var vm = new NewFormViewModel
            {
                MembershipTypes = _context.membershipTypes.ToList()
            };

            return(View(vm));
        }
Example #7
0
        public IActionResult Create(NewFormViewModel data)
        {
            var errorId = "NewForm";

            if (data.ParentId == -1)
            {
                return(RedirectToAction("Index", "Home", new { errorId, errorMsg = "Wybierz rodzica" }));
            }

            try
            {
                var newFormId = formService.Create(data);
                return(RedirectToAction("Edit", new { id = newFormId, instantEdit = true }));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index", "Home", new { errorId, errorMsg = e.Message }));
            }
        }
Example #8
0
        public ActionResult Edit(int id)
        {
            var customer = _context.Customer.Single(c => c.Id == id);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            ;
            var cust = customer.Name.Split(' ');
            var vm   = new NewFormViewModel
            {
                MembershipTypes   = _context.membershipTypes.ToList(),
                LastName          = cust[1],
                FirstName         = cust[0],
                DateOfBirth       = customer.DateOfBirth,
                IsSubcribed       = customer.IsSubcribed,
                membershipTypesId = customer.MembershipTypeId
            };

            return(View("create", vm));
        }
Example #9
0
 public void Setup()
 {
     _pageService = new Mock <IPageService>();
     _dialog      = new Mock <IUserDialogs>();
     viewModel    = new NewFormViewModel(_dialog.Object, _pageService.Object);
 }
Example #10
0
 public NewFormPage()
 {
     InitializeComponent();
     BindingContext = new NewFormViewModel(UserDialogs.Instance, new PageService());
 }
Example #11
0
        public void SetUp()
        {
            _pageService = new Mock <IPageService>();
            _dialog      = new Mock <IUserDialogs>();
            _form        = new NewFormViewModel(_dialog.Object, _pageService.Object);
            _formAnswer  = new ForumDEG.Models.FormAnswer {
                CoordinatorId     = "12345678",
                FormId            = "0001",
                DiscursiveAnswers = new List <ForumDEG.Models.DiscursiveQuestion> {
                    new ForumDEG.Models.DiscursiveQuestion {
                        Question = "Questão Discursiva",
                        Answer   = "Resposta Discursiva"
                    }
                },
                MultipleChoiceAnswers = new List <ForumDEG.Models.MultipleChoiceAnswer> {
                    new ForumDEG.Models.MultipleChoiceAnswer {
                        Question = "Questão Múltipla",
                        Answers  = new List <string> {
                            "Opção 1", "Opção 2"
                        }
                    }
                }
            };

            discursive = new List <ForumDEG.Models.DiscursiveQuestion>();
            discursive.Add(new ForumDEG.Models.DiscursiveQuestion {
                Question = "Chama, chama, chama"
            });

            multipleChoice = new List <ForumDEG.Models.MultipleChoiceQuestion>();
            multipleChoice.Add(new ForumDEG.Models.MultipleChoiceQuestion("Funcionaaa", false)
            {
                new ForumDEG.Models.Option {
                    OptionText = "fun"
                },
                new ForumDEG.Models.Option {
                    OptionText = "ci"
                },
                new ForumDEG.Models.Option {
                    OptionText = "o"
                },
                new ForumDEG.Models.Option {
                    OptionText = "na"
                },
            });
            multipleChoice.Add(new ForumDEG.Models.MultipleChoiceQuestion("lalala", true)
            {
                new ForumDEG.Models.Option {
                    OptionText = "uma"
                },
                new ForumDEG.Models.Option {
                    OptionText = "duas"
                },
            });

            _form.Title = "Titulo";
            _question1  = new QuestionDetailViewModel {
                Title           = "pergunta1",
                MultipleAnswers = true
            };
            _question1.Options.Add("reposta1");
            _question1.Options.Add("reposta2");

            _question2 = new QuestionDetailViewModel {
                Title           = "pergunta2",
                MultipleAnswers = false
            };
            _question2.Options.Add("reposta1");
            _question2.Options.Add("reposta2");
            _form.MultipleChoiceQuestions.Add(_question1);
            _form.MultipleChoiceQuestions.Add(_question2);

            _form.DiscursiveQuestionsTitles.Add("Chama, chama, chama");
        }
Example #12
0
        public async Task <object> CreateFormBenchmark([FromQuery] string fieldCount, [FromQuery] string totalForms)
        {
            bool isValidFieldCount = int.TryParse(fieldCount, out int fieldCountValue);

            if (!isValidFieldCount)
            {
                return(BadRequest(new
                {
                    success = false,
                    message = "Invalid Field Count"
                }));
            }

            bool isValidTotalForms = int.TryParse(totalForms, out int totalFormsValue);

            if (!isValidTotalForms)
            {
                totalFormsValue = 1;
            }

            List <FormBenchmarkModel> forms = new List <FormBenchmarkModel>();
            Stopwatch watch;
            long      totalTime = 0;

            try
            {
                for (int i = 0; i < totalFormsValue; i++)
                {
                    NewFormViewModel newForm = formGenerator.GenerateRandomForm(fieldCountValue);
                    watch = Stopwatch.StartNew();

                    FormResponseModel formResponse = await $"{Constants.BASE_URL}"
                                                     .AppendPathSegment("form")
                                                     .PostJsonAsync(newForm)
                                                     .ReceiveJson <FormResponseModel>();

                    watch.Stop();

                    forms.Add(new FormBenchmarkModel
                    {
                        formId      = formResponse.form.Id,
                        timeElapsed = watch.ElapsedMilliseconds
                    });
                    totalTime += watch.ElapsedMilliseconds;
                }

                return(Ok(new
                {
                    success = true,
                    totalFormsCreated = forms.Count,
                    totalTime,
                    averageTime = totalTime / forms.Count,
                    forms
                }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new JsonResult(new
                {
                    success = false,
                    totalFormsCreated = forms.Count,
                    forms,
                    message = e.Message
                }));
            }
        }
Example #13
0
 public NewDiscursiveQuestionPage(NewFormViewModel formViewModel)
 {
     _viewModel     = new NewDiscursiveQuestionViewModel(new PageService(), UserDialogs.Instance, formViewModel);
     BindingContext = _viewModel;
     InitializeComponent();
 }