Untitled

mail@pastecode.io avatar
unknown
plain_text
6 days ago
2.8 kB
6
Indexable
Never
   public string coursecode { get; set; }
   public string coursename { get; set; }



   public async Task<bool> _AddCourse(string _coursecode, string _CourseName)
   {
       var course = new Course()
       {
           coursecode = _coursecode,
           coursename = _CourseName
       };
       await client.Child("Course").PostAsync(course);
       return true;

   }

   public async Task<List<Course>> GetCourses()
   {
       return (await client
           .Child("Course")
           .OnceAsync<Course>()).Select(item => new Course
       { coursecode= item.Object.coursecode,
           coursename = item.Object.coursename,
          
       }).ToList();
   }

   public async Task<bool> GetCoursecode(String _coursecd)
   {
       try
       {
           var evaluatecoursecode =
               (await client.Child("Course").OnceAsync<Course>()).FirstOrDefault(a =>
                   a.Object.coursecode == _coursecd);
           if (evaluatecoursecode != null)
           {
               return false;
           }
           else
           {
               return true;
           }

       }
       catch
       {
           return false;
       }

   }


   public async Task<string> GetCourseKey(string _coursecode)
   {

       var evaluateID =
           (await client.Child("Course").OnceAsync<Course>()).FirstOrDefault(a =>
               a.Object.coursecode == _coursecode);
       if (evaluateID != null)
       {
           courseKey1 = evaluateID.Key;
           coursecode1 = evaluateID.Object.coursecode;
           coursename1 = evaluateID.Object.coursename;
           return evaluateID.Key;
       }

       return null;

   }

   public async Task<bool> _EditCourse(String coursecode, String coursname)
   {
       var course = new Course()
       {
           coursecode = coursecode,
           coursename = coursname
         
       };
       await client.Child($"Course/{courseKey1}").PatchAsync(course);
       return true;


   }


   public async Task<bool> _DeleteCourse(String coursecode)
   {
       try
       {
           var getcourseKey = (await client
               .Child("Course")
               .OnceAsync<Course>()).FirstOrDefault
               (a => a.Object.coursecode == coursecode);
           if (getcourseKey != null)
           {
               await client
                   .Child("Course")
                   .Child(getcourseKey.Key)
                   .DeleteAsync();
               client.Dispose();
               return true;
           }

           client.Dispose();
           return false;
       }
       catch
       {
           client.Dispose();
           return false;
       }

   }
Leave a Comment