public async Task <IActionResult> NewPassword([FromBody] PasswordRegister password) { if (password == null) { return(BadRequest("Non optional fields cannot be empty.")); } var user = await _repo.GetUser(password.UserId); if (user == null) { ModelState.AddModelError("UserId", "User does not exists."); } if (await _repo.PasswordExists(password.Name, password.UserId)) { ModelState.AddModelError("Name", "Password name already exists in the database."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newPassword = _mapper.Map <Password>(password); newPassword.Created = DateTime.Now; newPassword.Updated = DateTime.Now; await _repo.AddPassword(newPassword, user.UserKey); if (await _repo.SaveAll()) { return(StatusCode(201)); } return(BadRequest()); }
private async void EncodeImage(long initialSeed, byte tap, byte numberOfBits, bool alpha) { if (!alpha) { Register register = new Register(initialSeed, tap, numberOfBits); // O(1) long pixelsDone = 0; // UI Stopwatch watch = new Stopwatch(); //UI lblTimeTaken.Visible = true; //UI lblStatus.Text = "Encoding Image..."; watch.Start(); //UI for (int i = 0; i < ImageHeight; i++) // O(N^2) { await Task.Run(() => { for (int j = 0; j < ImageWidth; j++) //O(N^2) { ImageMatrix[i, j].red ^= (byte)register.StepK(8); // O(1) ImageMatrix[i, j].green ^= (byte)register.StepK(8); //O(1) ImageMatrix[i, j].blue ^= (byte)register.StepK(8); //O(1) pixelsDone++; // UI } }). ContinueWith((ant) => { //lblStatus.Text = "Encoding " + pixelsDone + " pixels / " + (ImageHeight * ImageWidth) + " pixels : " + ((long)(pixelsDone * 100) / (ImageHeight * ImageWidth)) string te = watch.Elapsed.ToString(@"m\:ss"); lblTimeTaken.Text = "Time Elapsed : " + te; } , TaskScheduler.FromCurrentSynchronizationContext()); } watch.Stop(); string tsOut = watch.Elapsed.ToString(@"m\:ss"); lblTimeTaken.Text = "Time Elapsed : " + tsOut; lblStatus.Text = "Image Encoded."; ImageOperations.DisplayImage(ImageMatrix, pictureBox2); } else { PasswordRegister register = new PasswordRegister(txtInitialSeed.Text, TapPosition); // O(1) long pixelsDone = 0; // UI Stopwatch watch = new Stopwatch(); //UI lblTimeTaken.Visible = true; //UI lblStatus.Text = "Encoding Image..."; watch.Start(); //UI for (int i = 0; i < ImageHeight; i++) { await Task.Run(() => { for (int j = 0; j < ImageWidth; j++) { ImageMatrix[i, j].red ^= (byte)register.StepK(8); ImageMatrix[i, j].green ^= (byte)register.StepK(8); ImageMatrix[i, j].blue ^= (byte)register.StepK(8); pixelsDone++; // UI } }). ContinueWith((ant) => { //lblStatus.Text = "Encoding " + pixelsDone + " pixels / " + (ImageHeight * ImageWidth) + " pixels : " + ((long)(pixelsDone * 100) / (ImageHeight * ImageWidth)) string te = watch.Elapsed.ToString(@"m\:ss"); lblTimeTaken.Text = "Time Elapsed : " + te; } , TaskScheduler.FromCurrentSynchronizationContext()); } watch.Stop(); string tsOut = watch.Elapsed.ToString(@"m\:ss"); lblTimeTaken.Text = "Time Elapsed : " + tsOut; lblStatus.Text = "Image Encoded."; ImageOperations.DisplayImage(ImageMatrix, pictureBox2); } //ImageColorFrequencies.GenerateFromImage(ImageMatrix); }