// POST api/todolist public async Task Post(TodoItem todo) { if (!ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value.Contains("access_as_user")) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'access_as_user' or scope claim not found" }); } // // Call the Graph API On Behalf Of the user who called the To Do list web API. // string dsiplayName = string.Empty; UserProfile profile = await CallGraphAPIOnBehalfOfUser(); if (profile != null) { dsiplayName = profile.DisplayName; } if (!string.IsNullOrWhiteSpace(todo.Title)) { db.TodoItems.Add(new TodoItem { Title = todo.Title, Owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name).Value, DisplayName = dsiplayName }); db.SaveChanges(); } }
// POST: api/TodoList public void Post(Todo todo) { string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; todo.Owner = owner; db.Todoes.Add(todo); db.SaveChanges(); }
public Todo Post(Todo todo) { string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; todo.Owner = owner; if (string.IsNullOrEmpty(todo.Description)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } db.Todoes.Add(todo); db.SaveChanges(); return(todo); }
// POST api/todolist public async Task Post(TodoItem todo) { if (!ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value.Contains("user_impersonation")) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found" }); } // // Call the Graph API On Behalf Of the user who called the To Do list web API. // string augmentedTitle = null; UserProfile profile = await CallGraphAPIOnBehalfOfUser(); if (profile != null) { augmentedTitle = String.Format("{0}, First Name: {1}, Last Name: {2}", todo.Title, profile.GivenName, profile.Surname); } else { augmentedTitle = todo.Title; } if (!string.IsNullOrWhiteSpace(todo.Title)) { db.TodoItems.Add(new TodoItem { Title = augmentedTitle, Owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value }); db.SaveChanges(); } }
public void Post(Todo todo) { db.Todoes.Add(todo); db.SaveChanges(); }