예제 #1
0
        public ActionResult Add(int id)
        {
            var auditSectionId = id;

            var auditSection   = _context.AuditSections.Single(a => a.Id == auditSectionId);
            var auditTemaplate = _context.AuditTemplates.Single(a => a.Id == auditSection.AuditTemplateId);

            if (auditTemaplate.GetCompletedAuditCount(_context) == 0)
            {
                var viewModel = new AuditElementViewModel
                {
                    SectionId = id,
                    Section   = new AuditSectionViewModel
                    {
                        AuditTemplate = new AuditTemplateViewModel()
                    }
                };

                AutoMapper.Mapper.Map(auditSection, viewModel.Section);
                AutoMapper.Mapper.Map(auditTemaplate, viewModel.Section.AuditTemplate);

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

            ViewBag.Message = "Unable to add element. Audits have already been completed using this audit template.";
            return(RedirectToAction("Details", "AuditTemplates", new { id = auditTemaplate.Id }));
        }
예제 #2
0
        public ActionResult Edit(AuditElementViewModel model)
        {
            var userId         = User.Identity.GetUserId();
            var submitDateTime = DateTime.Now;

            var auditElement  = _context.AuditElements.Single(a => a.Id == model.Id);
            var auditSection  = _context.AuditSections.Single(a => a.Id == auditElement.SectionId);
            var auditTemplate = _context.AuditTemplates.Single(a => a.Id == auditSection.AuditTemplateId);

            model.CreateDateTime   = auditElement.CreateDateTime;
            model.CreatedById      = auditElement.CreatedById;
            model.ModifiedDateTime = submitDateTime;
            model.ModifiedById     = userId;

            if (ModelState.IsValid)
            {
                auditElement.UpdateFromViewModel(model);
                auditSection.ModifiedById      = userId;
                auditSection.ModifiedDateTime  = submitDateTime;
                auditTemplate.ModifiedById     = userId;
                auditTemplate.ModifiedDateTime = submitDateTime;
                _context.SaveChanges();

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

            model.Section = new AuditSectionViewModel {
                AuditTemplate = new AuditTemplateViewModel()
            };
            AutoMapper.Mapper.Map(auditSection, model.Section);
            AutoMapper.Mapper.Map(auditTemplate, model.Section.AuditTemplate);
            return(View("Form", model));
        }
예제 #3
0
        public ActionResult Details(int id)
        {
            var auditElement = _context.AuditElements
                               .Include(a => a.Section.AuditTemplate)
                               .Include(a => a.CreatedBy)
                               .Include(a => a.ModifiedBy)
                               .Single(a => a.Id == id);

            var viewModel = new AuditElementViewModel
            {
                Section = new AuditSectionViewModel {
                    AuditTemplate = new AuditTemplateViewModel()
                }
            };

            AutoMapper.Mapper.Map(auditElement, viewModel);

            return(View(viewModel));
        }
예제 #4
0
        public ActionResult Edit(int id)
        {
            var auditElement = _context.AuditElements
                               .Include(a => a.Section.AuditTemplate)
                               .Single(a => a.Id == id);

            if (auditElement.Section.AuditTemplate.GetCompletedAuditCount(_context) == 0)
            {
                var viewModel = new AuditElementViewModel
                {
                    Section = new AuditSectionViewModel {
                        AuditTemplate = new AuditTemplateViewModel()
                    }
                };

                AutoMapper.Mapper.Map(auditElement, viewModel);

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

            ViewBag.Message = "Unable to edit element.  Audits have already been completed using the audit template that it belongs to.";
            return(RedirectToAction("Details", "AuditTemplates", new { id = auditElement.Section.AuditTemplateId }));
        }