Navigation Menu

Skip to content

Commit

Permalink
Azure Mobile Apps sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyCW committed Jun 1, 2015
1 parent 3e48a25 commit 2754a69
Show file tree
Hide file tree
Showing 18 changed files with 708 additions and 217 deletions.
22 changes: 22 additions & 0 deletions AzureMobileApps/UWPDevMVA_Runtime/UWPDevMVA.sln
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UWPDevMVAService", "UWPDevMVAService\UWPDevMVAService.csproj", "{209FA716-A7AD-4095-BD70-C8710FC66FA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{209FA716-A7AD-4095-BD70-C8710FC66FA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{209FA716-A7AD-4095-BD70-C8710FC66FA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{209FA716-A7AD-4095-BD70-C8710FC66FA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{209FA716-A7AD-4095-BD70-C8710FC66FA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Web.Http;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.AppService.Config;
using UWPDevMVAService.DataObjects;
using UWPDevMVAService.Models;

namespace UWPDevMVAService
{
public static class WebApiConfig
{
public static void Register()
{
AppServiceExtensionConfig.Initialize();

// 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 UWPDevMVAInitializer());
}
}

public class UWPDevMVAInitializer : ClearDatabaseSchemaIfModelChanges<UWPDevMVAContext>
{
protected override void Seed(UWPDevMVAContext context)
{
List<TodoItem> todoItems = new List<TodoItem>
{
new TodoItem { Id = Guid.NewGuid().ToString(), Text = "First item", Complete = false },
new TodoItem { Id = Guid.NewGuid().ToString(), Text = "Second item", Complete = false },
};

foreach (TodoItem todoItem in todoItems)
{
context.Set<TodoItem>().Add(todoItem);
}

base.Seed(context);
}
}
}

@@ -0,0 +1,52 @@
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.OData;
using Microsoft.Azure.Mobile.Server;
using UWPDevMVAService.DataObjects;
using UWPDevMVAService.Models;

namespace UWPDevMVAService.Controllers
{
public class TodoItemController : TableController<TodoItem>
{
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
UWPDevMVAContext context = new UWPDevMVAContext();
DomainManager = new EntityDomainManager<TodoItem>(context, Request, Services);
}

// GET tables/TodoItem
public IQueryable<TodoItem> GetAllTodoItems()
{
return Query();
}

// GET tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public SingleResult<TodoItem> GetTodoItem(string id)
{
return Lookup(id);
}

// PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task<TodoItem> PatchTodoItem(string id, Delta<TodoItem> patch)
{
return UpdateAsync(id, patch);
}

// POST tables/TodoItem
public async Task<IHttpActionResult> PostTodoItem(TodoItem item)
{
TodoItem current = await InsertAsync(item);
return CreatedAtRoute("Tables", new { id = current.Id }, current);
}

// DELETE tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task DeleteTodoItem(string id)
{
return DeleteAsync(id);
}
}
}
@@ -0,0 +1,11 @@
using Microsoft.Azure.Mobile.Server;

namespace UWPDevMVAService.DataObjects
{
public class TodoItem : EntityData
{
public string Text { get; set; }

public bool Complete { get; set; }
}
}
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="UWPDevMVAService.WebApiApplication" Language="C#" %>
13 changes: 13 additions & 0 deletions AzureMobileApps/UWPDevMVA_Runtime/UWPDevMVAService/Global.asax.cs
@@ -0,0 +1,13 @@
using System.Web.Http;
using System.Web.Routing;

namespace UWPDevMVAService
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
WebApiConfig.Register();
}
}
}
@@ -0,0 +1,44 @@
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Tables;
using UWPDevMVAService.DataObjects;

namespace UWPDevMVAService.Models
{
public class UWPDevMVAContext : DbContext
{
// You can add custom code to this file. Changes will not be overwritten.
//
// If you want Entity Framework to alter your database
// automatically whenever you change your model schema, please use data migrations.
// For more information refer to the documentation:
// http://msdn.microsoft.com/en-us/data/jj591621.aspx
//
// To enable Entity Framework migrations in the cloud, please ensure that the
// service name, set by the 'MS_MobileServiceName' AppSettings in the local
// Web.config, is the same as the service name when hosted in Azure.
private const string connectionStringName = "Name=MS_TableConnectionString";

public UWPDevMVAContext() : base(connectionStringName)
{
}

public DbSet<TodoItem> TodoItems { get; set; }

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()));
}
}

}
Expand Up @@ -2,28 +2,34 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UWPDevMVA")]
[assembly: AssemblyTitle("UWPDevMVAService")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuickStart")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyProduct("UWPDevMVAService")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2e8cfaa1-3743-49ef-9e21-2926ca18c058")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]

0 comments on commit 2754a69

Please sign in to comment.