public async Task <IActionResult> Create(TR sportTranslation, [FromForm] IFormFile imageSrc) { if (ModelState.IsValid) { try { if (imageSrc != null && sportTranslation is ITranslationWithImage withImage) { var image = await _imageService.AddImage(imageSrc); withImage.ImageId = image.Id; } _context.Add(sportTranslation); await _context.SaveChangesAsync(); return(RedirectToBaseEntity(sportTranslation.BaseEntityId)); } catch { ModelState.AddModelError("", "Такое сочетание ключей уже существует."); return(Create()); } } return(View(sportTranslation)); }
private void saveChanges_Click(object sender, EventArgs e) { var mainForm = (SoftCinemaForm)((Button)sender).Parent.Parent.Parent; mainForm.RenderSideBar(); try { string email = this.emailTextBox.Text; string phoneNumber = this.phoneNumberTextBox.Text; string password = this.passwordTextBox.Text; Models.Image profilePic = new Models.Image() { Content = imageBytes }; ImageService.AddImage(profilePic.Content); bool isDeleted = false; UserService.AddOrUpdateUser(user.Username, password, email, phoneNumber, (Role)user.Role, profilePic); user.ProfilePicture = profilePic; UserService.AddImageToUser(user, profilePic); UserService.AddImageToUser(MyAccountForm._currentUser, profilePic); MyAccountForm._currentUser = user; TopPanelForm.ShowGreetings(); } catch (Exception exception) { MessageBox.Show(Constants.ErrorMessages.UserUpdateErrorMesage); } SoftCinemaForm.SetContentHolderForm(new MyAccountForm()); }
public async Task <IActionResult> Edit([FromForm] UserModels.ProfileEdit model) { var user = await _db.Users.FindAsync(_userService.UserId); if (model.Email != null && user.Email.ToLower() != model.Email.ToLower()) { if (await _db.Users.AnyAsync(x => x.Email.ToLower() == model.Email.ToLower())) { return(BadRequest("Email is already being used")); } user.Email = model.Email; user.ConfirmationCodes.RemoveAll(x => x.Type == ConfirmationCode.Types.EmailConfirmation); } if (model.Name != null) { user.Name = model.Name; } if (model.AvatarSrc != null) { user.AvatarId = (await _imageService.AddImage(model.AvatarSrc)).Id; } if (model.PhoneNumber != null) { user.PhoneNumber = model.PhoneNumber; } await _db.SaveChangesAsync(); return(Ok(_userService.User.WithoutSensitive(false, true, true, true))); }
void AddImage() { DCT.ExecuteMainThread(d => { var openFile = new Microsoft.Win32.OpenFileDialog { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), FilterIndex = 2, RestoreDirectory = true }; if (openFile.ShowDialog() == true) { using (var client = new ImageService()) { var r = client.Ping(); Console.WriteLine($"Ping = {r}"); var bitmap = new BitmapImage(new Uri(openFile.FileName)); var bytes = ImageHelper.ConvertImageToByte(bitmap); client.AddImage(AddImageCallback, System.IO.Path.GetFileNameWithoutExtension(openFile.SafeFileName), bytes); } } }); }
private void addButton_Click(object sender, EventArgs e) { ImageService.AddImage(this.movieImageBytes); }