Skip to content

Commit

Permalink
Merge pull request #135 from HTBox/revert-134-133-Xamarin
Browse files Browse the repository at this point in the history
Revert "#133 xamarin project"
  • Loading branch information
rockfordlhotka committed May 7, 2016
2 parents e6c49aa + 102d9a8 commit e85fa71
Show file tree
Hide file tree
Showing 343 changed files with 174,208 additions and 8,396 deletions.
66 changes: 66 additions & 0 deletions src/MCM.KidsIdApp.MobileApi/App_Start/Startup.MobileApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Web.Http;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Authentication;
using Microsoft.Azure.Mobile.Server.Config;
using MCM.KidsIdApp.MobileApp.DataObjects;
using MCM.KidsIdApp.MobileApp.Models;
using Owin;

namespace MCM.KidsIdApp.MobileApp
{
public partial class Startup
{
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();

new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);

// Use Entity Framework Code First to create database tables based on your DbContext
Database.SetInitializer(new MobileServiceInitializer());

MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

if (string.IsNullOrEmpty(settings.HostName))
{
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
// This middleware is intended to be used locally for debugging. By default, HostName will
// only have a value when running in an App Service application.
SigningKey = ConfigurationManager.AppSettings["SigningKey"],
ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}

app.UseWebApi(config);
}
}

public class MobileServiceInitializer : CreateDatabaseIfNotExists<MobileServiceContext>
{
protected override void Seed(MobileServiceContext 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);
}
}
}

47 changes: 47 additions & 0 deletions src/MCM.KidsIdApp.MobileApi/Controllers/EmailController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using MCM.KidsIdApp.MobileApp.DataObjects;
using Microsoft.Azure.Mobile.Server.Config;
using SendGrid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mail;
using System.Web.Http;
using System.Threading.Tasks;
using System.Configuration;

namespace MCM.KidsIdApp.MobileApp.Controllers
{
[MobileAppController]
public class EmailController : ApiController
{
// POST: api/Email
public HttpResponseMessage Post([FromBody]dynamic value)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(value.emailAddress.ToString());
myMessage.From = new MailAddress(
ConfigurationManager.AppSettings["EmailFromAddress"],
ConfigurationManager.AppSettings["EmailFromName"]
);
myMessage.Subject = "Your KidsID Profile Details";
myMessage.Text = GetFormattedBody(value.profile);

var transportWeb = new Web(ConfigurationManager.AppSettings["SendGridApiKey"]);
transportWeb.DeliverAsync(myMessage);
//this seems awfully happy-path to me, y'know
HttpResponseMessage m = new HttpResponseMessage(HttpStatusCode.OK);
return m;
}

private string GetFormattedBody(dynamic profile)
{
string body = "You are recieving this email because a user of the KidsID app is sending you profile information for a child." + Environment.NewLine + Environment.NewLine;
body += "Profile details have been attached, but only those that you selected." + Environment.NewLine + Environment.NewLine;
body += "Authorities can use this data to communicate or create alerts for a child. Forward this email to authorities if necessary." + Environment.NewLine + Environment.NewLine;
body += profile.ToString() + Environment.NewLine + Environment.NewLine;
return body;
}
}
}
52 changes: 52 additions & 0 deletions src/MCM.KidsIdApp.MobileApi/Controllers/TodoItemController.cs
Original file line number Diff line number Diff line change
@@ -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 MCM.KidsIdApp.MobileApp.DataObjects;
using MCM.KidsIdApp.MobileApp.Models;

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

// 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);
}
}
}
23 changes: 23 additions & 0 deletions src/MCM.KidsIdApp.MobileApi/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Web.Http;
using Microsoft.Azure.Mobile.Server.Config;

namespace MCM.KidsIdApp.MobileApp.Controllers
{
// Use the MobileAppController attribute for each ApiController you want to use
// from your mobile clients
[MobileAppController]
public class ValuesController : ApiController
{
// GET api/values
public string Get()
{
return "Hello World!";
}

// POST api/values
public string Post()
{
return "Hello World!";
}
}
}
11 changes: 11 additions & 0 deletions src/MCM.KidsIdApp.MobileApi/DataObjects/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Azure.Mobile.Server;

namespace MCM.KidsIdApp.MobileApp.DataObjects
{
public class TodoItem : EntityData
{
public string Text { get; set; }

public bool Complete { get; set; }
}
}
Loading

0 comments on commit e85fa71

Please sign in to comment.