public ActionResult TaskSubmit(FormCollection formCollection) { // Create a new task if (formCollection["newTask"] != null && formCollection["newTask"].Length != 0) { TasksDbHelper.AddTask(formCollection["newTask"], ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value, ClaimsPrincipal.Current.FindFirst(Globals.GivennameClaimType).Value + ' ' + ClaimsPrincipal.Current.FindFirst(Globals.SurnameClaimType).Value); } // Change status of existing task if (formCollection["updateTasks"] != null) { foreach (string key in formCollection.Keys) { if (key.StartsWith("task-id:")) { TasksDbHelper.UpdateTask(Convert.ToInt32(key.Substring(key.IndexOf(':') + 1)), formCollection[key]); } } } // Delete a Task if (formCollection["delete"] != null && formCollection["delete"].Length > 0) { TasksDbHelper.DeleteTask(Convert.ToInt32(formCollection["delete"])); } return(RedirectToAction("Index", "Tasks")); }
public async Task <ActionResult> Share(string id) { AuthenticationHelper authHelper = new AuthenticationHelper(ConfigHelper.Authority, new ADALTokenCache(Util.GetSignedInUsersObjectIdFromClaims())); // Values Needed for the People Picker ViewData["tenant"] = ConfigHelper.TenantId; ViewData["token"] = await authHelper.GetOnBehalfOfAccessToken(ConfigHelper.GraphResourceId, ConfigHelper.PostLogoutRedirectUri); UserGroupsAndDirectoryRoles userGroupsAndDirectoryRoles = await TokenHelper.GetUsersGroupsAsync(ClaimsPrincipal.Current); List <string> userGroupsAndId = userGroupsAndDirectoryRoles.GroupIds; string userObjectId = Util.GetSignedInUsersObjectIdFromClaims(); userGroupsAndId.Add(userObjectId); ViewData["tasks"] = TasksDbHelper.GetAllTasks(userGroupsAndId); ViewData["userId"] = userObjectId; // Get the task details WebApp_GroupClaims_DotNet.Models.Task task = TasksDbHelper.GetTask(Convert.ToInt32(id)); if (task == null) { RedirectToAction("ShowError", "Error", new { message = "Task Not Found in DB." }); } ViewData["shares"] = task.SharedWith.ToList(); ViewData["taskText"] = task.TaskText; ViewData["taskId"] = task.TaskID; return(View()); }
public List <Models.Task> GetAll() { string userObjectId = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value; return(TasksDbHelper.GetAllTasks(new List <string> { userObjectId })); }
public async Task <ActionResult> Index() { string userObjectId = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value; ViewData["userId"] = userObjectId; ViewData["tenant"] = ClaimsPrincipal.Current.FindFirst(Globals.TenantIdClaimType).Value; ViewData["tasks"] = TasksDbHelper.GetAllTasks(new List <string> { userObjectId }); return(View()); }
public async Task <List <Models.Task> > GetAll() { List <object> tasks = new List <object>(); ClaimsIdentity userClaimsId = ClaimsPrincipal.Current.Identity as ClaimsIdentity; List <string> userGroupsAndId = await ClaimHelper.GetGroups(userClaimsId); string userObjectId = userClaimsId.FindFirst(Globals.ObjectIdClaimType).Value; userGroupsAndId.Add(userObjectId); return(TasksDbHelper.GetAllTasks(userGroupsAndId)); }
private void EnsureOwnerOfTask(int taskId) { // Check if the user is the owner of the task Models.Task task = TasksDbHelper.GetTask(taskId); string userObjectId = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value; if (task.Creator != userObjectId) { throw new HttpResponseException(HttpStatusCode.Forbidden); } }
public async Task <ActionResult> Index() { ClaimsIdentity userClaimsId = ClaimsPrincipal.Current.Identity as ClaimsIdentity; string userObjectId = userClaimsId.FindFirst(Globals.ObjectIdClaimType).Value; List <string> userGroupsAndId = await ClaimHelper.GetGroups(userClaimsId); userGroupsAndId.Add(userObjectId); ViewData["userId"] = userObjectId; ViewData["tenant"] = ClaimsPrincipal.Current.FindFirst(Globals.TenantIdClaimType).Value; ViewData["tasks"] = TasksDbHelper.GetAllTasks(userGroupsAndId); return(View()); }
private void EnsureAccessToTask(int taskId) { // Check if the user has permission to access the task string userObjectId = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value; List <Models.Task> tasks = TasksDbHelper.GetAllTasks(new List <string> { userObjectId }); if (tasks.Where(t => t.TaskID == taskId).Count() == 0) { throw new HttpResponseException(HttpStatusCode.Forbidden); } }
public Models.Task Create(Models.Task task) { // Create a new task if (task.TaskText != null && task.TaskText.Length != 0) { return(TasksDbHelper.AddTask(task.TaskText, ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value, ClaimsPrincipal.Current.FindFirst(Globals.GivennameClaimType).Value + ' ' + ClaimsPrincipal.Current.FindFirst(Globals.SurnameClaimType).Value)); } throw new HttpResponseException(HttpStatusCode.BadRequest); }
public ActionResult Create(string text) { // Create a new task if (text != null && text.Length != 0) { Models.Task task = TasksDbHelper.AddTask(text, ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value, ClaimsPrincipal.Current.FindFirst(Globals.GivennameClaimType).Value + ' ' + ClaimsPrincipal.Current.FindFirst(Globals.SurnameClaimType).Value); return(RedirectToAction("Index")); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public ActionResult Share(int taskId, string objectId, string displayName, string delete, string shareTasks) { // If the share button was clicked, share the task with the user or group if (shareTasks != null && objectId != null && objectId != string.Empty && displayName != null && displayName != string.Empty) { TasksDbHelper.AddShare(taskId, objectId, displayName); } // If a delete button was clicked, remove the share from the task if (delete != null && delete.Length > 0) { TasksDbHelper.DeleteShare(taskId, delete); } return(RedirectToAction("Share", new { id = taskId })); }
public List <Models.Share> GetShares(int id) { Models.Task task = TasksDbHelper.GetTask(id); List <Models.Share> shares = new List <Models.Share>(); foreach (Models.AadObject share in task.SharedWith) { if (share.AadObjectID != ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value) { shares.Add(new Models.Share { objectID = share.AadObjectID, displayName = share.DisplayName }); } } return(shares); }
public ActionResult Share(string id) { // Values Needed for the People Picker ViewData["tenant"] = ConfigHelper.Tenant; ViewData["token"] = GraphHelper.AcquireToken(ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value); // Get the task details WebAppGroupClaimsDotNet.Models.Task task = TasksDbHelper.GetTask(Convert.ToInt32(id)); if (task == null) { RedirectToAction("ShowError", "Error", new { message = "Task Not Found in DB." }); } ViewData["shares"] = task.SharedWith.ToList(); ViewData["taskText"] = task.TaskText; ViewData["taskId"] = task.TaskID; ViewData["userId"] = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value; return(View()); }
public List <Models.Share> GetShares(int id) { // Read the list of shares for the task EnsureAccessToTask(id); Models.Task task = TasksDbHelper.GetTask(id); List <Models.Share> shares = new List <Models.Share>(); foreach (Models.AadObject share in task.SharedWith) { // Don't show the client that the task is shared with the owner if (share.AadObjectID != ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value) { shares.Add(new Models.Share { objectId = share.AadObjectID, displayName = share.DisplayName }); } } return(shares); }
public async Task <ActionResult> Index() { try { // Get All Tasks User Can View ClaimsIdentity userClaimsId = ClaimsPrincipal.Current.Identity as ClaimsIdentity; List <string> userGroupsAndId = await ClaimHelper.GetGroups(userClaimsId); string userObjectId = userClaimsId.FindFirst(Globals.ObjectIdClaimType).Value; userGroupsAndId.Add(userObjectId); ViewData["tasks"] = TasksDbHelper.GetAllTasks(userGroupsAndId); ViewData["userId"] = userObjectId; return(View()); } catch (Exception e) { // Catch Both ADAL Exceptions and Web Exceptions return(RedirectToAction("ShowError", "Error", new { errorMessage = e.Message })); } }
public ActionResult TaskSubmit(FormCollection formCollection) { if (User.IsInRole("Admin") || User.IsInRole("Writer")) { // Add A New task to Tasks.xml if (formCollection["newTask"] != null && formCollection["newTask"].Length != 0) { TasksDbHelper.AddTask(formCollection["newTask"]); } } if (User.IsInRole("Admin") || User.IsInRole("Approver")) { // Change status of existing task foreach (string key in formCollection.Keys) { if (key != "newtask" && key != "delete") { TasksDbHelper.UpdateTask(Convert.ToInt32(key), formCollection[key]); } } } if (User.IsInRole("Admin")) { // Delete a Task foreach (string key in formCollection.Keys) { if (key == "delete" && formCollection[key] != null && formCollection[key].Length > 0) { string[] toDelete = formCollection[key].Split(','); foreach (string id in toDelete) { TasksDbHelper.DeleteTask(Convert.ToInt32(id)); } } } } return(RedirectToAction("Index", "Tasks")); }
public async Task <ActionResult> Index() { try { // Get All Tasks User Can View ClaimsIdentity userClaimsId = ClaimsPrincipal.Current.Identity as ClaimsIdentity; UserGroupsAndDirectoryRoles userGroupsAndDirectoryRoles = await TokenHelper.GetUsersGroupsAsync(ClaimsPrincipal.Current); List <string> userGroupsAndId = userGroupsAndDirectoryRoles.GroupIds; string userObjectId = Util.GetSignedInUsersObjectIdFromClaims(); userGroupsAndId.Add(userObjectId); ViewData["tasks"] = TasksDbHelper.GetAllTasks(userGroupsAndId); ViewData["userId"] = userObjectId; return(View()); } catch (Exception e) { // Catch Both ADAL Exceptions and Web Exceptions return(RedirectToAction("ShowError", "Error", new { errorMessage = e.Message })); } }
public ActionResult Index() { var bearerAccessToken = CreateBearerAccessToken(); if (string.IsNullOrWhiteSpace(bearerAccessToken)) { return(View()); } bool isSuccessResponseCode; var jsonText = SendRequestGetResponse("api/ToGoList", "GET", null, bearerAccessToken, out isSuccessResponseCode); var listOfTasks = new List <Models.Task>(); JArray jArray = JArray.Parse(jsonText); foreach (var item in jArray) { listOfTasks.Add(new Models.Task { TaskID = (int)item["ID"], TaskText = (string)item["Description"], Status = "Not Started" }); } ViewBag.Message = "Tasks"; if (isSuccessResponseCode == true) { ViewData["tasks"] = listOfTasks; } else { ViewData["tasks"] = TasksDbHelper.GetAllTasks(); } return(View()); }
public Models.Task Get(int id) { List <object> tasks = new List <object>(); return(TasksDbHelper.GetTask(id)); }
public void UpdateShares(int id, List <Models.Share> shares) { // Update the list of shares for the task EnsureOwnerOfTask(id); TasksDbHelper.UpdateShares(id, shares); }
public void Delete(int id) { // Delete an existing task EnsureOwnerOfTask(id); TasksDbHelper.DeleteTask(id); }
public Models.Task Update(int id, Models.Task task) { // Update an existing task EnsureAccessToTask(id); return(TasksDbHelper.UpdateTask(id, task.Status)); }
public Models.Task Get(int id) { EnsureAccessToTask(id); return(TasksDbHelper.GetTask(id)); }
public Models.Task Update(int id, Models.Task task) { return(TasksDbHelper.UpdateTask(id, task.Status)); }
public void Delete(int id) { TasksDbHelper.DeleteTask(id); }
public void UpdateShares(int id, List <Models.Share> shares) { TasksDbHelper.UpdateShares(id, shares); }
public ActionResult Index() { ViewBag.Message = "Tasks"; ViewData["tasks"] = TasksDbHelper.GetAllTasks(); return(View()); }