Ejemplo n.º 1
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Entity <UserProfile>()
            .HasMany <Technology>(s => s.InterestedIn)
            .WithMany(c => c.UserProfiles)
            .Map(cs =>
            {
                cs.MapLeftKey("UserProfileId");
                cs.MapRightKey("TechnologyId");
                cs.ToTable("UserTechnologies");
            });



            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
Ejemplo n.º 2
0
        public static void Register()
        {
            ConfigOptions options = new ConfigOptions
            {
                PushAuthorization        = AuthorizationLevel.Application,
                DiagnosticsAuthorization = AuthorizationLevel.Anonymous,
            };

            options.LoginProviders.Remove(typeof(AzureActiveDirectoryLoginProvider));
            options.LoginProviders.Add(typeof(AzureActiveDirectoryExtendedLoginProvider));

            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            // Now add any missing connection strings and app settings from the environment.
            // Any envrionment variables found with names that match existing connection
            // string and app setting names will be used to replace the value.
            // This allows the Web.config (which typically would contain secrets) to be
            // checked in, but requires people running the tests to config their environment.
            IServiceSettingsProvider  settingsProvider = config.DependencyResolver.GetServiceSettingsProvider();
            ServiceSettingsDictionary settings         = settingsProvider.GetServiceSettings();
            IDictionary environmentVariables           = Environment.GetEnvironmentVariables();

            foreach (var conKey in settings.Connections.Keys.ToArray())
            {
                var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == conKey);
                if (!string.IsNullOrEmpty(envKey))
                {
                    settings.Connections[conKey].ConnectionString = (string)environmentVariables[envKey];
                }
            }

            foreach (var setKey in settings.Keys.ToArray())
            {
                var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == setKey);
                if (!string.IsNullOrEmpty(envKey))
                {
                    settings[setKey] = (string)environmentVariables[envKey];
                }
            }

            // Emulate the auth behavior of the server: default is application unless explicitly set.
            config.Properties["MS_IsHosted"] = true;

            config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <IntIdRoundTripTableItem, IntIdRoundTripTableItemDto>()
                .ForMember(dto => dto.Id, map => map.MapFrom(db => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(db.Id))));
                cfg.CreateMap <IntIdRoundTripTableItemDto, IntIdRoundTripTableItem>()
                .ForMember(db => db.Id, map => map.MapFrom(dto => MySqlFuncs.LongParse(dto.Id)));

                cfg.CreateMap <IntIdMovie, IntIdMovieDto>()
                .ForMember(dto => dto.Id, map => map.MapFrom(db => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(db.Id))));
                cfg.CreateMap <IntIdMovieDto, IntIdMovie>()
                .ForMember(db => db.Id, map => map.MapFrom(dto => MySqlFuncs.LongParse(dto.Id)));
            });

            Database.SetInitializer(new DbInitializer());
        }
Ejemplo n.º 3
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Category>().HasKey(c => c.Id);

            modelBuilder.Entity <Product>().HasKey(p => p.Id);

            modelBuilder.Entity <Category>()
            .HasOptional(c => c.ParentCategory)
            .WithMany(c => c.SubCategories)
            .HasForeignKey(c => c.ParentCategoryId);

            modelBuilder.Entity <Product>()
            .HasRequired <Category>(p => p.Category)
            .WithMany(c => c.Products)
            .HasForeignKey(p => p.CategoryId);

            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
        // PATCH tables/User/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public Task <IHttpActionResult> PatchUser(string id, Delta <User> patch)
        {
            string updateCommand = "INSERT INTO UserRelations (Followers, Following)  VALUES = ('" +
                                   patch.GetEntity().Followers + "','" + patch.GetEntity().Following + "');";

            string command = String.Format(updateCommand, ServiceSettingsDictionary.GetSchemaName());

            context.Database.ExecuteSqlCommandAsync(command);
            return(null);
        }
