public HttpResponseMessage AddAdmin(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         if (Permitted(postAdmin.adminInfo.UserName, new int[] { 1 }))
         {
             if (postAdmin.request is AddAdminRequest)
             {
                 if ((((AddAdminRequest)postAdmin.request).addAdmin.Permissions.Length != 0 && Permitted(postAdmin.adminInfo.UserName, new int[] { 4 })) || ((AddAdminRequest)postAdmin.request).addAdmin.Permissions.Length == 0)
                 {
                     mySqlCom.AddAdmin(((AddAdminRequest)postAdmin.request).addAdmin);
                 }
                 else
                 {
                     return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, BadRequestCannotSetPermission));
                 }
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, BadRequestCantDeserialize));
             }
         }
         else
         {
             throw new HttpResponseException(HttpStatusCode.Forbidden);
         }
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
 public void AlterDataPermissions(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         if (Permitted(postAdmin.adminInfo.UserName, new int[] { 3, 4 }))
         {
             if (postAdmin.request is ChangePermissionRequest)
             {
                 mySqlCom.AlterPermissions(((ChangePermissionRequest)postAdmin.request).changePermission);
             }
             else
             {
                 throw new HttpResponseException(HttpStatusCode.BadRequest);
             }
         }
         else
         {
             throw new HttpResponseException(HttpStatusCode.Forbidden);
         }
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public bool Exists(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         return(this.mySqlCom.Exists((ExistsRequest)postAdmin.request));
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public Data GetSqlData(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         Data d = new Data(((GetDataRequest)postAdmin.request).getData);
         return(d);
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public void ChangeEmail(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         int?id = this.mySqlCom.GetAdminId(postAdmin.adminInfo.UserName);
         if (id == null)
         {
             throw new Exception("No admin with such name");
         }
         this.mySqlCom.UpdateEmail((int)id, ((EditEmailRequest)postAdmin.request));
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public string DeleteRow(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo) && (((DeleteRowRequest)postAdmin.request).TableName == "tbAdminAccounts" || ((DeleteRowRequest)postAdmin.request).TableName == "tbDaemons" || ((DeleteRowRequest)postAdmin.request).TableName == "tbTasks"))
     {
         if (Permitted(postAdmin.adminInfo.UserName, new int[] { 3 }))
         {
             this.mySqlCom.DeleteRow((DeleteRowRequest)postAdmin.request);
             return(null);
         }
         throw new HttpResponseException(HttpStatusCode.Forbidden);
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public TimerTicks GetTimerDaemon(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         if (Permitted(postAdmin.adminInfo.UserName, new int[] { 3 }))
         {
             return(mySqlCom.GetTimerTick(((GetTimerDaemonRequest)postAdmin.request).DaemonId));
         }
         else
         {
             throw new HttpResponseException(HttpStatusCode.Forbidden);
         }
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public void SetTask(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         var i = ((SetTasksRequest)postAdmin.request).setTasks;
         foreach (var item in i)
         {
             if (item.Sources == null || item.ExecutionTimes == null || item.ExecutionTimes.ExecutionTimes == null || item.ExecutionTimes.ExecutionTimes.Count == 0 || item.Destinations == null || item.DaemonId < 0 || item.Destinations.Count < 1)
             {
                 throw new HttpResponseException(HttpStatusCode.BadRequest);
             }
         }
         mySqlCom.SetTasks(((SetTasksRequest)postAdmin.request).setTasks);
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public void UpdatePassword(PostAdmin postAdmin)
 {
     if (this.Authorized(postAdmin.adminInfo))
     {
         if (((ChangePasswordRequest)postAdmin.request).newPasswordInBase64.Length < 6)
         {
             throw new HttpResponseException(HttpStatusCode.BadRequest);
         }
         if (Permitted(postAdmin.adminInfo.UserName, new int[] { 3, 5 }) || postAdmin.adminInfo.UserName == ((ChangePasswordRequest)postAdmin.request).targetUsername)
         {
             mySqlCom.UpdatePassword(((ChangePasswordRequest)postAdmin.request).newPasswordInBase64, ((ChangePasswordRequest)postAdmin.request).targetUsername);
         }
         else
         {
             throw new HttpResponseException(HttpStatusCode.Forbidden);
         }
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
 public void AlterTable(PostAdmin postAdmin)
 {
     if (postAdmin.request is ChangeTableRequest)
     {
         if (this.Authorized(postAdmin.adminInfo))
         {
             if (Permitted(postAdmin.adminInfo.UserName, new int[] { 3 }))
             {
                 if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "Allowed" &&
                     ((ChangeTableRequest)postAdmin.request).changeTable.Value is bool)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "IdDaemon" &&
                          ((ChangeTableRequest)postAdmin.request).changeTable.Value is int)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "Enabled" &&
                          ((ChangeTableRequest)postAdmin.request).changeTable.Value is bool)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "Email" &&
                          ((ChangeTableRequest)postAdmin.request).changeTable.Value is string)
                 {
                     mySqlCom.AlterTable(new ChangeTable()
                     {
                         ColumnName = "RecievingEmail", Id = (int)mySqlCom.GetAdminId(postAdmin.adminInfo.UserName), TableName = "tbEmailPreferences", Value = ((ChangeTableRequest)postAdmin.request).changeTable.Value
                     }, "IdAdmin");
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "Username" &&
                          !mySqlCom.Exists(new ExistsRequest()
                 {
                     Column = ((ChangeTableRequest)postAdmin.request).changeTable.ColumnName,
                     TableName = ((ChangeTableRequest)postAdmin.request).changeTable.TableName,
                     Value = ((ChangeTableRequest)postAdmin.request).changeTable.Value
                 }))
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "TimerTick" &&
                          (((ChangeTableRequest)postAdmin.request).changeTable.Value is long) || ((ChangeTableRequest)postAdmin.request).changeTable.Value is int)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "TimerOnStart" &&
                          (((ChangeTableRequest)postAdmin.request).changeTable.Value is long) || ((ChangeTableRequest)postAdmin.request).changeTable.Value is int)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else if (((ChangeTableRequest)postAdmin.request).changeTable.ColumnName == "TimerAfterFail" &&
                          (((ChangeTableRequest)postAdmin.request).changeTable.Value is long) || ((ChangeTableRequest)postAdmin.request).changeTable.Value is int)
                 {
                     mySqlCom.AlterTable(((ChangeTableRequest)postAdmin.request).changeTable);
                 }
                 else
                 {
                     throw new HttpResponseException(HttpStatusCode.BadRequest);
                 }
             }
             else
             {
                 throw new HttpResponseException(HttpStatusCode.Forbidden);
             }
         }
         else
         {
             throw new HttpResponseException(HttpStatusCode.Unauthorized);
         }
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
 }