public IHttpActionResult UpdateTestStructure(int AdminId, TestStructure testStructure)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         TestStructure oldData = db.TestStructures /*.AsNoTracking()*/.Where(ts => ts.Id == testStructure.Id).FirstOrDefault();
         if (oldData == null || !oldData.IsCurrent)
         {
             return(NotFound());
         }
         oldData.SetProperties(AdminId: AdminId, IsCurrent: false /*, SetNumberOfQuestions: false*/);
         db.SaveChanges();
         testStructure.Id = 0;
         if (testStructure.SetProperties(AdminId: AdminId))
         {
             db.TestStructures.Add(testStructure);
             try
             {
                 db.SaveChanges();
             }
             catch (DbUpdateException)
             {
                 if (TestStructureExists(testStructure.Id))
                 {
                     return(Conflict());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(Ok(testStructure));
         }
         return(BadRequest());
     }
 }
 public IHttpActionResult AddTestStructure(int AdminId, TestStructure testStructure)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         if (TestStructureExists(testStructure.Technology, testStructure.Level))
         {
             return(Ok(new TestStructure()));
         }
         if (testStructure.SetProperties(AdminId: AdminId))
         {
             db.TestStructures.Add(testStructure);
             try
             {
                 db.SaveChanges();
             }
             catch (DbUpdateException)
             {
                 if (TestStructureExists(testStructure.Id))
                 {
                     return(Conflict());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(CreatedAtRoute("DefaultApi", new { id = testStructure.Id }, testStructure));
         }
         return(BadRequest());
     }
 }
 public IHttpActionResult DeleteTestStructure(int AdminId, int TestStructureId)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         TestStructure testStructure = db.TestStructures.Find(TestStructureId);
         if (testStructure == null || !testStructure.IsCurrent)
         {
             return(NotFound());
         }
         testStructure.SetProperties(AdminId: AdminId, IsCurrent: false /*, SetNumberOfQuestions: false*/);
         db.SaveChanges();
         return(Ok(testStructure));
     }
 }