예제 #1
0
        public async Task <IActionResult> ClassDelete(ClassModel model)
        {
            var user = await userManager.GetUserAsync(User);

            ClassRepository repo = new ClassRepository(configModel.ConnectionString);
            ClassModel      dbClass;

            // Ensure that ONLY staff accounts have access to this API endpoint
            if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()))
            {
                return(Utilities.ErrorJson("Not authorized"));
            }

            // Verify that a valid class id was provided
            dbClass = repo.GetClass(model.Id);
            if (dbClass == null)
            {
                return(Utilities.ErrorJson("Invalid class id"));
            }

            try
            {
                repo.DeleteClass(model.Id);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(Utilities.NoErrorJson());
        }
예제 #2
0
        public async Task <ActionResult <Class> > DeleteClass(string classid)
        {
            return(await cr.DeleteClass(HttpContext.Items["UserID"].ToString(), classid));

            var deleted = collection.FindOneAndDelete(item => item.ID == classid);

            return(deleted);
        }
예제 #3
0
        async void DeleteClicked(object sender, EventArgs e)
        {
            var answer = await DisplayAlert("Confirm Delete", "Are you certain that you want to delete " + theClass.Name + "?", "Yes", "No");

            if (answer == true)
            {
                try
                {
                    ClassRepository cl = new ClassRepository();
                    await cl.DeleteClass(theClass);

                    thisApp.needClassRefresh = true;
                    await Navigation.PopAsync();
                }
                catch (AggregateException ex)
                {
                    string errMsg = "";
                    foreach (var exception in ex.InnerExceptions)
                    {
                        errMsg += Environment.NewLine + exception.Message;
                    }
                    await DisplayAlert("One or more exceptions has occurred:", errMsg, "Ok");
                }
                catch (ApiException apiEx)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("Errors:");
                    foreach (var error in apiEx.Errors)
                    {
                        sb.AppendLine("-" + error);
                    }
                    await DisplayAlert("Problem Deleting the Class:", sb.ToString(), "Ok");
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException().Message.Contains("connection with the server"))
                    {
                        await DisplayAlert("Error", "No connection with the server.", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Error", "Could not complete operation.", "Ok");
                    }
                }
            }
        }
예제 #4
0
 public void DeleteClass(int id)
 {
     Repository.DeleteClass(id);
 }