/// <summary> /// get QuestionClasification Field By QuestionID and RecordID /// </summary> /// <param name="QuestionID"></param> /// <param name="RecordID"></param> /// <returns></returns> public QuestionClasifications GetQuestionClasificationField(int QuestionID, int ParameterID, string TableName) { QuestionClasifications Record = null; try { Record = QuestionClasifications.SelectQuestionClasificationsView(Context, p => p.QuestionID == QuestionID && p.ParameterID == ParameterID && p.TableName == TableName).FirstOrDefault(); } catch (Exception ex) { Errors.Write(ex); } return(Record); }
/// <summary> /// Return List View of all QuestionsClassification List /// </summary> /// <param name="QuestionID"></param> /// <param name="StartIndex"></param> /// <param name="Count"></param> /// <param name="Sorting"></param> /// <param name="Filtering"></param> /// <param name="CountRecords"></param> /// <returns></returns> public IEnumerable <QuestionClasifications> GetQuestionClasificationByFiltering(int QuestionID, int StartIndex, int Count, string Sorting, string Filtering, out int CountRecords) { IEnumerable <QuestionClasifications> ListQuestionClasification = null; CountRecords = 0; try { Expression <Func <QuestionClasifications, bool> > ExpressionFilter = p => p.QuestionID == QuestionID; if ((Filtering ?? "") != "") { ExpressionFilter = ExpressionFilter.And( tbl => ( tbl.ParameterName.Contains(Filtering) || tbl.TableName.Contains(Filtering) || (tbl.AdminValue == AdminValue.YES ? "YES" : "NO").Contains(Filtering) || (tbl.ParameterType == ParameterType.Add ? "Add" : "Remove").Contains(Filtering) ) ); } Sorting = Sorting.Replace("TableID", "TableName"); var query = QuestionClasifications.SelectQuestionClasificationsView(Context, ExpressionFilter); query = query.GetOrderByQuery(Sorting); //string sqlstring = query.ToString(); query = query.Get(StartIndex, Count, out CountRecords); ListQuestionClasification = query.ToList(); } catch (Exception ex) { Errors.Write(ex); } return(ListQuestionClasification); }
public async Task GetVendorQuestions(int VendorID, Release currentRelease, WindowsPrincipal User) { try { Release updatedRelease; using (IReleaseRepository db = new ReleaseRepository()) { updatedRelease = db.WhereAndInclude(r => r.ReleaseID == currentRelease.ReleaseID, r => r.ReleaseVendors).FirstOrDefault(); } var vendorIDs = updatedRelease.ReleaseVendors.Select(rv => rv.VendorID).ToArray(); IEnumerable <Vendor> Vendors = DbSet.Where(v => vendorIDs.Contains(v.VendorID)) .Include(v => v.VendorAreass) .Include(v => v.VendorAreass.Select(a => a.Area.QuestionAreas)).ToList(); List <int> AreaIDs = new List <int>(); List <int> ReleaseQuestions = new List <int>(); Vendors.ToList().ForEach(v => v.VendorAreass.ToList().ForEach(e => { var IsReleaseArea = currentRelease.ReleaseAreaOwners.Any(a => a.AreaID == e.AreaID && a.IsChecked == true); if (IsReleaseArea) { AreaIDs.Add(e.AreaID); } })); List <int> ReleaseQuestion = new List <int>(); if (AreaIDs.Count > 0) { using (IQuestionRepository db = new QuestionRepository()) { ReleaseQuestions = db.Where(q => AreaIDs.Contains(q.SubArea.AreaID)).Select(q => q.QuestionID).ToList(); } var Qustions = QuestionClasifications.SelectQuestionClasificationsView(Context); var AreaQuestions = Qustions.Where(q => ReleaseQuestions.Contains(q.QuestionID)).ToList(); List <QuestionAreaView> arrQuestions = new List <QuestionAreaView>(); AreaQuestions.ToList().ForEach(e => { AdminValue userValue = AdminValue.NO; switch (e.TableName) { case "Product": { var obj = currentRelease.ReleaseProducts.Count > 0 ? currentRelease.ReleaseProducts.FirstOrDefault(p => p.ProductID == e.ParameterID) : null; userValue = obj != null && obj.IsChecked ? AdminValue.YES : AdminValue.NO; break; } case "FamilyProduct": { var obj = currentRelease.ReleaseFamilyProducts.Count > 0 ? currentRelease.ReleaseFamilyProducts.FirstOrDefault(p => p.FamilyProductID == e.ParameterID) : null; userValue = obj != null && obj.IsChecked ? AdminValue.YES : AdminValue.NO; break; } case "Characteristic": { var obj = currentRelease.ReleaseCharacteristics.Count > 0 ? currentRelease.ReleaseCharacteristics.FirstOrDefault(p => p.CharacteristicID == e.ParameterID) : null; userValue = obj != null && obj.IsChecked ? AdminValue.YES : AdminValue.NO; break; } case "Area": { var obj = currentRelease.ReleaseAreaOwners.Count > 0 ? currentRelease.ReleaseAreaOwners.FirstOrDefault(p => p.AreaID == e.ParameterID) : null; userValue = obj != null && obj.IsChecked ? AdminValue.YES : AdminValue.NO; break; } case "Stakeholder": { var obj = currentRelease.ReleaseStakeholders.Count > 0 ? currentRelease.ReleaseStakeholders.FirstOrDefault(p => p.StakeholderID == e.ParameterID && p.EmployeeID1 != null) : null; userValue = obj != null ? AdminValue.YES : AdminValue.NO; break; } default: break; } ; arrQuestions.Add(new QuestionAreaView() { TableName = e.TableName, ParameterID = e.ParameterID, AdminValue = e.AdminValue, ParameterType = e.ParameterType, QuestionID = e.QuestionID, UserValue = userValue }); }); var AddQuestion = arrQuestions.Where(q => q.ParameterType == ParameterType.Add && (q.UserValue == AdminValue.YES && q.AdminValue == AdminValue.YES)).Select(q => q.QuestionID).Distinct(); var removeQuestions = arrQuestions.Where(q => q.ParameterType == ParameterType.Remove && (q.AdminValue != q.UserValue)).Select(q => q.QuestionID).Distinct(); ReleaseQuestion = AddQuestion.Where(q => !removeQuestions.Contains(q)).ToList(); //if (ReleaseQuestion.Count > 0) //{ //} } using (IQuestionRepository db = new QuestionRepository()) { await db.SetInitiateQuestions(currentRelease, ReleaseQuestion, (WindowsPrincipal)User); } } catch (Exception ex) { throw ex; } }