public void AddUpdateAuditSubject(AuditViewModel model, int LoggedInOrganizationId)
        {
            List <AuditSubject> _auditsubject = Mapper.Map <List <AuditSubjectViewModel>, List <AuditSubject> >(model.AuditSubjects);

            List <AuditSubject> storeAuditSubject = this.GetAllSubject(model.AuditID, LoggedInOrganizationId);

            foreach (var saudsub in storeAuditSubject)
            {
                bool isExist = _auditsubject.Any(x => x.AuditSubjectID == saudsub.AuditSubjectID);
                if (!isExist)
                {
                    saudsub.IsDeleted = true;
                    base.Update(saudsub);
                }
            }

            _auditsubject.ToList().ForEach(z =>
            {
                z.OrganizationID = LoggedInOrganizationId;

                if (z.AuditSubjectID > 0)
                {
                    AuditSubject storedAuditSubject        = this.GetSingle(z.AuditSubjectID, LoggedInOrganizationId);
                    storedAuditSubject.Subject             = z.Subject;
                    storedAuditSubject.AuditorID           = z.AuditorID;
                    storedAuditSubject.AuditeeID           = z.AuditeeID;
                    storedAuditSubject.Location            = z.Location;
                    storedAuditSubject.FrequencyRecurrence = z.FrequencyRecurrence;
                    storedAuditSubject.OrganizationID      = LoggedInOrganizationId;
                    base.Update(storedAuditSubject);
                    _IAuditSubjectQuestionRepository.AddUpdateAuditSubjectQuestion(z, LoggedInOrganizationId);
                }
                else
                {
                    z.AuditSubjectID = 0;
                    z.AuditSubjectQuestions.ToList().ForEach(x =>
                    {
                        x.AuditSubjectID         = 0;
                        x.AuditSubjectQuestionID = 0;
                    });
                    base.Insert(z);
                }
            });
            this._unitOfWork.Save();
            foreach (var z in _auditsubject)
            {
                GenerateAuditSubjectReview(z, model.DueDate);
            }
        }
        private void GenerateAuditSubjectReview(AuditSubject z, DateTime duedate)
        {
            List <DateTime> occurences = CommonMethods.GenerateAllDateFromCronExpression(z.FrequencyRecurrence, DateTime.Now, duedate);

            List <AuditSubjectReview> storedallsubrev = _IAuditSubjectReviewRepository.GetAllSubjectReview(z.AuditSubjectID, z.OrganizationID ?? 0);

            foreach (var sr in storedallsubrev)
            {
                bool isExist = occurences.Any(x => x == sr.PlannedAuditDate);
                if (!isExist)
                {
                    _IAuditSubjectReviewRepository.Delete(sr.AuditSubjectReviewID);
                }
            }
            this._unitOfWork.Save();

            foreach (DateTime auditdate in occurences)
            {
                bool isExist = storedallsubrev.Any(x => x.PlannedAuditDate == auditdate);
                if (!isExist)
                {
                    AuditSubjectReviewViewModel subrev = new AuditSubjectReviewViewModel();
                    subrev.AuditID          = z.AuditID;
                    subrev.SubjectID        = z.AuditSubjectID;
                    subrev.PlannedAuditDate = auditdate;
                    subrev.AuditDate        = null;
                    subrev.AuditorID        = z.AuditorID;
                    subrev.AuditeeID        = z.AuditeeID;
                    subrev.LocationID       = z.Location;
                    List <AuditSubjectQuestion> listauditsubjectqus = _IAuditSubjectQuestionRepository.GetAuditSubjectQuestionBuSubjectId(z.AuditSubjectID);
                    foreach (var asubqus in listauditsubjectqus)
                    {
                        AuditSubjectReviewQuestionViewModel asubqusres = new AuditSubjectReviewQuestionViewModel();
                        asubqusres.AuditSubjectQuestionID = asubqus.AuditSubjectQuestionID;
                        subrev.AuditSubjectQuestionResponses.Add(asubqusres);
                    }
                    subrev.Status = false;
                    _IAuditSubjectReviewRepository.AddUpdateAuditReview(subrev, 0, z.OrganizationID ?? 0);
                }
            }
        }
Beispiel #3
0
        public void AddUpdateAuditSubjectQuestion(AuditSubject model, int LoggedInOrganizationId)
        {
            List <AuditSubjectQuestion> storeAuditSubjectQus = this.GetAllSubjectQuestion(model.AuditSubjectID);

            foreach (var saudsubqus in storeAuditSubjectQus)
            {
                bool isExist = model.AuditSubjectQuestions.Any(x => x.AuditSubjectQuestionID == saudsubqus.AuditSubjectQuestionID);
                if (!isExist)
                {
                    saudsubqus.IsDeleted = true;
                    base.Update(saudsubqus);
                }
            }

            model.AuditSubjectQuestions.ToList().ForEach(x => {
                if (x.AuditSubjectQuestionID == 0)
                {
                    x.AuditSubjectID = model.AuditSubjectID;
                    base.Insert(x);
                }
            });
            this._unitOfWork.Save();
        }