Ejemplo n.º 5
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Configuration.ProxyCreationEnabled = true;
            Configuration.LazyLoadingEnabled   = true;

            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Entity <Athlete>().ToTable("Athlete");
            modelBuilder.Entity <League>().ToTable("League");
            modelBuilder.Entity <Membership>().ToTable("Membership");
            modelBuilder.Entity <Challenge>().ToTable("Challenge");
            modelBuilder.Entity <GameResult>().ToTable("GameResult");

            modelBuilder.Entity <Challenge>().HasRequired(a => a.ChallengeeAthlete)
            .WithMany().HasForeignKey(a => a.ChallengeeAthleteId);

            modelBuilder.Entity <Challenge>().HasRequired(a => a.ChallengerAthlete)
            .WithMany().HasForeignKey(a => a.ChallengerAthleteId);

            modelBuilder.Entity <Challenge>().HasRequired(a => a.League)
            .WithMany().HasForeignKey(a => a.LeagueId);

            modelBuilder.Entity <GameResult>().HasRequired(a => a.Challenge)
            .WithMany().HasForeignKey(a => a.ChallengeId);

            modelBuilder.Entity <GameResult>().HasRequired(g => g.Challenge)
            .WithMany(c => c.MatchResult)
            .HasForeignKey(g => g.ChallengeId);

            modelBuilder.Entity <League>().HasOptional(a => a.CreatedByAthlete)
            .WithMany().HasForeignKey(a => a.CreatedByAthleteId);

            modelBuilder.Entity <Membership>().HasRequired(m => m.League)
            .WithMany(l => l.Memberships)
            .HasForeignKey(m => m.LeagueId);

            modelBuilder.Entity <Challenge>().HasRequired(c => c.League)
            .WithMany(l => l.Challenges)
            .HasForeignKey(m => m.LeagueId);

            modelBuilder.Entity <Membership>().HasRequired(m => m.Athlete)
            .WithMany(a => a.Memberships)
            .HasForeignKey(m => m.AthleteId);

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
Ejemplo n.º 6
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            Database.SetInitializer <JobDbContext>(null);
            base.OnModelCreating(modelBuilder);
        }
Ejemplo n.º 7
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();
            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
Ejemplo n.º 8
0
 public override void ConfigureMiddleware(IAppBuilder appBuilder,
     ServiceSettingsDictionary settings)
 {
     LinkedInAuthenticationOptions options = new LinkedInAuthenticationOptions
     {
         ClientId = settings["LinkedInClientId"],
         ClientSecret = settings["LinkedInClientSecret"],
         AuthenticationType = this.Name,
         Provider = new LinkedInLoginAuthenticationProvider()
     };
     appBuilder.UseLinkedInAuthentication(options);
 }
Ejemplo n.º 9
0
    public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings)
    {
        var options = new GoogleOAuth2AuthenticationOptions
        {
            ClientId           = settings["MS_GoogleClientID"],
            ClientSecret       = settings["MS_GoogleClientSecret"],
            AuthenticationType = this.Name,
            Provider           = new CustomGoogleLoginAuthenticationProvider()
        };

        appBuilder.UseGoogleAuthentication(options);
    }
