Example #1
0
        public IActionResult Load(long?ID, long?langId, long?productID, long?productDetailsID)
        {
            GetProductSubjectTypies operation = new GetProductSubjectTypies();

            operation.ID = ID;
            operation.ProductDetailsID = productDetailsID;
            operation.ProductID        = productID;

            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <ProductSubjectType>)result));
            }
        }
        public IActionResult LoadSubjectType(long?langId, long?productDetailID, long?ProductID, long?LineOfBusiness, long?SubLine)
        {
            GetSubjectTypies        subjectType      = new GetSubjectTypies();
            GetProductSubjectTypies prodSubjectTypes = new GetProductSubjectTypies();

            prodSubjectTypes.ProductID        = ProductID;
            prodSubjectTypes.ProductDetailsID = productDetailID;

            prodSubjectTypes.LineOfBusniess = LineOfBusiness;
            if (langId.HasValue)
            {
                subjectType.LangID      = langId;
                prodSubjectTypes.LangID = langId;
            }
            else
            {
                subjectType.LangID      = 1;
                prodSubjectTypes.LangID = 1;
            }



            List <ProductSubjectType> RelatedSubject   = new List <ProductSubjectType>();
            List <SubjectType>        UnRelatedSubject = new List <SubjectType>();



            subjectType.LineOfBusniessID = LineOfBusiness;
            var subject                   = subjectType.QueryAsync().Result;
            var SubjectsTypes             = (List <SubjectType>)subject;
            var productSubjectTypesResult = (List <ProductSubjectType>)prodSubjectTypes.QueryAsync().Result;

            if (productSubjectTypesResult.Count > 0)
            {
                RelatedSubject   = productSubjectTypesResult.Where(p => SubjectsTypes.Any(s => s.ID == p.SubjectTypeID && (s.SubLineOfBusniessID == SubLine || s.SubLineOfBusniessID == null))).ToList();
                UnRelatedSubject = SubjectsTypes.Where(s => productSubjectTypesResult.Any(p => p.SubjectTypeID != s.ID &&
                                                                                          (s.SubLineOfBusniessID == SubLine || s.SubLineOfBusniessID == null))).ToList();

                UnRelatedSubject = UnRelatedSubject.Where(un => !RelatedSubject.Exists(re => un.ID == re.SubjectTypeID)).ToList();
            }
            else
            {
                UnRelatedSubject = SubjectsTypes.Where(s => s.SubLineOfBusniessID == SubLine || s.SubLineOfBusniessID == null).ToList();
            }



            if (subject is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)subject).Errors
                }));
            }
            else
            {
                return(Ok(new { RelatedSubject, UnRelatedSubject }));
            }
        }