Ejemplo n.º 1
0
 public IActionResult getTWCCDispatchInnerStructurDetails(int structureId, int siteRequirementId, commonEnum.TWCCDispatchReleaseDate releaseFilter, bool isAttributeBasedFilter)
 {
     try
     {
         var response = _siteDispatchService.GetTWCCInnerStructureDetails(structureId, siteRequirementId, releaseFilter, isAttributeBasedFilter);
         return(Ok(response));
     }
     catch (Exception e)
     {
         Util.LogError(e);
         return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass()
         {
             code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong"
         }));
     }
 }
        public List <TWCCDispatchInnerStructure> GetTWCCInnerStructureDetails(int structureId, int siteRequirementId, commonEnum.TWCCDispatchReleaseDate releaseFilter, bool isAttributeBasedFilter)
        {
            List <TWCCDispatchInnerStructure> result = new List <TWCCDispatchInnerStructure>();
            List <TWCCDispatchInnerStructure> lstTWCCDispatchInnerStructure = new List <TWCCDispatchInnerStructure>();

            lstTWCCDispatchInnerStructure = _siteDispatchRepository.GetTWCCInnerStructureDetails(structureId);
            List <TWCCDispatchInnerStructure> lstFilteredResult = new List <TWCCDispatchInnerStructure>();
            List <TWCCDispatchInnerStructure> lstDistinctResult = new List <TWCCDispatchInnerStructure>();
            SiteRequirementDetailsForDispatch siteRequirementDetailsForDispatch = new SiteRequirementDetailsForDispatch();

            siteRequirementDetailsForDispatch = _siteDispatchRepository.GetSiteRequirementDetails(siteRequirementId);
            foreach (var item in lstTWCCDispatchInnerStructure)
            {
                item.SiteRequirementStructureAttributes = siteRequirementDetailsForDispatch.StrutureAttributes;
                item.SiteRequirementId = siteRequirementDetailsForDispatch.SiteRequirementId;
                item.PlanStartDate     = siteRequirementDetailsForDispatch.PlanStartDate;
                item.PlanReleaseDate   = siteRequirementDetailsForDispatch.PlanEndDate;
                if (!isAttributeBasedFilter)
                {
                    List <TWCCJsonValue> projectStrutureAttibutesToJson     = JsonConvert.DeserializeObject <List <TWCCJsonValue> >(item.ProjectStructureAttributes);
                    List <TWCCJsonValue> siteRequirementStructureAttributes = JsonConvert.DeserializeObject <List <TWCCJsonValue> >(siteRequirementDetailsForDispatch.StrutureAttributes);
                    bool isCorrectAttributes = false;
                    foreach (var projectValue in projectStrutureAttibutesToJson)
                    {
                        var siteValue = siteRequirementStructureAttributes.Find(x => x.name == projectValue.name);
                        if (siteValue != null)
                        {
                            if (projectValue.value == siteValue.value)
                            {
                                isCorrectAttributes = true;
                            }
                            else
                            {
                                isCorrectAttributes = false;
                                break;
                            }
                        }
                    }
                    if (isCorrectAttributes)
                    {
                        lstFilteredResult.Add(item);
                    }
                }
                else
                {
                    lstFilteredResult.Add(item);
                }
            }
            lstDistinctResult = lstFilteredResult.Distinct().ToList();
            switch (releaseFilter)
            {
            case commonEnum.TWCCDispatchReleaseDate.ONEMONTH:

                DateTime currentStartDate = DateTime.Now.AddDays(-30);
                DateTime currentEndDate   = DateTime.Now;
                result = lstDistinctResult.FindAll(x => x.ExpReleaseDate >= currentStartDate && x.ExpReleaseDate <= currentEndDate);
                break;

            case commonEnum.TWCCDispatchReleaseDate.THREEMONTHS:
                currentStartDate = DateTime.Now.AddDays(-90);
                currentEndDate   = DateTime.Now;
                result           = lstDistinctResult.FindAll(x => x.ExpReleaseDate >= currentStartDate && x.ExpReleaseDate <= currentEndDate);
                break;

            case commonEnum.TWCCDispatchReleaseDate.SIXMONTHS:
                currentStartDate = DateTime.Now.AddDays(-180);
                currentEndDate   = DateTime.Now;
                result           = lstDistinctResult.FindAll(x => x.ExpReleaseDate >= currentStartDate && x.ExpReleaseDate <= currentEndDate);
                break;

            default:
                result = lstDistinctResult;
                break;
            }
            return(result);
        }