Ejemplo n.º 10
0
        public override void ConfigureMiddleware(IAppBuilder appBuilder,
                                                 ServiceSettingsDictionary settings)
        {
            LinkedInAuthenticationOptions options = new LinkedInAuthenticationOptions
            {
                ClientId           = settings["LinkedInClientId"],
                ClientSecret       = settings["LinkedInClientSecret"],
                AuthenticationType = this.Name,
                Provider           = new LinkedInLoginAuthenticationProvider()
            };

            appBuilder.UseLinkedInAuthentication(options);
        }
        /// <summary>
        /// </summary>
        /// <param name="appBuilder"></param>
        /// <param name="settings"></param>
        public override void ConfigureMiddleware(IAppBuilder appBuilder,
                                                 ServiceSettingsDictionary settings)
        {
            var options = new FacebookAuthenticationOptions
            {
                AppId              = Environment.GetEnvironmentVariable("FBAppId"),
                AppSecret          = Environment.GetEnvironmentVariable("FBAppSecret"),
                AuthenticationType = Name,
                Provider           = new FBLoginAuthenticationProvider(),
                Scope              = { "email" }
            };

            appBuilder.UseFacebookAuthentication(options);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// </summary>
        /// <param name="appBuilder"></param>
        /// <param name="settings"></param>
        public override void ConfigureMiddleware(IAppBuilder appBuilder,
                                                 ServiceSettingsDictionary settings)
        {
            var options = new VkAuthenticationOptions
            {
                ClientId           = Environment.GetEnvironmentVariable("VKClientId"),
                ClientSecret       = Environment.GetEnvironmentVariable("VKClientSecret"),
                Provider           = new VKLoginAuthenticationProvider(),
                AuthenticationType = Name,
                Scope = { "email" }
            };

            appBuilder.UseVkontakteAuthentication(options);
        }
Ejemplo n.º 13
0
        public static void Register()
        {
            // Use this class to set configuration options for your mobile service
            ConfigOptions options = new ConfigOptions();

            // Use this class to set WebAPI configuration options
            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            // To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            Database.SetInitializer(new TicTacToeMobileServiceInitializer(ServiceSettingsDictionary.GetSchemaName()));
        }
Ejemplo n.º 14
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
            modelBuilder.Entity <EventItem>()
            .HasMany(eventItem => eventItem.ParticipantItems)
            .WithMany(participant => participant.EventItems);
            modelBuilder.Entity <EventItem>()
            .HasOptional(eventItem => eventItem.PlaceItem)
            .WithMany(placeItem => placeItem.EventItems);
        }
Ejemplo n.º 15
0
        public string GetGroupId(AadGroups group)
        {
            if (this.groupIds == null)
            {
                ServiceSettingsDictionary settings = this.settingsProvider.GetServiceSettings();
                this.groupIds = new Dictionary <AadGroups, string>();

                string storeAssociateId = ReadSetting(settings, "AadSalesAssociateGroupObjectId");
                this.groupIds.Add(AadGroups.StoreAssociate, storeAssociateId);
                string fieldMangerGroupId = ReadSetting(settings, "AadFieldManagerGroupObjectId");
                this.groupIds.Add(AadGroups.FieldManager, fieldMangerGroupId);
                string fieldAgentGroupId = ReadSetting(settings, "AadFieldAgentGroupObjectId");
                this.groupIds.Add(AadGroups.FieldAgent, fieldAgentGroupId);
            }

            string groupId;

            return(this.groupIds.TryGetValue(group, out groupId) ? groupId : null);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// The on model creating.
        /// </summary>
        /// <param name="modelBuilder">
        /// The model builder.
        /// </param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            modelBuilder.Entity <Customer>()
            .HasMany(e => e.Orders)
            .WithRequired(e => e.Customer)
            .HasForeignKey(e => e.CustomerId)
            .WillCascadeOnDelete(false);
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
            modelBuilder.Entity <Travel>()
            .HasMany(t => t.Categories)
            .WithRequired()
            .WillCascadeOnDelete(true);
            modelBuilder.Entity <Categorie>()
            .HasMany(c => c.Items)
            .WithRequired()
            .WillCascadeOnDelete(true);
        }
Ejemplo n.º 18
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            /*
             * The following line of code is part of the VS template.
             * It creates a column annotation "ServiceTableColumn" for data fields with attribute [TableColumn].
             * E.g.: The attribute [TableColumn(TableColumnType.UpdatedAt)] will be translated to a
             * column annotation "UpdatedAt".
             * This annotation enables the entity framework to automatically fill the corresponding fields
             * when according actions took place.
             */
            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
