示例#1
0
        public ActionResult Index(int? page, int? PageSize, string sortBy)
        {
            var customers = new List<DSC_CUSTOMER>();
            var viewCustomers = new List<CustViewModel>();
            ViewBag.CurrentItemsPerPage = PageSize ?? 10;
            ViewBag.SortNameParameter = String.IsNullOrEmpty(sortBy) ? "Name desc" : "Name";
            ViewBag.SortParentParameter = sortBy == "Parent" ? "Parent desc" : "Parent"; 

            using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
            {
                customers = db.DSC_CUSTOMER.Where(cust_id => cust_id.dsc_cust_id > 0).ToList();
            }
            //DateTime active_date;
            foreach (DSC_CUSTOMER customer in customers)
            {
                string activeAction = "";
                try
                {
                    if (customer.dsc_cust_eff_end_date == null)
                    {
                        activeAction = "YES";

                    }//end of if
                    else
                    {
                        if (customer.dsc_cust_eff_end_date <= DateTime.Today)
                        {
                            activeAction = "NO";
                        }
                        else
                        {
                            activeAction = "YES";
                        }
                    }//end of else
                }//end of try
                catch
                {
                    activeAction = "NO";
                }//end of catch

                viewCustomers.Add(new CustViewModel(customer.dsc_cust_id, customer.dsc_cust_name, customer.dsc_cust_parent_name, activeAction, activeAction == "YES" ? "Deactivate" : "Activate"));
            }// end of foreach
            switch (sortBy)
            {
                case "Name desc":
                    return View(viewCustomers.OrderByDescending(x=>x.dsc_cust_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case "Parent desc":
                    return View(viewCustomers.OrderByDescending(x => x.dsc_cust_parent_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case"Name":
                    return View(viewCustomers.OrderBy(x => x.dsc_cust_name).ToPagedList(page ?? 1, PageSize ?? 10));
                case "Parent":
                    return View(viewCustomers.OrderBy(x => x.dsc_cust_parent_name).ToPagedList(page ?? 1, PageSize ?? 10));
                default: return View(viewCustomers.ToPagedList(page ?? 1, PageSize ?? 10));


            }

            
            
        }
示例#2
0
 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 public static bool DeactivateCust(int dsc_cust_id)
 {
     using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
     {
         var customer = db.DSC_CUSTOMER.Single(cust_id => cust_id.dsc_cust_id == dsc_cust_id);
         customer.dsc_cust_eff_end_date = DateTime.Today;
         db.SaveChanges();
     }
      return true;
 }
示例#3
0
 public ActionResult List(int dsc_cust_id)
 {
     try
     {
         using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
         {
             var customer = db.DSC_CUSTOMER.Single(cust_id => cust_id.dsc_cust_id == dsc_cust_id);
             customer.dsc_cust_eff_end_date = null;
             db.SaveChanges();
             return View(List());
         }
     }
     catch { return View(List()); }
 }
示例#4
0
        public static List<OBS_QUESTION> SearchQuestion(string search, string includeActiveOnly, DSC_OBS_DB_ENTITY db)
        {


            if (!String.IsNullOrWhiteSpace(search) && includeActiveOnly == "on")
            {
              
                return db.OBS_QUESTION.Where(ques => ques.obs_question_full_text.Contains(search) && DateTime.Today >= ques.obs_question_eff_st_dt && DateTime.Today < ques.obs_question_eff_end_dt).ToList();
            }
            else if (!String.IsNullOrWhiteSpace(search) && String.IsNullOrWhiteSpace(includeActiveOnly))
            {
                return db.OBS_QUESTION.Where(ques => ques.obs_question_full_text.Contains(search)).ToList();
            }
            else if (String.IsNullOrWhiteSpace(search) && includeActiveOnly == "on")
            {
                return db.OBS_QUESTION.Where(ques => DateTime.Today >= ques.obs_question_eff_st_dt && DateTime.Today < ques.obs_question_eff_end_dt).ToList();
            }

            else { return db.OBS_QUESTION.Where(ques => DateTime.Today >= ques.obs_question_eff_st_dt && DateTime.Today < ques.obs_question_eff_end_dt).ToList(); }

        }
 public void save(OBS_QUEST_ANS_TYPES oBS_QUEST_ANS_TYPES_U)
 {
     using (DSC_OBS_DB_ENTITY db1 = new DSC_OBS_DB_ENTITY())
     {
         db1.OBS_QUEST_ANS_TYPES.Add(oBS_QUEST_ANS_TYPES_U);
         db1.SaveChanges();
     }
 }
        private void retrieveQuestionData()
        {
            DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY();  //To give Database access to this Class
            // Pull all the questions information for the selected Form in the correct order
            var formQuestions = db.OBS_COL_FORM_QUESTIONS.Include(o => o.OBS_FORM_SECTION).Where(x => x.obs_cft_id == cft_id).ToList().OrderBy(y => y.obs_col_form_quest_order);
            if (formQuestions.Count() > 0)
            { //Pupulate the Form Sections and Questions List only if there is question data for the selcted Form
                int sectionCounter = 0;
                string oldSectionName = "undefined";
                string newSectionName = String.Empty;
                int questionCounter = 1;
                CollectionFormSection oSection = new CollectionFormSection();
                foreach (OBS_COL_FORM_QUESTIONS q in formQuestions)
                {
                    newSectionName = q.OBS_FORM_SECTION.obs_form_section_name;
                    //If the section name has changed, then we are in a new section
                    if (!newSectionName.Equals(oldSectionName))   // --- If this is a new Section ---
                    {
                        sectionCounter++;
                        // If this is not the first section. Add the old Section to the List
                        if (!oldSectionName.Equals("undefined")) { colFormSections.Add(oSection); }
                        //Create a new Section from scratch
                        oSection = new CollectionFormSection();
                        oSection.sectionNumber = sectionCounter;
                        oSection.sectionName = q.OBS_FORM_SECTION.obs_form_section_name;
                        oSection.sectionViewId = "viewSection" + oSection.sectionNumber.ToString();
                    }

                    //Create New question, Populate the Info and Add it to the current Form section
                    CollectionFormQuestion oQuestion = new CollectionFormQuestion();
                    oQuestion.cfq_id = q.obs_col_form_quest_id;
                    oQuestion.cfq_questId = q.OBS_QUEST_ANS_TYPES.obs_question_id;
                    oQuestion.cfq_order = q.obs_col_form_quest_order;
                    oQuestion.cfq_seqInForm = questionCounter.ToString("00");
                    oQuestion.cfq_fullText = q.OBS_QUEST_ANS_TYPES.OBS_QUESTION.obs_question_full_text.Replace(System.Environment.NewLine.ToString(), "").Trim();
                    oQuestion.cfq_AT = q.OBS_QUEST_ANS_TYPES.OBS_ANS_TYPE.obs_ans_type_name;
                    oQuestion.cfq_qatId = q.obs_qat_id;
                    oQuestion.cfq_na_yn = q.obs_col_form_quest_na_yn;
                    //oQuestion.cfq_SelectableAnswers = q.OBS_QUEST_ANS_TYPES.OBS_QUEST_SLCT_ANS.Where(item => item.obs_qsa_eff_st_dt <= DateTime.Now && item.obs_qsa_eff_end_dt > DateTime.Now).OrderBy(xx => xx.obs_qsa_order).Select(x => x.obs_qsa_text).ToList();
                    oQuestion.cfq_SelectableAnswers = q.OBS_QUEST_ANS_TYPES.OBS_QUEST_SLCT_ANS.OrderBy(xx => xx.obs_qsa_order).Select(x => x.obs_qsa_text).ToList();
                    // .... Populate the rest of the oQuestion properties
                    oSection.colFormQuestionList.Add(oQuestion);

                    // reset the name of the old  section indicator
                    oldSectionName = newSectionName;
                    questionCounter++;
                } // End of For-each question loop
                //Finally add the last populated section to the section List
                colFormSections.Add(oSection);
            }
        }
        //---------------------------------------------HELPERS----------------------------------------//
        public List<int> searchQuestionsWithMatchingSearchCriteria(string search_for_string, string search_criteria)
        {
            DSC_OBS_DB_ENTITY OBSdb = new DSC_OBS_DB_ENTITY();
            List<int> cft_ids_with_matching_qiestions = new List<int>();

            List<OBS_QUESTION> list_of_questions = (from q in OBSdb.OBS_QUESTION
                                                    join qa in OBSdb.OBS_QUEST_ANS_TYPES
                                                    on q.obs_question_id equals qa.obs_question_id
                                                    join fq in OBSdb.OBS_COL_FORM_QUESTIONS
                                                     on qa.obs_qat_id equals fq.obs_qat_id

                                                    select q).Distinct().ToList();
            string[] splitterm = { " " };
            string[] splitted_search_string = search_for_string.Split(splitterm, StringSplitOptions.RemoveEmptyEntries);
            switch (search_criteria)
            {
                case "Any":
                    foreach (OBS_QUESTION quest in list_of_questions)
                    {
                        if (matchesSearchCriteria(search_for_string, quest.obs_question_full_text, search_criteria))
                        {

                            List<int> temp = (from q in OBSdb.OBS_QUESTION
                                              join qa in OBSdb.OBS_QUEST_ANS_TYPES
                                              on q.obs_question_id equals qa.obs_question_id
                                              join fq in OBSdb.OBS_COL_FORM_QUESTIONS
                                               on qa.obs_qat_id equals fq.obs_qat_id
                                              where q.obs_question_id == quest.obs_question_id
                                              select fq.obs_cft_id).Distinct().ToList();
                            cft_ids_with_matching_qiestions = temp.Union(cft_ids_with_matching_qiestions).ToList();
                        }

                    }
                    break;

                case "All":
                    foreach (OBS_QUESTION quest in list_of_questions)
                    {
                        if (matchesSearchCriteria(search_for_string, quest.obs_question_full_text, search_criteria))
                        {
                            List<int> temp = (from q in OBSdb.OBS_QUESTION
                                              join qa in OBSdb.OBS_QUEST_ANS_TYPES
                                              on q.obs_question_id equals qa.obs_question_id
                                              join fq in OBSdb.OBS_COL_FORM_QUESTIONS
                                               on qa.obs_qat_id equals fq.obs_qat_id
                                              where q.obs_question_id == quest.obs_question_id
                                              select fq.obs_cft_id).Distinct().ToList();
                            cft_ids_with_matching_qiestions = temp.Union(cft_ids_with_matching_qiestions).ToList();
                        }
                    }
                    break;

                case "Exact":
                    cft_ids_with_matching_qiestions = (from q in OBSdb.OBS_QUESTION
                                                       join qa in OBSdb.OBS_QUEST_ANS_TYPES
                                                       on q.obs_question_id equals qa.obs_question_id
                                                       join fq in OBSdb.OBS_COL_FORM_QUESTIONS
                                                        on qa.obs_qat_id equals fq.obs_qat_id
                                                       where q.obs_question_full_text.Contains(search_for_string)
                                                       select fq.obs_cft_id).Distinct().ToList();
                    return cft_ids_with_matching_qiestions;

            }


            return cft_ids_with_matching_qiestions;
        }
示例#8
0
        public ActionResult Edit([Bind(Include = "dsc_emp_id,dsc_assigned_lc_id,dsc_emp_perm_id,dsc_emp_wms_clock_nbr,dsc_emp_first_name,dsc_emp_last_name,dsc_emp_email_addr,dsc_emp_title,dsc_emp_adp_id,dsc_emp_hire_dt,dsc_emp_init_work_dt,dsc_emp_term_dt,dsc_emp_can_be_obs_yn,dsc_emp_temp_yn,dsc_emp_hourly_yn,dsc_emp_added_id,dsc_emp_added_dtm,dsc_emp_upd_uid,dsc_emp_upd_dtm")] DSC_EMPLOYEE formEmployee)
        {
            using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
            {
                //var employee = db.EMPLOYEEs.Single(x => x.dsc_emp_id == formEmployee.dsc_emp_id);
                DSC_EMPLOYEE employee = formEmployee;
                //if (!ModelState.IsValid) {
                //    return View(formEmployee);
                //}
                try {
                    employee = db.DSC_EMPLOYEE.Find(formEmployee.dsc_emp_id);
                    employee.dsc_emp_title = formEmployee.dsc_emp_title;
                    employee.dsc_emp_perm_id = formEmployee.dsc_emp_perm_id;
                    employee.dsc_assigned_lc_id = formEmployee.dsc_assigned_lc_id;
                    employee.dsc_emp_can_be_obs_yn = formEmployee.dsc_emp_can_be_obs_yn == "on" ? "Y" : "N";
                    employee.dsc_emp_hourly_yn = formEmployee.dsc_emp_hourly_yn == "on" ? "Y" : "N";
                    employee.dsc_emp_temp_yn = formEmployee.dsc_emp_temp_yn == "on" ? "Y" : "N";
                    //employee.dsc_emp_hire_dt = formEmployee.dsc_emp_hire_dt;
                    employee.dsc_emp_term_dt = formEmployee.dsc_emp_term_dt;
                    employee.dsc_emp_email_addr = formEmployee.dsc_emp_email_addr;
                    employee.dsc_emp_upd_dtm = DateTime.Now;
                    employee.dsc_emp_upd_uid = User.Identity.Name;
                    formEmployee = employee;
                    db.SaveChanges();
                    ViewBag.dsc_assigned_lc_id = new SelectList(db.DSC_LC.Where(x => x.dsc_lc_id > 0 && x.dsc_lc_eff_end_date.Equals(null)).ToList(), "dsc_lc_id", "dsc_lc_name", formEmployee.dsc_assigned_lc_id);
                    ViewBag.ConfMsg = "Employee Information Saved Successfully.";
                }
                catch(Exception ex){
                    ViewBag.ConfMsg = "ERROR: " + ex.Message;
                }

                return View(employee);
            }
            //==========================================================
            //EMPLOYEE employeeFromFB = new EMPLOYEE();
            //employeeFromFB = db.EMPLOYEEs.Find(formEmployee.dsc_emp_id);

            //employeeFromFB.dsc_emp_perm_id = formEmployee.dsc_emp_perm_id;
            //employeeFromFB.dsc_emp_title = formEmployee.dsc_emp_title;
            //employeeFromFB.dsc_assigned_lc_id = formEmployee.dsc_assigned_lc_id;
            //employeeFromFB.dsc_emp_hire_dt = formEmployee.dsc_emp_hire_dt;
            //employeeFromFB.dsc_emp_term_dt = formEmployee.dsc_emp_term_dt;
            //employeeFromFB.dsc_emp_can_be_obs_yn = formEmployee.dsc_emp_can_be_obs_yn;
            //employeeFromFB.dsc_emp_hourly_yn = formEmployee.dsc_emp_hourly_yn;
            //employeeFromFB.dsc_emp_temp_yn = formEmployee.dsc_emp_temp_yn;
            //employeeFromFB.dsc_emp_upd_dtm = DateTime.Today;
            //employeeFromFB.dsc_emp_upd_uid = User.Identity.Name;

            //try
            //{
            //    db.Entry(employeeFromFB).State = EntityState.Modified;
            //    db.SaveChanges();
            //    ViewBag.ConfMsg = "Success";
            //}
            //catch { }
            //    //return RedirectToAction("Index");


            ////if (ModelState.IsValid)
            ////{
            ////    db.Entry(employeeFromFB).State = EntityState.Modified;
            ////    db.SaveChanges();
            ////    ViewBag.ConfMsg = "Success";
            ////    //return RedirectToAction("Index");
            ////}

            //ViewBag.dsc_assigned_lc_id = new SelectList(db.DSC_LC, "dsc_lc_id", "dsc_lc_name", formEmployee.dsc_assigned_lc_id);
            //return View(employeeFromFB);

            // ===========================================================================================
            ////using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
            ////{

            ////    var employee = db.EMPLOYEEs.Single(x => x.dsc_emp_id == formEmployee.dsc_emp_id);
            ////    employee.dsc_emp_title = formEmployee.dsc_emp_title;
            ////    db.SaveChanges();
            ////    formEmployee = employee;
            ////    ViewBag.
            ////    ViewBag.dsc_assigned_lc_id = new SelectList(db.DSC_LC.Where(x => x.dsc_lc_id>0).ToList(), "dsc_lc_id", "dsc_lc_name", formEmployee.dsc_assigned_lc_id);
            ////    return View(employee);
            ////}

            ////if (ModelState.IsValid) { }
            //db.ObjectStateManager.ChangeObjectState(dbEmployee, EntityState.Modified);
            //db.SaveChanges();
            //return View(dbEmployee);
        }
示例#9
0
        public ActionResult QuestionAddUpdatePost(FormCollection postedData, QuestionMDViewModel QuestionMDView,
                                 [Bind(Prefix = "questn")] OBS_QUESTION questionHdr, string ans_type_list)
        {
            string posted_deleted_ids = postedData["obs_qat_Id_delList"];

            if (questionHdr.obs_question_eff_end_dt < Convert.ToDateTime("01/01/2000")) { questionHdr.obs_question_eff_end_dt = Convert.ToDateTime("12/31/2060"); }
            string posted_ans_type_list = postedData["ans_type_list"];//represents newly added selectable ans types
            string posted_existing_ans_type_data = postedData["sel_ans_list"]; //represents existing assigned ans types that need to be modified
            //string ans_type_list = "6~true~yes~no~maybe,10~false~1~2~3~4~5";
            //ans_type_list format: at_id~default~sel_ans,
            //                          6~ true  ~always~sometimes~never,
            //obs_qat_id_delList = qat_id,qat_id,... list of answer types to be deleted
            //-------- Save the Question Information ----
            int defaultQATid = -1;
            try
            {
                defaultQATid = Convert.ToInt32(postedData["defaultQATid"]);
            }
            catch { }
            using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        
                        if(defaultQATid>0)
                        {
                            updateDefaultAnswerType(defaultQATid, "Y");
                        }
                        else if (questionHdr.obs_question_id > 0)
                        {             
                            List<OBS_QUEST_ANS_TYPES> temp_OBS_QUEST_ANS_TYPES = db.OBS_QUEST_ANS_TYPES.Where(x => x.obs_question_id == questionHdr.obs_question_id).ToList();
                            foreach(OBS_QUEST_ANS_TYPES x in temp_OBS_QUEST_ANS_TYPES )
                            {
                                x.obs_qat_default_ans_type_yn = "N";
                                db.SaveChanges();
                            }
                        }
                        ///////////////////////////////This section saves changes to existing answer types/////////////////////////////////
                        if (!string.IsNullOrEmpty(posted_existing_ans_type_data))
                        {
                            string[] split_ans_types_by = { "," };
                            string[] posted_single_ans_type_data = posted_existing_ans_type_data.Split(split_ans_types_by, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string str in posted_single_ans_type_data)
                            {
                                List<string> selAnsList_from_form = new List<string>();
                                string[] splitterm = { "~" };
                                string[] ans_type_elements = str.Split(splitterm, StringSplitOptions.RemoveEmptyEntries);
                                int intQATid = Convert.ToInt32(ans_type_elements[0]);
                                short obs_ans_type_id = db.OBS_QUEST_ANS_TYPES.Single(x => x.obs_qat_id == intQATid).obs_ans_type_id;
                                for (int i = 1; i < ans_type_elements.Length; i++)
                                {
                                    selAnsList_from_form.Add(ans_type_elements[i].Trim().ToUpper());
                                }
                                OBS_ANS_TYPE ans_type = db.OBS_ANS_TYPE.Single(item => item.obs_ans_type_id == obs_ans_type_id);
                                List<string> current_sel_ans_list = db.OBS_QUEST_SLCT_ANS.Where(item => item.obs_qat_id == intQATid && item.obs_qsa_eff_st_dt <= DateTime.Now && item.obs_qsa_eff_end_dt > DateTime.Now).Select(x => x.obs_qsa_text).ToList();                           
                                if (isEqualList(current_sel_ans_list, selAnsList_from_form, ans_type.obs_ans_type_category))
                                {//if we're here that means 2 lists are the same and we only need to change the order of selected answers list
                                        short order = 1;
                                        for (int i = 1; i < ans_type_elements.Length; i++)
                                        {
                                            string sel_ans_element = ans_type_elements[i];
                                            OBS_QUEST_SLCT_ANS oBS_QUEST_SLCT_ANS = db.OBS_QUEST_SLCT_ANS.Single(item => item.obs_qat_id == intQATid && item.obs_qsa_text == sel_ans_element && item.obs_qsa_eff_st_dt <= DateTime.Now && item.obs_qsa_eff_end_dt > DateTime.Now);
                                            oBS_QUEST_SLCT_ANS.obs_qsa_order = order;
                                            db.SaveChanges();
                                            order++;
                                        }
                                }
                                else//if we're here, that means user passed a different list of selected answers and we need to delete the current one and add new
                                {                                  
                                        //List<OBS_QUEST_SLCT_ANS> oBS_QUEST_SLCT_ANS = db.OBS_QUEST_SLCT_ANS.Where(item => item.obs_qat_id == intQATid).ToList();
                                        db.OBS_QUEST_SLCT_ANS.RemoveRange(db.OBS_QUEST_SLCT_ANS.Where(x => x.obs_qat_id == intQATid)); ;//update end effective date to todays date
                                        short order = 1;
                                        for (int i = 1; i < ans_type_elements.Length; i++)//now lets create a new record with updated selected answers
                                        {
                                            OBS_QUEST_SLCT_ANS UPDATED_oBS_QUEST_SLCT_ANS = new OBS_QUEST_SLCT_ANS();
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qat_id = intQATid;
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_text = ans_type_elements[i].ToUpper();
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_order = order;
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_wt = 1;
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_dflt_yn = "N";
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_eff_st_dt = DateTime.Now;
                                            UPDATED_oBS_QUEST_SLCT_ANS.obs_qsa_eff_end_dt = Convert.ToDateTime("12/31/2060");
                                            db.OBS_QUEST_SLCT_ANS.Add(UPDATED_oBS_QUEST_SLCT_ANS);
                                            order++;
                                        }// end foreach
                                       db.SaveChanges();                                                                      
                                }
                            }//foreach (string str in posted_single_ans_type_data)
                        }//end of  if (!string.IsNullOrEmpty(posted_existing_ans_type_data))
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                        //this section saves new question information or new question answer type
                        if (questionHdr.obs_question_id > 0)
                        {
                            OBS_QUESTION editedQuestion = db.OBS_QUESTION.Single(x => x.obs_question_id == questionHdr.obs_question_id);

                            if (!editedQuestion.obs_question_full_text.Equals(questionHdr.obs_question_full_text))
                            {
                                editedQuestion.obs_question_ver++;
                                
                            }                            
                            editedQuestion.obs_question_full_text = questionHdr.obs_question_full_text;
                            editedQuestion.obs_question_desc = questionHdr.obs_question_desc;
                            editedQuestion.obs_question_eff_st_dt = questionHdr.obs_question_eff_st_dt;
                            editedQuestion.obs_question_eff_end_dt = questionHdr.obs_question_eff_end_dt;
                            editedQuestion.obs_question_upd_dtm = DateTime.Now;
                            editedQuestion.obs_question_upd_uid = User.Identity.Name;
                            db.SaveChanges();
                        }
                        else {

                            if (questionHdr.obs_question_eff_end_dt < Convert.ToDateTime("01/01/1900"))
                            {
                                questionHdr.obs_question_eff_end_dt = Convert.ToDateTime("12/31/2060");
                            }
                            if (questionHdr.obs_question_eff_st_dt < Convert.ToDateTime("01/01/1900"))
                            {
                                questionHdr.obs_question_eff_st_dt = DateTime.Now;
                            }
                            questionHdr.obs_question_ver = 1;
                            questionHdr.obs_question_added_uid = User.Identity.Name;
                            questionHdr.obs_question_added_dtm = DateTime.Now;
                            db.OBS_QUESTION.Add(questionHdr);
                            db.SaveChanges();
                        }

                        if (!String.IsNullOrEmpty(posted_ans_type_list))
                        {
                            string[] splitter = { "," };
                            string[] passed_sel_ans_info = posted_ans_type_list.Split(splitter, StringSplitOptions.RemoveEmptyEntries);//all passed selectable answers data
                            foreach (string s in passed_sel_ans_info)
                            {
                                string[] splitby = { "~" };
                                string[] single_sel_ans_info = s.Split(splitby, StringSplitOptions.RemoveEmptyEntries);//individual answer type data
                                OBS_QUEST_ANS_TYPES new_assigned_ans_type = new OBS_QUEST_ANS_TYPES();
                                new_assigned_ans_type.obs_ans_type_id = Convert.ToInt16(single_sel_ans_info[0]);
                                new_assigned_ans_type.obs_question_id = questionHdr.obs_question_id;
                                new_assigned_ans_type.obs_qat_default_ans_type_yn = single_sel_ans_info[1] == "true" ? "Y" : "N";
                                db.OBS_QUEST_ANS_TYPES.Add(new_assigned_ans_type);
                                db.SaveChanges();//at this point we've saved the OBS_QUEST_ANS_TYPES record.
                                OBS_QUEST_ANS_TYPES passed_quest_ans_record = db.OBS_QUEST_ANS_TYPES.Single(x => x.obs_qat_id == new_assigned_ans_type.obs_qat_id);
                                if (passed_quest_ans_record.obs_qat_default_ans_type_yn != new_assigned_ans_type.obs_qat_default_ans_type_yn && new_assigned_ans_type.obs_qat_default_ans_type_yn == "N")
                                { //if existing record is default and we need to set it to N we need to do it here and we won't have to 
                                  //change any other records
                                    passed_quest_ans_record.obs_qat_default_ans_type_yn = "N";
                                    db.SaveChanges();
                                }
                                else if (passed_quest_ans_record.obs_qat_default_ans_type_yn != new_assigned_ans_type.obs_qat_default_ans_type_yn && new_assigned_ans_type.obs_qat_default_ans_type_yn == "Y")
                                {//  if passed qat_id needs to be default one, we should first set existing default to N and then update passed  to Y   
                                    try
                                    {
                                        int current_default_quest_id = db.OBS_QUEST_ANS_TYPES.Single(x => x.obs_question_id == passed_quest_ans_record.obs_question_id && x.obs_qat_id != passed_quest_ans_record.obs_qat_id && x.obs_qat_default_ans_type_yn == "Y").obs_question_id;
                                        setExistingDefaultToN(current_default_quest_id);
                                    }
                                    catch { }
                                    passed_quest_ans_record.obs_qat_default_ans_type_yn = "Y";
                                    db.SaveChanges();
                                }
                                if (single_sel_ans_info.Count() > 2)//now we need to check if there's selectable answers for this question
                                {
                                    short order = 1;
                                    for (int i = 2; i < single_sel_ans_info.Count(); i++)
                                    {
                                        OBS_QUEST_SLCT_ANS new_sel_ans = new OBS_QUEST_SLCT_ANS();
                                        new_sel_ans.obs_qat_id = new_assigned_ans_type.obs_qat_id;
                                        new_sel_ans.obs_qsa_text = single_sel_ans_info[i];
                                        new_sel_ans.obs_qsa_order = order;
                                        new_sel_ans.obs_qsa_wt = 1;
                                        new_sel_ans.obs_qsa_dflt_yn = "N";
                                        new_sel_ans.obs_qsa_eff_st_dt = DateTime.Now;
                                        new_sel_ans.obs_qsa_eff_end_dt = Convert.ToDateTime("12/31/2060");
                                        db.OBS_QUEST_SLCT_ANS.Add(new_sel_ans);
                                        db.SaveChanges();
                                        order++;
                                    }
                                }
                            }
                        }
                        ///////////////////////////////////WE DELETE SEL ANS HERE///////////////////////////////////////////
                        if (!string.IsNullOrEmpty(posted_deleted_ids))
                        {
                            string[] qats_to_delete = posted_deleted_ids.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string qat_to_delete in qats_to_delete)
                            {
                                deleteAssignedSelAns(Convert.ToInt32(qat_to_delete), db);
                            }
                        }
                        ///////////////////////////////////END OF DELETING SEL ANS///////////////////////////////////////////

                        // ------- Save the Question Metadata Changes ----
                        string MDlistBefore = postedData["origTags"];
                        string MDlistAfter = postedData["qAssignedMD"];
                        List<string> originalMDList = new List<string>();
                        List<string> newMDList = new List<string>();
                        if (!String.IsNullOrEmpty(MDlistBefore)) { originalMDList = MDlistBefore.Split(',').ToList(); }
                        if (!String.IsNullOrEmpty(MDlistAfter)) { newMDList = MDlistAfter.Split(',').ToList(); }
                        string[] mdIDsToDelete = originalMDList.Except(newMDList).ToArray();
                        string[] mdIDsToAdd = newMDList.Except(originalMDList).ToArray();

                        //---- Soft Delete all Metadata tags that are no longer used by the question
                        foreach (string deleteId in mdIDsToDelete)
                        {
                            int tempId = Convert.ToInt32(deleteId);
                            //int joitemp = db.OBS_QUEST_ASSGND_MD.Where(x => x.obs_quest_md_id == Convert.ToInt32(deleteId) && x.obs_question_id == questionHdr.obs_question_id).Select(x => x.obs_qad_id);
                            OBS_QUEST_ASSGND_MD oBS_QUEST_ASSGND_MD = db.OBS_QUEST_ASSGND_MD.FirstOrDefault(x => x.obs_quest_md_id == tempId && x.obs_question_id == questionHdr.obs_question_id);
                            oBS_QUEST_ASSGND_MD.obs_qad_eff_end_dt = DateTime.Today;
                            //db.OBS_QUESTION_METADATA.Remove(oBS_QUESTION_METADATA);  //No hard deletes
                        }

                        //---- Enable or Add the New metadata (MD) that will be assigned to the question ---
                        //-- Process each metadata entry to add for the selected question
                        foreach (string mdIdtoAdd in mdIDsToAdd)
                        {
                            try
                            {
                                int tempId = Convert.ToInt32(mdIdtoAdd);
                                //-- Look for an entry in OBS_QUEST_ASSGND_MD usign the Question Id and the metadata it.
                                OBS_QUEST_ASSGND_MD oBS_QUEST_ASSGND_MD = db.OBS_QUEST_ASSGND_MD.FirstOrDefault(x => x.obs_quest_md_id == tempId && x.obs_question_id == questionHdr.obs_question_id);
                                //-- If an entry is found in the junction table for that question, just enable it
                                if (oBS_QUEST_ASSGND_MD != null && tempId > 0)
                                {
                                    oBS_QUEST_ASSGND_MD.obs_qad_eff_end_dt = Convert.ToDateTime("12/31/2060");
                                }
                                else
                                { //-- If selected MD does not exist in the junction table for that question, add it.
                                    oBS_QUEST_ASSGND_MD = new OBS_QUEST_ASSGND_MD();
                                    oBS_QUEST_ASSGND_MD.obs_quest_md_id = tempId;
                                    oBS_QUEST_ASSGND_MD.obs_question_id = questionHdr.obs_question_id;
                                    oBS_QUEST_ASSGND_MD.obs_qad_eff_st_dt = DateTime.Today;
                                    oBS_QUEST_ASSGND_MD.obs_qad_eff_end_dt = Convert.ToDateTime("12/31/2060");
                                    db.OBS_QUEST_ASSGND_MD.Add(oBS_QUEST_ASSGND_MD);
                                }
                            }
                            catch { }
                        }

                        //---- Save All Changes ------
                        db.SaveChanges();

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        string notused = e.Message;
                        transaction.Rollback();
                    }
                }


            }


            //ViewBag.ConfMsg = "Data Saved Successfully.";

            return RedirectToAction("QuestionAddUpdate", new {id = questionHdr.obs_question_id});

            //return RedirectToAction("Index", "Question");
            //return View("Edit");
        }
