Beispiel #1
0
        public ActionResult Edit(AuditTemplateViewModel model)
        {
            var auditTemplate = _context.AuditTemplates.Single(a => a.Id == model.Id);

            model.CreateDateTime   = auditTemplate.CreateDateTime;
            model.CreatedById      = auditTemplate.CreatedById;
            model.ModifiedDateTime = DateTime.Now;
            model.ModifiedById     = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                auditTemplate.UpdateFromViewModel(model);
                _context.SaveChanges();
                return(RedirectToAction("Details", new { id = auditTemplate.Id }));
            }
            return(View("Form", model));
        }
Beispiel #2
0
        public ActionResult Details(int id)
        {
            var auditTemplate = _context.AuditTemplates
                                .Include(a => a.CreatedBy)
                                .Include(a => a.ModifiedBy)
                                .Single(a => a.Id == id);

            var auditSections = _context.AuditSections
                                .Where(a => a.AuditTemplateId == id)
                                .ToList();


            var viewModel = new AuditTemplateViewModel
            {
                Sections = new List <AuditSectionViewModel>()
            };

            AutoMapper.Mapper.Map(auditTemplate, viewModel);
            AutoMapper.Mapper.Map(auditSections, viewModel.Sections);

            foreach (var section in viewModel.Sections)
            {
                var elements = _context.AuditElements
                               .Where(a => a.SectionId == section.Id)
                               .ToList();

                section.Elements = new List <AuditElementViewModel>();

                AutoMapper.Mapper.Map(elements, section.Elements);

                foreach (var element in section.Elements)
                {
                    var choices = _context.AuditElementChoices
                                  .Where(a => a.ElementId == element.Id)
                                  .ToList();

                    element.Choices = new List <AuditElementChoiceViewModel>();

                    AutoMapper.Mapper.Map(choices, element.Choices);
                }
            }

            viewModel.AuditsCompleted = _context.Audits.Count(a => a.AuditTemplateId == auditTemplate.Id);

            return(View(viewModel));
        }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            var viewModel = new AuditTemplateViewModel
            {
                AuditsCompleted = _context.Audits.Count(a => a.AuditTemplateId == id)
            };

            if (viewModel.AuditsCompleted == 0)
            {
                var auditTemplate = _context.AuditTemplates.Single(a => a.Id == id);

                AutoMapper.Mapper.Map(auditTemplate, viewModel);

                return(View("Form", viewModel));
            }

            ViewBag.Message = "You cannot edit an audit template once audits have already been completed using it.";
            return(View("Index"));
        }
Beispiel #4
0
        public ActionResult Add(AuditTemplateViewModel model)
        {
            model.CreateDateTime   = DateTime.Now;
            model.ModifiedDateTime = DateTime.Now;
            model.CreatedById      = User.Identity.GetUserId();
            model.ModifiedById     = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                var auditTemaplate = new AuditTemplate();

                AutoMapper.Mapper.Map(model, auditTemaplate);

                _context.AuditTemplates.Add(auditTemaplate);
                _context.SaveChanges();

                return(RedirectToAction("Details", new { id = auditTemaplate.Id }));
            }

            return(View("Form", model));
        }
Beispiel #5
0
        public ActionResult Add()
        {
            var viewModel = new AuditTemplateViewModel();

            return(View("Form", viewModel));
        }