Skip to content

Commit 5aa4ca9

Browse files
authored
Merge pull request #68 from asisec/feature/staff-list-view
fix: profile edit form UX improvements and data refresh
2 parents 5b8e11d + 39ea78c commit 5aa4ca9

File tree

8 files changed

+1145
-121
lines changed

8 files changed

+1145
-121
lines changed

OpsFlow/Services/Implementations/UserService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public List<User> GetAllUsers()
2424
return _context.Users
2525
.Include(u => u.Company)
2626
.Include(u => u.Role)
27+
.Include(u => u.Department)
2728
.AsNoTracking()
2829
.ToList();
2930
}
@@ -43,6 +44,7 @@ public User GetUserById(int id)
4344
var user = _context.Users
4445
.Include(u => u.Company)
4546
.Include(u => u.Role)
47+
.Include(u => u.Department)
4648
.FirstOrDefault(u => u.Id == id);
4749

4850
if (user == null)
@@ -133,6 +135,7 @@ public void UpdateUser(User user)
133135
existingUser.Phone = user.Phone;
134136
existingUser.CompanyId = user.CompanyId;
135137
existingUser.RoleId = user.RoleId;
138+
existingUser.DepartmentId = user.DepartmentId;
136139
existingUser.IsActive = user.IsActive;
137140
existingUser.AvatarUrl = user.AvatarUrl;
138141

@@ -141,7 +144,6 @@ public void UpdateUser(User user)
141144
existingUser.Password = HashingHelper.HashPassword(user.Password);
142145
}
143146

144-
_context.Users.Update(existingUser);
145147
_context.SaveChanges();
146148
}
147149
catch (NotFoundException)
@@ -230,9 +232,6 @@ private void ValidateUser(User user)
230232
if (string.IsNullOrWhiteSpace(user.Email) || !user.Email.Contains("@"))
231233
throw new ValidationException("Lütfen geçerli bir e-posta adresi giriniz.");
232234

233-
if (user.CompanyId <= 0)
234-
throw new ValidationException("Lütfen geçerli bir şirket seçiniz.");
235-
236235
if (user.RoleId <= 0)
237236
throw new ValidationException("Lütfen kullanıcı için bir rol tanımlayınız.");
238237
}

OpsFlow/UI/Forms/Main/MainForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void LoadContent(string viewName)
7878
case "Dashboard":
7979
break;
8080
case "Staff":
81-
LoadForm(new AddPersonelForm());
81+
LoadForm(new PersonelListForm());
8282
break;
8383
case "Tasks":
8484
break;

OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs

Lines changed: 15 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 107 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,90 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Data;
5-
using System.Drawing;
6-
using System.Text;
7-
using System.Windows.Forms;
1+
using OpsFlow.Core.Models;
2+
using OpsFlow.Core.Services;
3+
using OpsFlow.Services.Implementations;
84

95
namespace OpsFlow.UI.Forms.Management;
106

117
public partial class PersonelCard : UserControl
128
{
9+
private User? _user;
10+
1311
public PersonelCard()
1412
{
1513
InitializeComponent();
14+
this.Margin = new Padding(35, 35, 35, 35);
15+
}
16+
17+
public void SetUserData(User user)
18+
{
19+
_user = user;
20+
21+
lblName.Text = $"{user.Name} {user.Surname}";
22+
23+
string departmentName = user.Department?.DepartmentName ?? "Departman Yok";
24+
btnRoleBadge.Text = departmentName;
25+
26+
Size textSize = TextRenderer.MeasureText(departmentName, btnRoleBadge.Font);
27+
int requiredWidth = textSize.Width + 24;
28+
int maxWidth = 215;
29+
btnRoleBadge.Width = Math.Min(requiredWidth, maxWidth);
30+
31+
LoadAvatarAsync(user.AvatarUrl);
32+
}
33+
34+
private async void LoadAvatarAsync(string? avatarUrl)
35+
{
36+
if (string.IsNullOrWhiteSpace(avatarUrl))
37+
{
38+
PictureBox.Image = null;
39+
return;
40+
}
41+
42+
try
43+
{
44+
if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out Uri? uri) &&
45+
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
46+
{
47+
using (HttpClient client = new HttpClient())
48+
{
49+
byte[] imageData = await client.GetByteArrayAsync(uri);
50+
using (MemoryStream ms = new MemoryStream(imageData))
51+
{
52+
PictureBox.Image = Image.FromStream(ms);
53+
}
54+
}
55+
}
56+
else
57+
{
58+
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
59+
string[] possiblePaths = {
60+
Path.Combine(baseDir, "Resources", "Uploads", avatarUrl),
61+
Path.Combine(baseDir, "..", "..", "..", "Resources", "Uploads", avatarUrl),
62+
Path.Combine(baseDir, "..", "..", "Resources", "Uploads", avatarUrl),
63+
avatarUrl
64+
};
65+
66+
foreach (string path in possiblePaths)
67+
{
68+
if (File.Exists(path))
69+
{
70+
PictureBox.Image = Image.FromFile(path);
71+
return;
72+
}
73+
}
74+
75+
PictureBox.Image = null;
76+
}
77+
}
78+
catch
79+
{
80+
PictureBox.Image = null;
81+
}
1682
}
1783

18-
private void btnViewProfile_Click(object sender, EventArgs e)
84+
private async void btnViewProfile_Click(object sender, EventArgs e)
1985
{
86+
if (_user == null) return;
87+
2088
if (this.FindForm() is Form anaForm)
2189
{
2290
Form dimmer = new Form();
@@ -27,13 +95,42 @@ private void btnViewProfile_Click(object sender, EventArgs e)
2795
dimmer.StartPosition = FormStartPosition.Manual;
2896
dimmer.Location = anaForm.Location;
2997
dimmer.Size = anaForm.Size;
30-
using (ProfileEditForm popup = new ProfileEditForm())
98+
using (ProfileEditForm popup = new ProfileEditForm(_user))
3199
{
32100
popup.StartPosition = FormStartPosition.CenterParent;
33101
dimmer.Show(anaForm);
34-
popup.ShowDialog(dimmer);
102+
DialogResult result = popup.ShowDialog(dimmer);
35103
dimmer.Close();
104+
105+
// Eğer kullanıcı bilgileri güncellendiyse, kartı yeniden yükle
106+
if (result == DialogResult.OK)
107+
{
108+
await RefreshUserDataAsync();
109+
}
36110
}
37111
}
38112
}
113+
114+
private async Task RefreshUserDataAsync()
115+
{
116+
if (_user == null) return;
117+
118+
try
119+
{
120+
using var context = OpsFlow.Core.Services.DatabaseManager.CreateContext();
121+
var userService = new OpsFlow.Services.Implementations.UserService(context);
122+
123+
// Güncel kullanıcı bilgilerini veritabanından çek
124+
var updatedUser = userService.GetUserById(_user.Id);
125+
if (updatedUser != null)
126+
{
127+
// Kartı güncel verilerle yeniden yükle
128+
SetUserData(updatedUser);
129+
}
130+
}
131+
catch
132+
{
133+
// Hata durumunda sessizce devam et
134+
}
135+
}
39136
}

0 commit comments

Comments
 (0)