public ActionResult Edit(UserDto user, HttpPostedFileBase image) { if (image != null) { var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png", "image/gif", "image/tif" }; if (allowedContentTypes.Contains(image.ContentType)) { var imagesPath = "/Content/UserImages/"; var filename = Guid.NewGuid().ToString() + image.FileName; var uploadPath = imagesPath + filename; var physicalPath = Server.MapPath(uploadPath); image.SaveAs(physicalPath); user.UserImage = uploadPath; } } else { return(RedirectToAction("Edit")); } OpUserUpdate op = new OpUserUpdate(); op.UserDto = user; OperationResult result = OperationManager.Singleton.ExecuteOperation(op); TempData["Success"] = "Updated Successfully!"; return(RedirectToAction("Index")); }
protected void btnUserUpdateFunction_Click(object sender, EventArgs e) { int id = Convert.ToInt32(tbIdUser.Text); string user = tbUserName.Text; string pass = tbPassword.Text; string mail = tbMail.Text; int userFunction = Convert.ToInt32(ddlFunctionUser.SelectedValue); OpUserUpdate oud = new OpUserUpdate(); oud.User = new UserDb { IdUser = id, UserName = user, Password = pass, Mail = mail, IdFunction = userFunction }; OperationResult obj = OperationManager.Singleton.executeOperation(oud); if ((obj == null) || (!obj.Status)) { return; } else { Response.Redirect(Request.RawUrl); GridView1.DataSource = obj.DbItems; GridView1.DataBind(); } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { string password = passwordInfo.Password.ToString(); string rePassword = rePasswordInfo.Password.ToString(); int id = documentManagerVM.CurrentUserVM.Model.Id; string fullName = documentManagerVM.CurrentUserVM.Model.FullName; string username = documentManagerVM.CurrentUserVM.Model.UserName; string image = documentManagerVM.CurrentUserVM.Model.Image; string email = documentManagerVM.CurrentUserVM.Model.Email; if (password == rePassword) { OpUserUpdate ouu = new OpUserUpdate(); ouu.User = new UserDb { User_Id = id, Username = username, Full_Name = fullName, Image = image, Password = password, Email = email }; OperationResult obj = OperationManager.Singleton.executeOperation(ouu); if ((obj == null) || (!obj.Status)) { return; } else { bool isWindowOpen = false; foreach (Window w in Application.Current.Windows) { if (w is UpdateSuccessWindow) { isWindowOpen = true; w.Activate(); } } if (!isWindowOpen) { UpdateSuccessWindow newwindow = new UpdateSuccessWindow(); if (newwindow.ShowDialog() ?? false) { passwordInfo.Password = ""; rePasswordInfo.Password = ""; btnUpdate.IsEnabled = false; Color color = Color.FromRgb(55, 71, 79); Brush background = new SolidColorBrush(color); passwordInfo.BorderBrush = background; rePasswordInfo.BorderBrush = background; } } } } else { Color color = Color.FromRgb(219, 21, 21); Brush background = new SolidColorBrush(color); passwordInfo.BorderBrush = background; rePasswordInfo.BorderBrush = background; } }
public ActionResult Edit(UserDetailsDto dto) { OpUserUpdate update = new OpUserUpdate(); update.User = dto; var result = _manager.ExecuteOperation(update); return(RedirectToAction("Index")); }
private void btnUpdateImage_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Image files (*.png, *.jpg)|*.png;*.jpg|All files (*.*)|*.*"; if (dialog.ShowDialog() ?? false) { FileInfo fileInfo = new FileInfo(dialog.FileName); long numBytes = fileInfo.Length; double dLen = Convert.ToDouble(fileInfo.Length / 1000000); // Because of limited size of 4MB if (dLen < 4) { FileStream fileStream = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read); BinaryReader binaryReader = new BinaryReader(fileStream); byte[] data = binaryReader.ReadBytes((int)numBytes); binaryReader.Close(); string fileName = this.documentManagerVM.CurrentUserVM.Model.UserName + this.documentManagerVM.CurrentUserVM.Model.Id.ToString() + dialog.SafeFileName; int userId = this.documentManagerVM.CurrentUserVM.Model.Id; //action string status = Server.UploadImage(data, fileName); fileStream.Close(); fileStream.Dispose(); if (status != null) { string password = this.documentManagerVM.CurrentUserVM.Model.Password; int id = documentManagerVM.CurrentUserVM.Model.Id; string fullName = documentManagerVM.CurrentUserVM.Model.FullName; string username = documentManagerVM.CurrentUserVM.Model.UserName; string image = status; string email = documentManagerVM.CurrentUserVM.Model.Email; OpUserUpdate ouu = new OpUserUpdate(); ouu.User = new UserDb { User_Id = id, Username = username, Full_Name = fullName, Image = image, Password = password, Email = email }; OperationResult obj = OperationManager.Singleton.executeOperation(ouu); if ((obj == null) || (!obj.Status)) { return; } else { bool isWindowOpen = false; foreach (Window w in Application.Current.Windows) { if (w is UpdateSuccessWindow) { isWindowOpen = true; w.Activate(); } } if (!isWindowOpen) { UpdateSuccessWindow newwindow = new UpdateSuccessWindow(); if (newwindow.ShowDialog() ?? false) { this.documentManagerVM.CurrentUserVM.Model.Image = status; Server.RemoveOldImage(status); } } } } else { MessageBox.Show("Unable to upload the file", "File Error"); } } else { // Display message if the file was too large to upload MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size"); } } }