public static AddEditDeliveryLocationViewModel Populate(this AddEditDeliveryLocationViewModel model,
                                                                int apprenticeshipLocationId, ProviderPortalEntities db)
        {
            var userContext = UserContext.GetUserContext();

            if (!userContext.IsProvider())
            {
                return(null);
            }
            if (apprenticeshipLocationId == 0)
            {
                return(null);
            }

            var deliveryLocation = db.ApprenticeshipLocations
                                   .FirstOrDefault(x => x.Apprenticeship.ProviderId == userContext.ItemId.Value &&
                                                   x.ApprenticeshipLocationId == apprenticeshipLocationId);

            if (deliveryLocation == null)
            {
                return(null);
            }

            model = new AddEditDeliveryLocationViewModel
            {
                ProviderId = deliveryLocation.Apprenticeship.ProviderId,
                ApprenticeshipLocationId = deliveryLocation.ApprenticeshipLocationId,
                ApprenticeshipId         = deliveryLocation.ApprenticeshipId,
                RecordStatusId           = deliveryLocation.RecordStatusId,
                DeliveryModes            = db.DeliveryModes.ToList(),
                SelectedDeliveryModes    = deliveryLocation.DeliveryModes.Select(x => x.DeliveryModeId).ToList(),
                LocationId         = deliveryLocation.LocationId,
                Radius             = deliveryLocation.Radius,
                ApprenticeshipName = deliveryLocation.Apprenticeship.ApprenticeshipDetails()
            };
            model.AddMetaData(db, userContext);

            return(model);
        }
        public static AddEditDeliveryLocationViewModel PopulateNew(this AddEditDeliveryLocationViewModel model,
                                                                   int apprenticeshipId, ProviderPortalEntities db)
        {
            var userContext = UserContext.GetUserContext();

            model = new AddEditDeliveryLocationViewModel
            {
                RecordStatusId        = (Int32)Constants.RecordStatus.Live,
                ApprenticeshipId      = apprenticeshipId,
                SelectedDeliveryModes = new List <Int32>()
            };
            var apprenticeship = db.Apprenticeships
                                 .FirstOrDefault(x => x.ApprenticeshipId == apprenticeshipId);

            model.ApprenticeshipName = apprenticeship != null
                ? apprenticeship.ApprenticeshipDetails()
                : String.Empty;

            model.ProviderId = apprenticeship != null ? apprenticeship.ProviderId : 0;
            model.AddMetaData(db, userContext);
            return(model);
        }