예제 #1
0
        public void Save(T model, ApplicationDbContext db)
        {
            SurveyQuestionData modelData = model as SurveyQuestionData;

            int id, type;

            int.TryParse(modelData.Id, out id);
            int.TryParse(modelData.Type, out type);

            SurveyPartTemplate surveyPartTemplate = db.T_SurveyPartTemplate.Find(id);

            if (surveyPartTemplate != null)
            {
                SurveyQuestionTemplate surveyQuestionTemplate = new SurveyQuestionTemplate()
                {
                    Name                 = modelData.Name,
                    Definition           = modelData.Criteria,
                    QuestionType         = type,
                    SurveyPartTemplateId = id
                };
                db.T_SurveyQuestionTemplate.Add(surveyQuestionTemplate);
                db.Entry(surveyPartTemplate).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
        public T1 GetView(ApplicationDbContext db)
        {
            SurveyUserData       model = Parameters as SurveyUserData;
            SurveyUserDataReturn surveyUserDataReturn = new SurveyUserDataReturn();

            int id               = StringToValue.ParseInt(model.Id);
            int surveyPartId     = StringToValue.ParseInt(model.SectionId);
            int surveyQuestionId = StringToValue.ParseInt(model.QuestionId);

            SurveyPart             surveyPart             = db.T_SurveyPart.Where(sp => sp.SurveyId == id && sp.Id == surveyPartId).FirstOrDefault();
            List <SurveyQuestion>  surveyQuestions        = db.T_SurveyQuestion.Where(sq => sq.SurveyPartId == surveyPart.Id && sq.Id < surveyQuestionId).ToList();
            SurveyQuestion         surveyQuestion         = surveyQuestions[surveyQuestions.Count() - 1];
            SurveyPartTemplate     surveyPartTemplate     = db.T_SurveyPartTemplate.Find(surveyPart.SurveyPartTemplateId);
            SurveyQuestionTemplate surveyQuestionTemplate = db.T_SurveyQuestionTemplate.Find(surveyQuestion.SurveyQuestionTemplateId);

            surveyUserDataReturn.TotalSections  = db.T_SurveyPart.Where(sp => sp.SurveyId == id).Count();
            surveyUserDataReturn.TotalQuestions = db.T_SurveyPart
                                                  .Join(db.T_SurveyQuestion,
                                                        sp => sp.Id, sq => sq.SurveyPartId,
                                                        (sp, sq) => sp).Where(sp => sp.SurveyId == id).Count();
            surveyUserDataReturn.TotalSectionQuestions   = db.T_SurveyQuestion.Where(sq => sq.SurveyPartId == surveyPart.Id).Count();
            surveyUserDataReturn.QuestionSectionNo       = db.T_SurveyQuestion.Where(sq => sq.SurveyPartId == surveyPart.Id && sq.Id <= surveyQuestion.Id).Count();
            surveyUserDataReturn.SectionName             = surveyPartTemplate.Name;
            surveyUserDataReturn.SectionTitle            = surveyPartTemplate.SummaryTitle;
            surveyUserDataReturn.SectionId               = surveyPart.Id;
            surveyUserDataReturn.QuestionId              = surveyQuestion.Id;
            surveyUserDataReturn.QuestionName            = surveyQuestionTemplate.Name;
            surveyUserDataReturn.QuestionDescription     = surveyQuestionTemplate.Definition;
            surveyUserDataReturn.QuestionType            = surveyQuestionTemplate.QuestionType;
            surveyUserDataReturn.QuestionEmployeeScore   = surveyQuestion.EmployeeScore;
            surveyUserDataReturn.QuestionEmployeeComment = surveyQuestion.EmployeeComment;
            surveyUserDataReturn.SectionNo               = db.T_SurveyPart.Where(sp => sp.SurveyId == id && sp.Id <= surveyPart.Id).Count();

            return(surveyUserDataReturn as T1);
        }
        public T1 GetView(ApplicationDbContext db)
        {
            SurveyUserData       model = Parameters as SurveyUserData;
            SurveyUserDataReturn surveyUserDataReturn = new SurveyUserDataReturn();
            SurveyPart           surveyPart           = new SurveyPart();

            int id = StringToValue.ParseInt(model.Id);

            surveyPart = db.T_SurveyPart.Where(sp => sp.SurveyId == id).FirstOrDefault();
            SurveyPartTemplate surveyPartTemplate = db.T_SurveyPartTemplate.Find(surveyPart.SurveyPartTemplateId);

            surveyUserDataReturn.TotalSections  = db.T_SurveyPart.Where(sp => sp.SurveyId == id).Count();
            surveyUserDataReturn.TotalQuestions = db.T_SurveyPart
                                                  .Join(db.T_SurveyQuestion,
                                                        sp => sp.Id, sq => sq.SurveyPartId,
                                                        (sp, sq) => sp).Where(sp => sp.SurveyId == id).Count();
            surveyUserDataReturn.TotalSectionQuestions = db.T_SurveyQuestion.Where(sq => sq.SurveyPartId == surveyPart.Id).Count();
            surveyUserDataReturn.SectionName           = surveyPartTemplate.Name;
            surveyUserDataReturn.SectionTitle          = surveyPartTemplate.SummaryTitle;
            surveyUserDataReturn.SectionId             = surveyPart.Id;
            surveyUserDataReturn.QuestionId            = 0;
            surveyUserDataReturn.SectionNo             = db.T_SurveyPart.Where(sp => sp.SurveyId == id && sp.Id <= surveyPart.Id).Count();

            return(surveyUserDataReturn as T1);
        }
        public ActionResult DeletePart(int?id)
        {
            SurveyPartTemplate surveyPartTemplate = db.T_SurveyPartTemplate.Find(id);

            if (surveyPartTemplate != null)
            {
                db.T_SurveyPartTemplate.Remove(surveyPartTemplate);
                db.SaveChanges();
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(RedirectToAction("Edit/" + surveyPartTemplate.SurveyTemplateId.ToString()));
        }
        public void Save(T model, ApplicationDbContext db)
        {
            SurveyPartData modelData      = model as SurveyPartData;
            int            id             = StringToValue.ParseInt(modelData.Id);
            SurveyTemplate surveyTemplate = db.T_SurveyTemplate.Find(id);

            if (surveyTemplate != null)
            {
                SurveyTemplate newSurveyTemplate = new SurveyTemplate()
                {
                    Name                = modelData.Name,
                    SurveyDate          = DateTime.Now,
                    PublishDate         = new DateTime(1900, 1, 1),
                    SurveyPartTemplates = new List <SurveyPartTemplate>()
                };

                db.Entry(surveyTemplate).Collection(p => p.SurveyPartTemplates).Load();
                if (surveyTemplate.SurveyPartTemplates != null)
                {
                    foreach (SurveyPartTemplate surveyPartTemplate in surveyTemplate.SurveyPartTemplates)
                    {
                        SurveyPartTemplate newSurveyPartTemplate = new SurveyPartTemplate()
                        {
                            Name                    = surveyPartTemplate.Name,
                            SummaryTitle            = surveyPartTemplate.SummaryTitle,
                            SurveyQuestionTemplates = new List <SurveyQuestionTemplate>()
                        };

                        newSurveyTemplate.SurveyPartTemplates.Add(newSurveyPartTemplate);

                        db.Entry(surveyPartTemplate).Collection(p => p.SurveyQuestionTemplates).Load();
                        foreach (SurveyQuestionTemplate surveyQuestionTemplate in surveyPartTemplate.SurveyQuestionTemplates)
                        {
                            SurveyQuestionTemplate newSurveyQuestionTemplate = new SurveyQuestionTemplate()
                            {
                                Name         = surveyQuestionTemplate.Name,
                                Definition   = surveyQuestionTemplate.Definition,
                                QuestionType = surveyQuestionTemplate.QuestionType
                            };
                            newSurveyPartTemplate.SurveyQuestionTemplates.Add(newSurveyQuestionTemplate);
                        }
                    }
                }
                db.T_SurveyTemplate.Add(newSurveyTemplate);
                db.SaveChanges();
            }
        }
        public ActionResult DeleteQuestion(int?id)
        {
            SurveyQuestionTemplate surveyQuestionTemplate = db.T_SurveyQuestionTemplate.Find(id);
            SurveyPartTemplate     surveyPartTemplate     = db.T_SurveyPartTemplate.Find(surveyQuestionTemplate.SurveyPartTemplateId);

            //if (db.T_SurveyPartTemplate.Where(e => e.PositionId == id).ToList().Count() == 0)
            if (surveyQuestionTemplate != null)
            {
                db.T_SurveyQuestionTemplate.Remove(surveyQuestionTemplate);
                db.SaveChanges();
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(RedirectToAction("Edit/" + surveyPartTemplate.SurveyTemplateId.ToString()));
        }
        public void Save(T model, ApplicationDbContext db)
        {
            SurveyPartData modelData = model as SurveyPartData;

            int id;

            int.TryParse(modelData.Id, out id);

            SurveyPartTemplate surveyPartTemplate = db.T_SurveyPartTemplate.Find(id);

            if (surveyPartTemplate != null)
            {
                surveyPartTemplate.Name         = modelData.Name;
                surveyPartTemplate.SummaryTitle = modelData.Summary;

                db.Entry(surveyPartTemplate).State = EntityState.Modified;
                db.SaveChanges();
            }
        }