Ejemplo n.º 19
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Account>().HasKey(a => a.Id);

            modelBuilder.Entity <Order>().HasKey(o => o.Id);

            modelBuilder.Entity <Category>().HasKey(c => c.Id);

            modelBuilder.Entity <Product>().HasKey(p => p.Id);

            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            modelBuilder.Entity <User>()
            .HasMany <User>(u => u.Followers)
            .WithMany(c => c.Following)
            .Map(cs =>
            {
                cs.MapLeftKey("Followers");
                cs.MapRightKey("Following");
                cs.ToTable("UserRelations");
            });
        }
Ejemplo n.º 21
0
        public string GetAccessToken()
        {
            ServiceSettingsDictionary settings = this.settingsProvider.GetServiceSettings();

            if (!this.configuration.GetIsHosted())
            {
                // Running in localhost, return null
                return(null);
            }

            string tenant   = ReadSetting(settings, "AadTenantDomain");
            string clientId = ReadSetting(settings, "MS_AadClientID");
            string appKey   = ReadSetting(settings, "AadServiceAppKey");

            ClientCredential      clientCred  = new ClientCredential(clientId, appKey);
            string                authority   = string.Format(CultureInfo.InvariantCulture, AadInstance, tenant);
            AuthenticationContext authContext = new AuthenticationContext(authority);

            AuthenticationResult result = null;

            try
            {
                result = authContext.AcquireToken(GraphResourceId, clientCred);
            }
            catch (ActiveDirectoryAuthenticationException ex)
            {
                // If there is an issue acquiring the token, log the issue
                // and clear the cache, which will get a fresh token. If
                // the second call throws, let it bubble out.

                Trace.TraceError("Problem acquiring token: {0}", ex.ToString());
                authContext.TokenCacheStore.Clear();
                result = authContext.AcquireToken(GraphResourceId, clientCred);
            }

            return(result.AccessToken);
        }
Ejemplo n.º 22
0
 public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings)
 {
     // Not Applicable - used for federated identity flows
     return;
 }
