Пример #1
0
        public ActionResult Overview(InspectionFormViewModel model, FormCollection formValues)
        {
            //QUESTION: Possible to remove FormCollection?

            try
            {
                Assignees temp;
                int       questionsAmount, answeredQuestionsAmount;

                using (UnitOfWork uow = new UnitOfWork())
                {
                    temp = uow.AssigneesRepository
                           .GetIncludes("InspectionForm.FormQuestion.Answer", x => x.UserId == (int)Session["userID"] && x.InspectionFormId == model.Id)
                           .FirstOrDefault();

                    questionsAmount = temp.InspectionForm.FormQuestion
                                      .Count();

                    answeredQuestionsAmount = temp.InspectionForm.FormQuestion
                                              .Where(question => question.Answer.Count() > 0)
                                              .Count();

                    if (questionsAmount == answeredQuestionsAmount)
                    {
                        temp.Completed = true;
                    }
                }
            }
            catch (Exception)
            {
                //
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        public ActionResult Update(InspectionFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Organization   = _context.Organizations.ToList();
                viewModel.InspectionType = _context.PostingTypes.ToList();
                return(View("InspectionForm", viewModel));
            }
            var userId     = User.Identity.GetUserId();
            var inspection = _context.Inspections.Single(i => i.Id == viewModel.Id && i.User.Id == userId);

            inspection.OrganizationId   = viewModel.OrganizationId;
            inspection.InspectionTypeId = viewModel.InspectionTypeId;
            inspection.DateTime         = viewModel.GetDateTime();
            inspection.Description      = viewModel.Description;

            var notification = Notification.InspectionUpdated(inspection);

            var users = _context.Users.Where(u => u.OrganizationId == inspection.OrganizationId).ToList();

            foreach (var user in users)
            {
                user.Notify(notification);
            }

            _context.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
Пример #3
0
        public ActionResult Overview(InspectionFormViewModel model)
        {
            if (Session["userID"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }

            if (model.Id == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            InspectionForm temp, answers;

            using (UnitOfWork uow = new UnitOfWork())
            {
                temp = uow.InspectionFormRepository
                       .GetIncludes("FormQuestion.Answer", u => u.Id == model.Id)
                       .FirstOrDefault();

                answers = uow.InspectionFormRepository
                          .GetIncludes("FormQuestion.Answer", u => u.Id == model.Id)
                          .FirstOrDefault();
            }

            model.FormQuestion = temp.FormQuestion.ToList();

            return(View(model));
        }
Пример #4
0
        private void EditItem(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string name       = ((Button)sender).Tag.ToString();
            var    itemToEdit = this.inspectionViewModel.InspectionForms.Where(form => form.Name == name).First();

            this.inEditMode = true;
            this.editInspectionFormViewModel = itemToEdit;
            this.listName.Text = this.editInspectionFormViewModel.Name;
            SaveBtn.Content    = "Update";
        }
Пример #5
0
        public ActionResult Edit(int id)
        {
            var organizations = _context.Organizations.ToList();
            var postingTypes  = _context.PostingTypes.ToList();
            var user          = User.Identity.GetUserId();
            var inspections   = _context.Inspections.Include(i => i.User).Include(i => i.InspectionType).Single(i => i.Id == id && i.UserId == user);


            var viewModel = new InspectionFormViewModel(postingTypes, inspections.InspectionType.SafetyCategory, organizations, inspections.Id, inspections.DateTime.ToString("d MMM yyyy"), inspections.DateTime.ToString("HH:mm"), inspections.Description, inspections.InspectionTypeId, inspections.UserId, inspections.OrganizationId, PageTitles.Edit);

            return(View("InspectionForm", viewModel));
        }
Пример #6
0
        public void Overview_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var inspectionController      = new InspectionController();
            InspectionFormViewModel model = null;

            // Act
            var result = inspectionController.Overview(
                model);

            // Assert
            Assert.Fail();
        }
Пример #7
0
        public void Index_StateUnderTest_ExpectedBehavior1()
        {
            // Arrange
            var                     inspectionController = new InspectionController();
            FormCollection          form  = null;
            InspectionFormViewModel model = null;

            // Act
            var result = inspectionController.Index(
                form,
                model);

            // Assert
            Assert.Fail();
        }
Пример #8
0
        public ActionResult View(int id)
        {
            var currentUser = User.Identity.GetUserId();
            var inspections = _context.Inspections.Include(c => c.User).Include(c => c.InspectionType).Single(i => i.Id == id);

            var viewModel = new InspectionFormViewModel(
                inspections.DateTime.ToString("d MMM yyyy"),
                inspections.DateTime.ToString("HH:mm"),
                inspections.Description,
                inspections.InspectionTypeId,
                inspections.InspectionType.SafetyCategory,
                inspections.User,
                inspections.OrganizationId,
                inspections.IsCanceled);

            return(View("View", viewModel));
        }
Пример #9
0
        public ActionResult InspectionForm()
        {
            var currentUser = User.Identity.GetUserId();
            var user        = _context.Users.SingleOrDefault(u => u.Id == currentUser);

            if (!user.IsQA)
            {
                throw new InvalidOperationException("User is not QA");
            }

            var organizations = _context.Organizations.ToList();
            var postingTypes  = _context.PostingTypes.ToList();

            var viewModel = new InspectionFormViewModel(organizations, postingTypes, PageTitles.Schedule);

            return(View(viewModel));
        }
Пример #10
0
        // GET: Inspection
        public ActionResult Index(InspectionFormViewModel model)
        {
            if (Session["userID"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }

            Assignees temp, answers, eventdetails;

            using (UnitOfWork uow = new UnitOfWork())
            {
                temp = uow.AssigneesRepository
                       .GetIncludes("InspectionForm.FormQuestion.Multplechoice", u => u.UserId == (int)Session["userID"] && u.InspectionForm.Id == model.Id)
                       .FirstOrDefault();

                answers = uow.AssigneesRepository
                          .GetIncludes("InspectionForm.FormQuestion.Answer", u => u.UserId == (int)Session["userID"] && u.InspectionForm.Id == model.Id)
                          .FirstOrDefault();

                eventdetails = uow.AssigneesRepository
                               .GetIncludes("InspectionForm.EventInspection.Event", u => u.UserId == (int)Session["userID"] && u.InspectionForm.Id == model.Id)
                               .FirstOrDefault();
            }

            answers.InspectionForm.FormQuestion = answers.InspectionForm.FormQuestion.Select(formquestion =>
            {
                formquestion.Answer = formquestion.Answer
                                      .Where(answer => answer.UserId == (int)Session["userID"])
                                      .ToList();

                return(formquestion);
            }).ToList();

            InspectionFormViewModel inspectionFormViewModel = new InspectionFormViewModel()
            {
                Id        = temp.InspectionForm.Id, FormQuestion = temp.InspectionForm.FormQuestion.ToList(),
                EventName = $"{temp.InspectionForm.EventInspection.Event.Name} : {temp.InspectionForm.Name}"
            };

            return(View(inspectionFormViewModel));
        }
Пример #11
0
 public TemplateCreate()
 {
     this.InitializeComponent();
     inspectionFormViewModel       = new InspectionFormViewModel();
     ListViewQuestions.ItemsSource = inspectionFormViewModel.FormQuestions;
 }
Пример #12
0
        public ActionResult Index(FormCollection form, InspectionFormViewModel model)
        {
            if (Session["userID"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }

            var saveType = Int32.Parse(form["SaveType"]);

            form.Remove("SaveType");

            UnitOfWork uow = new UnitOfWork();

            var temp   = uow.InspectionFormRepository.GetIncludes("FormQuestion.Answer", u => u.Id == model.Id).FirstOrDefault();
            var images = Request.Files;

            // Images
            foreach (var imageKey in images.AllKeys)
            {
                foreach (var questionz in temp.FormQuestion)
                {
                    if (Int32.Parse(imageKey.ToString().Replace("question", "")) == questionz.Id)
                    {
                        var filetype = images[imageKey];

                        if (images[imageKey].FileName != String.Empty && images[imageKey].ContentType.Contains("image"))
                        {
                            // Create local image storage if folder doesnt exist
                            Directory.CreateDirectory(Server.MapPath("~/Content/form" + model.Id));
                            var filename = Path.Combine(Server.MapPath("~/Content/form" + model.Id + "/"), images[imageKey].FileName);
                            images[imageKey].SaveAs(filename);
                            filename = $"~/Content/form{model.Id}/{images[imageKey].FileName}";

                            // Write to database
                            var existingRecord = uow.AnswerRepository.Get(u => u.UserId == (int)Session["userID"] && u.FormQuestionId == Int32.Parse(imageKey.ToString().Replace("question", "")));

                            if (existingRecord.Count() == 0)
                            {
                                uow.AnswerRepository.Insert(new Answer()
                                {
                                    UserId = (int)Session["userID"], Value = filename, FormQuestionId = Int32.Parse(imageKey.ToString().Replace("question", ""))
                                });
                            }
                            else
                            {
                                existingRecord.First().Value = filename;
                                uow.AnswerRepository.Update(existingRecord.First());
                            }
                        }
                    }
                }
            }

            // Textbox & multiple choice
            foreach (var key in form.AllKeys)
            {
                var answer = form[key];
                if (answer.ToString() != String.Empty)
                {
                    foreach (var questionx in temp.FormQuestion)
                    {
                        if (questionx.Id == Int32.Parse(key.ToString().Replace("question", "")))
                        {
                            var existingRecord = uow.AnswerRepository.Get(u => u.UserId == (int)Session["userID"] && u.FormQuestionId == questionx.Id);

                            if (existingRecord.Count() == 0)
                            {
                                uow.AnswerRepository.Insert(new Answer()
                                {
                                    UserId = (int)Session["userID"], Value = answer, FormQuestionId = questionx.Id
                                });
                            }
                            else
                            {
                                existingRecord.First().Value = answer;
                                uow.AnswerRepository.Update(existingRecord.First());
                            }
                        }
                    }
                }
            }

            uow.Save();
            uow.Dispose();

            if (saveType == 1)
            {
                return(RedirectToAction("Overview", "Inspection", model));
            }
            else
            {
                return(RedirectToAction("Index", "Inspection"));
            }
        }
Пример #13
0
 public TemplateEdit()
 {
     this.InitializeComponent();
     inspectionFormViewModel = new InspectionFormViewModel();
 }