public string CreateNewLocationGroup(LocationGroupEntity lge) { var locationGroupAlreadyExistsInPool = LocationGroupEntityCheck.DoesLocationGroupNameExistForCountry(DataContext, lge.LocationGroupName, lge.PoolId); if (locationGroupAlreadyExistsInPool) { return(LocationGroupEntityCheck.LocationGroupAlreadyExistsForCountry); } var newLocationGroupEntity = new CMS_LOCATION_GROUP { IsActive = true, cms_location_group1 = lge.LocationGroupName, cms_location_group_code_dw = string.Empty, cms_pool_id = lge.PoolId, }; DataContext.CMS_LOCATION_GROUPs.InsertOnSubmit(newLocationGroupEntity); var returned = SubmitDbChanges(); if (returned != string.Empty) { return(returned); } //Insert new MARS_CMS_NECESSARY_FLEET var twoLetterCountryCode = DataContext.COUNTRies.Single(d => d.CountryId == lge.CountryId).country1; int locationGroupId = newLocationGroupEntity.cms_location_group_id; var allCarGroups = from cg in DataContext.CAR_GROUPs where cg.CAR_CLASS.CAR_SEGMENT.COUNTRy1.CountryId == lge.CountryId select cg.car_group_id; var fleetToInsert = new List <MARS_CMS_NECESSARY_FLEET>(); foreach (var cg in allCarGroups) { fleetToInsert.Add(new MARS_CMS_NECESSARY_FLEET { COUNTRY = twoLetterCountryCode, CMS_LOCATION_GROUP_ID = locationGroupId, CAR_CLASS_ID = cg, //Not Car Class, NessFleet has bad column Naming UTILISATION = 100, NONREV_FLEET = 0, }); } DataContext.MARS_CMS_NECESSARY_FLEETs.InsertAllOnSubmit(fleetToInsert); returned = SubmitDbChanges(); return(returned); }
public string UpdateLocationGroup(LocationGroupEntity lge) { var locationGroupAlreadyExistsInPool = LocationGroupEntityCheck.DoesLocationGroupNameExistForCountry(DataContext, lge.LocationGroupName, lge.PoolId, lge.Id); if (locationGroupAlreadyExistsInPool) { return(LocationGroupEntityCheck.LocationGroupAlreadyExistsForCountry); } var locationGroupDbEntry = DataContext.CMS_LOCATION_GROUPs.Single(d => d.cms_location_group_id == lge.Id); locationGroupDbEntry.cms_pool_id = lge.PoolId; locationGroupDbEntry.cms_location_group1 = lge.LocationGroupName; locationGroupDbEntry.IsActive = lge.Active; var returned = SubmitDbChanges(); return(returned); }