public static int? GetMakeId(lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc, int DepartmentID, string Name, int? AssetTypeId) { if (string.IsNullOrEmpty(Name)) return null; IQueryable<int> IDs; IDs = from d in dc.AssetMakes where d.DepartmentId == DepartmentID && d.Make == Name select d.Id; foreach (int ID in IDs) return ID; if (AssetTypeId == null) return null; lib.bwa.bigWebDesk.LinqBll.Context.AssetMakes data = new lib.bwa.bigWebDesk.LinqBll.Context.AssetMakes(); data.DepartmentId = DepartmentID; data.Make = Name; data.TypeId = (int)AssetTypeId; dc.AssetMakes.InsertOnSubmit(data); dc.SubmitChanges(); return data.Id; }
public static string Merge(lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc, int DepartmentId, int SourceFolderId, int DestFolderId) { var SourceFolders = from f in dc.Folders where f.DId == DepartmentId && f.Id == SourceFolderId select f; var Source = SourceFolders.FirstOrNull(); if (Source == null) return "Can not find the source folder."; var DestFolders = from f in dc.Folders where f.DId == DepartmentId && f.Id == DestFolderId select f; var Dest = DestFolders.FirstOrNull(); if (Dest == null) return "Can not find the destination folder."; if (Dest.ParentId == SourceFolderId) { Dest.ParentId = Source.ParentId; } var SourceSubFolders = from f in dc.Folders where f.DId == DepartmentId && f.ParentId == SourceFolderId select f; foreach (var sub in SourceSubFolders) sub.ParentId = DestFolderId; var SourceTickets = from t in dc.Tbl_ticket where t.Company_id == DepartmentId && t.Folder_id == SourceFolderId select t; foreach (var t in SourceTickets) t.Folder_id = DestFolderId; dc.Folders.DeleteOnSubmit(Source); dc.SubmitChanges(); return null; }
public static string Merge(lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc, int DepartmentId, int SourceMakeID, int DestMakeID) { var MergeInfo = from SourceModel in dc.AssetModels join DestModel in dc.AssetModels on new { SourceDID = SourceModel.DepartmentId, DestDID = DepartmentId, SourceMakeID = SourceModel.MakeId, DestMakeID, SourceModel.Model } equals new { SourceDID = DepartmentId, DestDID = DestModel.DepartmentId, SourceMakeID, DestMakeID = DestModel.MakeId, DestModel.Model } select new { SourceModel, DestModel }; foreach (var mi in MergeInfo) { AssetModels.Merge(dc, DepartmentId, mi.SourceModel.Id, mi.DestModel.Id); } var Models = from m in dc.AssetModels where m.DepartmentId == DepartmentId && m.MakeId == SourceMakeID select m; foreach (var Model in Models) Model.MakeId = DestMakeID; var Assets = from a in dc.Assets where a.DepartmentId == DepartmentId && a.MakeId == SourceMakeID select a; foreach (var a in Assets) a.MakeId = DestMakeID; var Makes = from m in dc.AssetMakes where m.DepartmentId == DepartmentId && m.Id == SourceMakeID select m; dc.AssetMakes.DeleteAllOnSubmit(Makes); dc.SubmitChanges(); return null; }
public static string Merge(lib.bwa.bigWebDesk.LinqBll.Context.MutiBaseDataContext dc, int DepartmentId, int SourceTypeID, int DestTypeID) { //AssetMakes var MergeInfo = from SourceMake in dc.AssetMakes join DestMake in dc.AssetMakes on new { SDID = SourceMake.DepartmentId, DDID = DepartmentId, SourceTypeID = SourceMake.TypeId, DestTypeID, SourceMake.Make } equals new { SDID = DepartmentId, DDID = DestMake.DepartmentId, SourceTypeID, DestTypeID = DestMake.TypeId, DestMake.Make } orderby SourceMake.Make, SourceMake.Id, DestMake.Make, DestMake.Id select new { SourceMake, DestMake }; foreach (var mi in MergeInfo) { AssetMakes.Merge(dc, DepartmentId, mi.SourceMake.Id, mi.DestMake.Id); } //AssetMakes var Makes = from m in dc.AssetMakes where m.DepartmentId == DepartmentId && m.TypeId == SourceTypeID select m; foreach (var Make in Makes) Make.TypeId = DestTypeID; //Assets var Assets = from a in dc.Assets where a.DepartmentId == DepartmentId && a.TypeId == SourceTypeID select a; foreach (var Asset in Assets) Asset.TypeId = DestTypeID; //DupeAssetTypeProperties var DupeTypeProperties = from sp in dc.AssetTypeProperties join dp in dc.AssetTypeProperties on new { sDepartmentId = sp.DId, dDepartmentId = DepartmentId, SourceTypeID = sp.AssetTypeId, DestTypeID, sp.Name } equals new { sDepartmentId = DepartmentId, dDepartmentId = dp.DId, SourceTypeID, DestTypeID=dp.AssetTypeId, dp.Name } select new { sp, dp}; foreach (var DupeTypeProperty in DupeTypeProperties) { var TypePropValues = from v in dc.AssetPropertyValues where v.AssetTypePropertyId == DupeTypeProperty.sp.Id select v; foreach (var TypePropValue in TypePropValues) { TypePropValue.AssetTypePropertyId = DupeTypeProperty.dp.Id; dc.AssetTypeProperties.DeleteOnSubmit(DupeTypeProperty.sp); } } dc.SubmitChanges(); //AssetTypeProperties var TypeProperties = from p in dc.AssetTypeProperties where p.DId == DepartmentId && p.AssetTypeId == SourceTypeID select p; foreach (var TypeProperty in TypeProperties) TypeProperty.AssetTypeId = DestTypeID; //AssetTypeCustCap var TypeCustCaps = from c in dc.AssetTypeCustCap where c.TypeId == SourceTypeID select c; foreach (var TypeCustCap in TypeCustCaps) TypeCustCap.TypeId = DestTypeID; //AssetTypes var Types = from t in dc.AssetTypes where t.DepartmentId == DepartmentId && t.Id == SourceTypeID select t; dc.AssetTypes.DeleteAllOnSubmit(Types); dc.SubmitChanges(); return null; }