public CommodityAnalysisModel GetList() { try { using (db = new IEDEntities()) { var commoAnaModel = new CommodityAnalysisModel(); var commoAnalysis = (from x in db.T_CommodityAnalysis where !x.IsDeleted && x.ObjectType == (int)eObjectType.isCommodity select new ProAnaModel() { Id = x.Id, Name = x.Name, Node = x.Node, ObjectId = x.ObjectId, ObjectType = x.ObjectType, ParentId = x.ParentId, Description = x.Description, CreatedDate = x.CreatedDate }); if (commoAnalysis != null) { commoAnaModel.CommoAna.AddRange(commoAnalysis); commoAnaModel.years.AddRange(commoAnalysis.Select(x => x.CreatedDate.Month).Distinct()); } return(commoAnaModel); } } catch (Exception ex) { throw ex; } }
public CommodityAnalysisModel GetCommoAnaItemByParentId(int parentId, string value, int Type, int companyId, int[] relationCompanyId, int year) { try { using (db = new IEDEntities()) { var commoAnaModel = new CommodityAnalysisModel(); int value_ = 0; switch (Type) { case (int)eObjectType.getYear: commoAnaModel.years.AddRange((from x in db.T_CommodityAnalysis where !x.IsDeleted && (x.CompanyId == companyId || relationCompanyId.Contains(x.CompanyId)) && x.ObjectType == (int)eObjectType.isCommodity select x.CreatedDate.Year).Distinct()); break; case (int)eObjectType.getMonth: value_ = int.Parse(value); commoAnaModel.years.AddRange((from x in db.T_CommodityAnalysis where !x.IsDeleted && (x.CompanyId == companyId || relationCompanyId.Contains(x.CompanyId)) && x.ObjectType == (int)eObjectType.isCommodity && x.CreatedDate.Year == value_ select x.CreatedDate.Month).Distinct()); break; case (int)eObjectType.isCommodity: value_ = int.Parse(value); commoAnaModel.CommoAna.AddRange((from x in db.T_CommodityAnalysis where !x.IsDeleted && (x.CompanyId == companyId || relationCompanyId.Contains(x.CompanyId)) && x.ObjectType == (int)eObjectType.isCommodity && x.CreatedDate.Year == year && x.CreatedDate.Month == value_ select new ProAnaModel() { Id = x.Id, Name = x.Name, Node = x.Node, ObjectId = x.ObjectId, ObjectType = x.ObjectType, ParentId = x.ParentId, Description = x.Description, CreatedDate = x.CreatedDate })); break; case (int)eObjectType.isWorkShop: case (int)eObjectType.isComponent: case (int)eObjectType.isGroupVersion: case (int)eObjectType.isPhaseGroup: commoAnaModel.CommoAna.AddRange((from x in db.T_CommodityAnalysis where !x.IsDeleted && x.ParentId == parentId select new ProAnaModel() { Id = x.Id, Name = x.Name, Node = x.Node, ObjectId = x.ObjectId, ObjectType = x.ObjectType, ParentId = x.ParentId, Description = x.Description, CreatedDate = x.CreatedDate, })); break; } if (commoAnaModel.CommoAna.Count > 0) { switch (commoAnaModel.CommoAna.First().ObjectType) { case (int)eObjectType.isCommodity: var commoIds = commoAnaModel.CommoAna.Select(x => x.ObjectId); var commoCheck = db.T_Product.Where(x => !x.IsDeleted && commoIds.Contains(x.Id)).Select(x => x.Id); commoAnaModel.CommoAna = commoAnaModel.CommoAna.Where(x => commoCheck.Contains(x.ObjectId)).ToList(); break; case (int)eObjectType.isWorkShop: var workshopIds = commoAnaModel.CommoAna.Select(x => x.ObjectId); var workshopCheck = db.T_WorkShop.Where(x => !x.IsDeleted && workshopIds.Contains(x.Id)).Select(x => x.Id); commoAnaModel.CommoAna = commoAnaModel.CommoAna.Where(x => workshopCheck.Contains(x.ObjectId)).ToList(); break; case (int)eObjectType.isPhaseGroup: var phaseGroupIds = commoAnaModel.CommoAna.Select(x => x.ObjectId); var phaseGroupCheck = db.T_PhaseGroup.Where(x => !x.IsDeleted && phaseGroupIds.Contains(x.Id)).Select(x => x.Id); commoAnaModel.CommoAna = commoAnaModel.CommoAna.Where(x => phaseGroupCheck.Contains(x.ObjectId)).ToList(); break; } } return(commoAnaModel); } } catch (Exception ex) { throw ex; } }