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);
        }
Example #2
0
        protected void btnSavePopup_Click(object sender, EventArgs e)
        {
            if (ddlPool.SelectedValue == string.Empty)
            {
                ProcessDatabaseReply("A Pool must be selected", "", AdminMappingEnum.CmsLocationGroup, lblMessage);
                return;
            }
            var lge = new LocationGroupEntity
            {
                Id                = int.Parse(hfLocationGroupId.Value),
                PoolId            = int.Parse(ddlPool.SelectedValue),
                CountryId         = int.Parse(ddlCountry.SelectedValue),
                LocationGroupName = tbLocationGroup.Text,
                Active            = cbActive.Checked
            };

            SaveDataToDataBase(lge);
        }
Example #3
0
        private void SaveDataToDataBase(LocationGroupEntity lge)
        {
            string message;

            if (lge.Id == 0)
            {
                //lge.CountryId = int.Parse(ddlCountry.SelectedValue);
                using (var dataAccess = new MappingDeleteAndCreate())
                {
                    message = dataAccess.CreateNewLocationGroup(lge);
                }
            }
            else
            {
                lge.Id = int.Parse(hfLocationGroupId.Value);
                using (var dataAccess = new MappingSingleUpdate())
                {
                    message = dataAccess.UpdateLocationGroup(lge);
                }
            }
            ProcessDatabaseReply(message, UpdateLocationGroupSuccess, AdminMappingEnum.CmsLocationGroup, lblMessage);
        }
Example #4
0
        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);
        }