Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions OpsFlow/Services/Implementations/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public List<User> GetAllUsers()
return _context.Users
.Include(u => u.Company)
.Include(u => u.Role)
.Include(u => u.Department)
.AsNoTracking()
.ToList();
}
Expand All @@ -43,6 +44,7 @@ public User GetUserById(int id)
var user = _context.Users
.Include(u => u.Company)
.Include(u => u.Role)
.Include(u => u.Department)
.FirstOrDefault(u => u.Id == id);

if (user == null)
Expand Down Expand Up @@ -133,6 +135,7 @@ public void UpdateUser(User user)
existingUser.Phone = user.Phone;
existingUser.CompanyId = user.CompanyId;
existingUser.RoleId = user.RoleId;
existingUser.DepartmentId = user.DepartmentId;
existingUser.IsActive = user.IsActive;
existingUser.AvatarUrl = user.AvatarUrl;

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

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

if (user.CompanyId <= 0)
throw new ValidationException("Lütfen geçerli bir şirket seçiniz.");

if (user.RoleId <= 0)
throw new ValidationException("Lütfen kullanıcı için bir rol tanımlayınız.");
}
Expand Down
2 changes: 1 addition & 1 deletion OpsFlow/UI/Forms/Main/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void LoadContent(string viewName)
case "Dashboard":
break;
case "Staff":
LoadForm(new AddPersonelForm());
LoadForm(new PersonelListForm());
break;
case "Tasks":
break;
Expand Down
31 changes: 15 additions & 16 deletions OpsFlow/UI/Forms/Management/PersonelCard.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 107 additions & 10 deletions OpsFlow/UI/Forms/Management/PersonelCard.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,90 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpsFlow.Core.Models;
using OpsFlow.Core.Services;
using OpsFlow.Services.Implementations;

namespace OpsFlow.UI.Forms.Management;

public partial class PersonelCard : UserControl
{
private User? _user;

public PersonelCard()
{
InitializeComponent();
this.Margin = new Padding(35, 35, 35, 35);
}

public void SetUserData(User user)
{
_user = user;

lblName.Text = $"{user.Name} {user.Surname}";

string departmentName = user.Department?.DepartmentName ?? "Departman Yok";
btnRoleBadge.Text = departmentName;

Size textSize = TextRenderer.MeasureText(departmentName, btnRoleBadge.Font);
int requiredWidth = textSize.Width + 24;
int maxWidth = 215;
btnRoleBadge.Width = Math.Min(requiredWidth, maxWidth);

LoadAvatarAsync(user.AvatarUrl);
}

private async void LoadAvatarAsync(string? avatarUrl)
{
if (string.IsNullOrWhiteSpace(avatarUrl))
{
PictureBox.Image = null;
return;
}

try
{
if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out Uri? uri) &&
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
{
using (HttpClient client = new HttpClient())
{
byte[] imageData = await client.GetByteArrayAsync(uri);
using (MemoryStream ms = new MemoryStream(imageData))
{
PictureBox.Image = Image.FromStream(ms);
}
}
}
else
{
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
string[] possiblePaths = {
Path.Combine(baseDir, "Resources", "Uploads", avatarUrl),
Path.Combine(baseDir, "..", "..", "..", "Resources", "Uploads", avatarUrl),
Path.Combine(baseDir, "..", "..", "Resources", "Uploads", avatarUrl),
avatarUrl
};

foreach (string path in possiblePaths)
{
if (File.Exists(path))
{
PictureBox.Image = Image.FromFile(path);
return;
}
}

PictureBox.Image = null;
}
}
catch
{
PictureBox.Image = null;
}
}

private void btnViewProfile_Click(object sender, EventArgs e)
private async void btnViewProfile_Click(object sender, EventArgs e)
{
if (_user == null) return;

if (this.FindForm() is Form anaForm)
{
Form dimmer = new Form();
Expand All @@ -27,13 +95,42 @@ private void btnViewProfile_Click(object sender, EventArgs e)
dimmer.StartPosition = FormStartPosition.Manual;
dimmer.Location = anaForm.Location;
dimmer.Size = anaForm.Size;
using (ProfileEditForm popup = new ProfileEditForm())
using (ProfileEditForm popup = new ProfileEditForm(_user))
{
popup.StartPosition = FormStartPosition.CenterParent;
dimmer.Show(anaForm);
popup.ShowDialog(dimmer);
DialogResult result = popup.ShowDialog(dimmer);
dimmer.Close();

// Eğer kullanıcı bilgileri güncellendiyse, kartı yeniden yükle
if (result == DialogResult.OK)
{
await RefreshUserDataAsync();
}
}
}
}

private async Task RefreshUserDataAsync()
{
if (_user == null) return;

try
{
using var context = OpsFlow.Core.Services.DatabaseManager.CreateContext();
var userService = new OpsFlow.Services.Implementations.UserService(context);

// Güncel kullanıcı bilgilerini veritabanından çek
var updatedUser = userService.GetUserById(_user.Id);
if (updatedUser != null)
{
// Kartı güncel verilerle yeniden yükle
SetUserData(updatedUser);
}
}
catch
{
// Hata durumunda sessizce devam et
}
}
}
Loading