Esempio n. 1
0
 async void SaveClicked(object sender, EventArgs e)
 {
     try
     {
         theClass.TypeID = getClassTypeID();
         if (theClass.TypeID > 0)
         {
             ClassRepository cl = new ClassRepository();
             if (theClass.ID == 0)
             {
                 await cl.AddClass(theClass);
             }
             else
             {
                 await cl.UpdateClass(theClass);
             }
             thisApp.needClassRefresh = true;
             await Navigation.PopAsync();
         }
         else
         {
             await DisplayAlert("Class Type Not Selected:", "You must set the type of your class.", "Ok");
         }
     }
     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);
         }
         thisApp.needClassRefresh = true;
         await DisplayAlert("Problem Saving 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");
         }
     }
 }
Esempio n. 2
0
        public async Task <ActionResult <Class> > AddClass(Class newClass)
        {
            return(await cr.AddClass(HttpContext.Items["UserID"].ToString(), newClass));

            /*var newClass = new Class
             * {
             *  name = name,
             *  color = color,
             *  icon = icon
             * };*/
            collection.InsertOne(newClass);
            return(newClass);
        }