示例#10
0
        /*
        *       This method deletes assigned selected answers and all the selectable answers if needed  
        */
        public void deleteAssignedSelAns(int qat_id, DSC_OBS_DB_ENTITY ObsDB)
        {
            //first need to check if qat_id is already tied to any Form
            if (ObsDB.OBS_COL_FORM_QUESTIONS.Where(x => x.obs_qat_id == qat_id).ToList().Count > 0)
            {
                //if answer type requires selectable answers, lets deactivate them first
                short ans_type_id = ObsDB.OBS_QUEST_ANS_TYPES.Single(y => y.obs_qat_id == qat_id).obs_ans_type_id;
                if (ObsDB.OBS_ANS_TYPE.Single(x => x.obs_ans_type_id == ans_type_id).obs_ans_type_has_fxd_ans_yn == "Y")
                {
                    List<OBS_QUEST_SLCT_ANS> sel_answers = ObsDB.OBS_QUEST_SLCT_ANS.Where(x => x.obs_qat_id == qat_id && x.obs_qsa_eff_st_dt <= DateTime.Now && x.obs_qsa_eff_end_dt > DateTime.Now).ToList();
                    foreach (OBS_QUEST_SLCT_ANS sel_ans in sel_answers) 
                    {
                        sel_ans.obs_qsa_eff_end_dt = DateTime.Now;                       
                    }
                }
                ObsDB.OBS_QUEST_ANS_TYPES.Single(x => x.obs_qat_id == qat_id).obs_qat_end_eff_dt = DateTime.Now;

            }
            else
            {//ok, this qat id doesn't belong to any form. We can hard delete it
                //but first we need to check if there are selectable answers for this answer type and delete them
                short ans_type_id = ObsDB.OBS_QUEST_ANS_TYPES.Single(y => y.obs_qat_id == qat_id).obs_ans_type_id;
                if (ObsDB.OBS_ANS_TYPE.Single(x=>x.obs_ans_type_id== ans_type_id).obs_ans_type_has_fxd_ans_yn=="Y")
                {
                    ObsDB.OBS_QUEST_SLCT_ANS.RemoveRange(ObsDB.OBS_QUEST_SLCT_ANS.Where(x => x.obs_qat_id == qat_id));
                }               
                ObsDB.OBS_QUEST_ANS_TYPES.Remove(ObsDB.OBS_QUEST_ANS_TYPES.Find(qat_id));
            }
            ObsDB.SaveChanges();
        }
示例#11
0
 public ActionResult Activate(int id, string actionText)
 {
     if (actionText == "Activate")
     {
         using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
         {
             var customer = db.DSC_CUSTOMER.Single(cust_id => cust_id.dsc_cust_id == id);
             customer.dsc_cust_eff_end_date = null;
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     else if (actionText == "Deactivate")
     {
         using (DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY())
         {
             var customer = db.DSC_CUSTOMER.Single(cust_id => cust_id.dsc_cust_id == id);
             customer.dsc_cust_eff_end_date = DateTime.Today;
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return RedirectToAction("Index");
 }