public CheckListTemplateEditModel SaveTemplate(CheckListTemplateEditModel model, long organizationRoleUserId) { CheckListTemplate templateinDb = null; var template = Mapper.Map <CheckListTemplateEditModel, CheckListTemplate>(model); if (template.Id > 0) { templateinDb = _checkListTemplateRepository.GetById(template.Id); template.CreatedBy = templateinDb.CreatedBy; template.DateCreated = templateinDb.DateCreated; template.DateModified = DateTime.Now; template.ModifiedBy = organizationRoleUserId; } else { template.CreatedBy = organizationRoleUserId; template.DateCreated = DateTime.Now; template.Type = model.Type; } //var groupQuestions = _checkListTemplateRepository.GetAllGroupQuestions(); //var gpIds = model.Questions.Select(x => x.Id).ToArray(); //var checklistTemplateList = new List<CheckListGroupQuestionEditModel>(); //foreach (var groupQuestionId in gpIds) //{ // var groupQuestion = groupQuestions.Single(x => x.Id == groupQuestionId); // checklistTemplateList.Add(new CheckListGroupQuestionEditModel { IsSelected = true, Id = groupQuestion.Id,GroupId = groupQuestion.GroupId, QuestionId = groupQuestion.QuestionId }); //} //model.Questions = checklistTemplateList.ToArray(); using (var scope = new TransactionScope()) { template = _checkListTemplateRepository.Save(template, model.Questions.Where(x => x.IsSelected)); scope.Complete(); } model.Id = template.Id; return(model); }
public CheckListTemplate Save(CheckListTemplate checkListTemplate, IEnumerable <CheckListGroupQuestionEditModel> questions) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { using (var scope = new TransactionScope()) { var entity = Mapper.Map <CheckListTemplate, CheckListTemplateEntity>(checkListTemplate); if (!adapter.SaveEntity(entity, true)) { throw new PersistenceFailureException(); } DeleteHealthAssessmentTemplateQuestion(entity.Id); SaveHealthAssessmentTemplatequestion(entity.Id, questions); var template = GetById(entity.Id); scope.Complete(); return(template); } } }