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 void CanConvertToNumberFromValidString()
        {
            var number = StringToValue.ParseInt("123");

            Assert.AreEqual(number, 123);
            number = StringToValue.ParseInt("-12322223");
            Assert.AreEqual(number, -12322223);
        }
        public void Save(T model, ApplicationDbContext db)
        {
            var    surveyUserData = model as Tuple <string, string>;
            Survey survey         = db.T_Survey.Find(StringToValue.ParseInt(surveyUserData.Item1));

            survey.HRSummary       = surveyUserData.Item2;
            survey.SurveyStatusId  = 4;
            db.Entry(survey).State = EntityState.Modified;
            db.SaveChanges();
        }
Beispiel #5
0
        public void Save(T model, ApplicationDbContext db)
        {
            SurveyUserData surveyUserData = model as SurveyUserData;

            if (surveyUserData != null && surveyUserData.QuestionId != null && surveyUserData.QuestionId != "0")
            {
                Survey survey = db.T_Survey.Find(StringToValue.ParseInt(surveyUserData.Id));
                survey.CompliteEmployeeDate = DateTime.Now;
                survey.EmployeeCompleted    = true;
                survey.SurveyStatusId       = 2;

                db.Entry(survey).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
        public void Save(T model, ApplicationDbContext db)
        {
            SurveyUserData surveyUserData = model as SurveyUserData;

            if (surveyUserData != null && surveyUserData.QuestionId != null && surveyUserData.QuestionId != "0")
            {
                SurveyQuestion surveyQuestion = db.T_SurveyQuestion.Find(StringToValue.ParseInt(surveyUserData.QuestionId));
                surveyQuestion.EmployeeScore = StringToValue.ParseInt(surveyUserData.QuestionSelection);
                if (surveyUserData.QuestionEmployeeComment != null && surveyUserData.QuestionEmployeeComment != "")
                {
                    surveyQuestion.EmployeeComment = surveyUserData.QuestionEmployeeComment;
                }
                db.Entry(surveyQuestion).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Beispiel #7
0
        public int Check(T model, out string message, ApplicationDbContext db)
        {
            SurveyPartData modelData = model as SurveyPartData;
            int            errorCode = 0;

            message = "";

            int            id             = StringToValue.ParseInt(modelData.Id);
            SurveyTemplate surveyTemplate = db.T_SurveyTemplate.Find(id);

            if (surveyTemplate != null)
            {
                db.Entry(surveyTemplate).Collection(p => p.SurveyPartTemplates).Load();
                List <SurveyPartTemplate> surveyPartTemplates = surveyTemplate.SurveyPartTemplates;
                if (surveyPartTemplates == null || surveyPartTemplates.Count() == 0)
                {
                    errorCode = 2;
                    message   = "Brak przynajmniej jednej sekcji ankiety.";
                    return(errorCode);
                }
                foreach (SurveyPartTemplate surveyPartTemplate in surveyTemplate.SurveyPartTemplates)
                {
                    db.Entry(surveyPartTemplate).Collection(p => p.SurveyQuestionTemplates).Load();
                    if (surveyPartTemplate.SurveyQuestionTemplates == null || surveyPartTemplate.SurveyQuestionTemplates.Count() == 0)
                    {
                        errorCode = 2;
                        message   = "Sekcja '" + surveyPartTemplate.Name + "' nie zawiera ani jednego pytania.";
                        return(errorCode);
                    }
                }
            }
            else
            {
                errorCode = 1;
                message   = "Nie znaleziono wzorca ankiety.";
            }

            return(errorCode);
        }
        public void CanNotConvertToNumberFromInvalidString()
        {
            var number = StringToValue.ParseInt("123A");

            Assert.AreEqual(number, 0);
        }