public async Task<int> CreateUser(user newUser)
 {
     using (var context = new appsterEntities())
     {
         var checkData = context.users.FirstOrDefault(i => i.username == newUser.username || i.email == newUser.email);
         if (checkData == null)
         {
             context.users.Add(newUser);
             await context.SaveChangesAsync();
             return newUser.id;
         }
         else
         {
             if (checkData.username == newUser.username) throw new AppsUsernameAlreadyExistException();
             if (checkData.email == newUser.email) throw new AppsEmailAlreadyExistException();
         }
         throw new AppsDatabaseExecutionException();
     }
 }
 public async Task UpdateUser(user updatedUser)
 {
     if (!GetRoles().Any(i => i.id == updatedUser.role_id)) throw new AppsRequiredDataIsNullException();
     using (var context = new appsterEntities())
     {
         var checkData = context.users.SingleOrDefault(i => i.id != updatedUser.id &&
                         (i.username == updatedUser.username || i.email == updatedUser.email));
         if (checkData == null)
         {
             context.users.Add(updatedUser);
             context.Entry(updatedUser).State = System.Data.Entity.EntityState.Modified;
             await context.SaveChangesAsync();
         }
         else
         {
             if (checkData.username == updatedUser.username) throw new AppsUsernameAlreadyExistException();
             if (checkData.email == updatedUser.email) throw new AppsEmailAlreadyExistException();
         }
     }
 }