Ejemplo n.º 23
0
        public static void Register()
        {
            ConfigOptions options = new ConfigOptions
            {
                PushAuthorization        = AuthorizationLevel.Application,
                DiagnosticsAuthorization = AuthorizationLevel.Anonymous,
            };

            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            // Now add any missing connection strings and app settings from the environment.
            // Any envrionment variables found with names that match existing connection
            // string and app setting names will be used to replace the value.
            // This allows the Web.config (which typically would contain secrets) to be
            // checked in, but requires people running the tests to config their environment.
            IServiceSettingsProvider  settingsProvider = config.DependencyResolver.GetServiceSettingsProvider();
            ServiceSettingsDictionary settings         = settingsProvider.GetServiceSettings();
            IDictionary environmentVariables           = Environment.GetEnvironmentVariables();

            foreach (var conKey in settings.Connections.Keys.ToArray())
            {
                var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == conKey);
                if (!string.IsNullOrEmpty(envKey))
                {
                    settings.Connections[conKey].ConnectionString = (string)environmentVariables[envKey];
                }
            }

            foreach (var setKey in settings.Keys.ToArray())
            {
                var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == setKey);
                if (!string.IsNullOrEmpty(envKey))
                {
                    settings[setKey] = (string)environmentVariables[envKey];
                }
            }

            // Emulate the auth behavior of the server: default is application unless explicitly set.
            config.Properties["MS_IsHosted"] = true;

            config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <RoundTripTableItem, RoundTripTableItemFakeStringId>()
                // While we would like to use ResolveUsing here, for ComplexType1 and 2,
                // we cannot because it is incompatable with LINQ queries, which is the
                // whole point of doing this mapping. Instead use AfterMap below.
                .ForMember(dst => dst.ComplexType1, map => map.Ignore())
                .ForMember(dst => dst.ComplexType2, map => map.Ignore())
                .ForMember(dst => dst.IntId, map => map.MapFrom(src => src.RoundTripTableItemId))
                .ForMember(dst => dst.Id, map => map.MapFrom(src => SqlFuncs.StringConvert(src.RoundTripTableItemId).Trim()))
                .AfterMap((src, dst) =>
                {
                    dst.ComplexType1 = src.ComplexType1Serialized == null ? null : JsonConvert.DeserializeObject <ComplexType[]>(src.ComplexType1Serialized);
                    dst.ComplexType2 = src.ComplexType2Serialized == null ? null : JsonConvert.DeserializeObject <ComplexType2>(src.ComplexType2Serialized);
                });
                cfg.CreateMap <RoundTripTableItemFakeStringId, RoundTripTableItem>()
                .ForMember(dst => dst.ComplexType1Serialized, map => map.ResolveUsing(src => (src.ComplexType1 == null ? null : JsonConvert.SerializeObject(src.ComplexType1))))
                .ForMember(dst => dst.ComplexType2Serialized, map => map.ResolveUsing(src => (src.ComplexType2 == null ? null : JsonConvert.SerializeObject(src.ComplexType2))))
                .ForMember(dst => dst.RoundTripTableItemId, map => map.MapFrom(src => src.Id));


                cfg.CreateMap <StringIdRoundTripTableItemForDB, StringIdRoundTripTableItem>()
                .ForMember(dst => dst.Complex, map => map.Ignore())
                .ForMember(dst => dst.ComplexType, map => map.Ignore())
                .AfterMap((src, dst) =>
                {
                    dst.Complex     = src.ComplexSerialized == null ? null : JsonConvert.DeserializeObject <string[]>(src.ComplexSerialized);
                    dst.ComplexType = src.ComplexTypeSerialized == null ? null : JsonConvert.DeserializeObject <string[]>(src.ComplexTypeSerialized);
                });
                cfg.CreateMap <StringIdRoundTripTableItem, StringIdRoundTripTableItemForDB>()
                .ForMember(dst => dst.ComplexSerialized, map => map.ResolveUsing(src => (src.Complex == null ? null : JsonConvert.SerializeObject(src.Complex))))
                .ForMember(dst => dst.ComplexTypeSerialized, map => map.ResolveUsing(src => (src.ComplexType == null ? null : JsonConvert.SerializeObject(src.ComplexType))));

                cfg.CreateMap <W8JSRoundTripTableItemForDB, W8JSRoundTripTableItem>()
                .ForMember(dst => dst.ComplexType, map => map.Ignore())
                .ForMember(dst => dst.Id, map => map.MapFrom(src => src.W8JSRoundTripTableItemForDBId))
                .AfterMap((src, dst) =>
                {
                    dst.ComplexType = src.ComplexTypeSerialized == null ? null : JsonConvert.DeserializeObject <string[]>(src.ComplexTypeSerialized);
                });
                cfg.CreateMap <W8JSRoundTripTableItem, W8JSRoundTripTableItemForDB>()
                .ForMember(dst => dst.ComplexTypeSerialized, map => map.ResolveUsing(src => (src.ComplexType == null ? null : JsonConvert.SerializeObject(src.ComplexType))))
                .ForMember(dst => dst.W8JSRoundTripTableItemForDBId, map => map.MapFrom(src => src.Id));
            });

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <SDKClientTestContext>());
        }
Ejemplo n.º 24
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }
            //modelBuilder.Entity<Apartment>().Property(x => x.Latitude).HasPrecision(20, 20);
            //modelBuilder.Entity<Apartment>().Property(x => x.Longitude).HasPrecision(20, 20);
            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            /***********************
            *       User          *
            ***********************/
            // User + Profile

            modelBuilder.Entity <User>()
            .HasOptional(s => s.Profile)
            .WithRequired(ad => ad.User)
            .WillCascadeOnDelete(false);

            // User + Account
            modelBuilder.Entity <User>()
            .HasMany(s => s.Accounts)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Apartment
            modelBuilder.Entity <User>()
            .HasMany(s => s.Apartments)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Card
            modelBuilder.Entity <User>()
            .HasMany(s => s.Cards)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Favorite
            modelBuilder.Entity <User>()
            .HasMany(s => s.Favorites)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Notification
            modelBuilder.Entity <User>()
            .HasMany(s => s.Notifications)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Reservation
            modelBuilder.Entity <User>()
            .HasMany(s => s.Reservations)
            .WithRequired(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            // User + Review
            modelBuilder.Entity <User>()
            .HasMany(s => s.OutReviews)
            .WithRequired(s => s.FromUser)
            .HasForeignKey(s => s.FromUserId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <User>()
            .HasMany(s => s.InReviews)
            .WithRequired(s => s.ToUser)
            .HasForeignKey(s => s.ToUserId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <User>()
            .HasMany(s => s.Feedbacks)
            .WithOptional(s => s.User)
            .HasForeignKey(s => s.UserId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <User>()
            .HasMany(s => s.Appeals)
            .WithOptional(s => s.Abuser)
            .HasForeignKey(s => s.AbuserId)
            .WillCascadeOnDelete(false);

            //Apartment
            modelBuilder.Entity <Apartment>()
            .HasMany(s => s.Cards)
            .WithOptional(s => s.Apartment)
            .HasForeignKey(s => s.ApartmentId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Apartment>()
            .HasMany(s => s.Pictures)
            .WithMany(c => c.Apartments)
            .Map(cs =>
            {
                cs.MapLeftKey("ApartmentRefId");
                cs.MapRightKey("PictureRefId");
                cs.ToTable("ApartmentPicture");
            });


            // Card

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Dates)
            .WithRequired(s => s.Card)
            .HasForeignKey(s => s.CardId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Genders)
            .WithRequired(s => s.Card)
            .HasForeignKey(s => s.CardId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Reservations)
            .WithRequired(s => s.Card)
            .HasForeignKey(s => s.CardId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Favorites)
            .WithRequired(s => s.Card)
            .HasForeignKey(s => s.CardId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Notifications)
            .WithOptional(s => s.Card)
            .HasForeignKey(s => s.CardId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Card>()
            .HasMany(s => s.Pictures)
            .WithMany(c => c.Cards)
            .Map(cs =>
            {
                cs.MapLeftKey("CardRefId");
                cs.MapRightKey("PictureRefId");
                cs.ToTable("CardPicture");
            });


            // Reservation
            modelBuilder.Entity <Reservation>()
            .HasMany(s => s.Notifications)
            .WithOptional(s => s.Reservation)
            .HasForeignKey(s => s.ReservationId)
            .WillCascadeOnDelete(false);


            // Review
            modelBuilder.Entity <Review>()
            .HasMany(s => s.Notifications)
            .WithOptional(s => s.Review)
            .HasForeignKey(s => s.ReviewId)
            .WillCascadeOnDelete(false);

            //Favorite
            modelBuilder.Entity <Favorite>()
            .HasMany(s => s.Notifications)
            .WithOptional(s => s.Favorite)
            .HasForeignKey(s => s.FavoriteId)
            .WillCascadeOnDelete(true);

            // Picture + Profile
            modelBuilder.Entity <Picture>()
            .HasMany(s => s.Profiles)
            .WithOptional(s => s.Picture)
            .HasForeignKey(s => s.PictureId);
        }
Ejemplo n.º 25
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }

            // I happen to like my table names to be singular
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            // set the Id column of every to be the PK
            modelBuilder.Properties <string>()
            .Where(p => p.Name == "Id")
            .Configure(p => p.IsKey());

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            modelBuilder.Entity <Profile>()
            .Property(m => m.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity <Training>()
            .Property(m => m.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity <School>()
            .Property(m => m.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity <Event>()
            .Property(m => m.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            modelBuilder.Entity <Location>()
            .Property(m => m.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // map Profile to Training and back
            modelBuilder.Entity <Training>().HasRequired(t => t.Profile)
            .WithMany(p => p.Training)
            .HasForeignKey(t => t.ProfileId);

            // map Event to Location and back
            modelBuilder.Entity <Event>().HasRequired(e => e.Location)
            .WithMany(l => l.Events)
            .HasForeignKey(e => e.LocationId);

            // map School to Location
            modelBuilder.Entity <School>().HasRequired(s => s.Location)
            .WithMany()
            .HasForeignKey(s => s.LocationId);

            // map Reviews to School and back
            modelBuilder.Entity <Review>().HasRequired(r => r.School)
            .WithMany(s => s.Reviews)
            .HasForeignKey(r => r.SchoolId);
        }
Ejemplo n.º 26
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            string schema = ServiceSettingsDictionary.GetSchemaName();

            if (!string.IsNullOrEmpty(schema))
            {
                modelBuilder.HasDefaultSchema(schema);
            }
            else
            {
                modelBuilder.HasDefaultSchema("dbo");
            }

            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention <TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));

            modelBuilder.Entity <Customer>()
            .Property(e => e.AdditionalContactNumber)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.County)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.FullName)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.HouseNumberOrName)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Id)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Latitude)
            .HasPrecision(9, 6);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Longitude)
            .HasPrecision(9, 6);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Postcode)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.PrimaryContactNumber)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Street)
            .IsUnicode(false);

            modelBuilder.Entity <Customer>()
            .Property(e => e.Town)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.Description)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.Id)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.EquipmentNumber)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.FullImage)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.Name)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .Property(e => e.ThumbImage)
            .IsUnicode(false);

            modelBuilder.Entity <Equipment>()
            .HasMany(e => e.Jobs)
            .WithMany(e => e.Equipments)
            .Map(m => m.ToTable("EquipmentIds").MapLeftKey("EquipmentId").MapRightKey("JobId"));

            modelBuilder.Entity <Job>()
            .Property(e => e.CustomerId)
            .IsUnicode(false);

            modelBuilder.Entity <Job>()
            .Property(e => e.EtaTime)
            .IsUnicode(false);

            modelBuilder.Entity <Job>()
            .Property(e => e.Id)
            .IsUnicode(false);

            modelBuilder.Entity <Job>()
            .Property(e => e.JobNumber)
            .IsUnicode(false);

            modelBuilder.Entity <Job>()
            .Property(e => e.Status)
            .IsUnicode(false);

            modelBuilder.Entity <Job>()
            .Property(e => e.Title)
            .IsUnicode(false);

            modelBuilder.Entity <JobHistory>()
            .Property(e => e.ActionBy)
            .IsUnicode(false);

            modelBuilder.Entity <JobHistory>()
            .Property(e => e.Comments)
            .IsUnicode(false);

            modelBuilder.Entity <JobHistory>()
            .Property(e => e.JobId)
            .IsUnicode(false);

            modelBuilder.Entity <JobHistory>()
            .Property(e => e.Id)
            .IsUnicode(false);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// This method does nothing in the default implementation. Override to customize behavior.
 /// </summary>
 /// <param name="appBuilder">Not used.</param>
 /// <param name="settings">Not used.</param>
 public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings)
 {
 }
 public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings)
 {
     return;
 }
Ejemplo n.º 29
0
 public MobileServiceContext()
     : base(connectionStringName)
 {
     this.Schema = ServiceSettingsDictionary.GetSchemaName();
 }
 public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings)
 {
     // Not Applicable - used for federated identity flows
     return;
 }
Ejemplo n.º 31
0
        private static string ReadSetting(ServiceSettingsDictionary settings, string settingName)
        {
            string settingValue;

            return(settings.TryGetValue(settingName, out settingValue) ? settingValue : null);
        }