aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-28 01:08:31 +0200
committertranstrike <transtrike@gmail.com>2021-01-28 01:08:31 +0200
commite632e9241e8afe530f6b37cb683b211769135c45 (patch)
tree37674ce51d0ce272bb9ddd8535bf67956f01a3cb /src/DevHive.Data/Repositories
parentf8e17868c617e1734c0e77e58a8318300a5b663a (diff)
downloadDevHive-e632e9241e8afe530f6b37cb683b211769135c45.tar
DevHive-e632e9241e8afe530f6b37cb683b211769135c45.tar.gz
DevHive-e632e9241e8afe530f6b37cb683b211769135c45.zip
USER UPDATE FIIIIIIXED
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/BaseRepository.cs11
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs37
2 files changed, 42 insertions, 6 deletions
diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs
index 0a97ac1..f1e6673 100644
--- a/src/DevHive.Data/Repositories/BaseRepository.cs
+++ b/src/DevHive.Data/Repositories/BaseRepository.cs
@@ -13,7 +13,6 @@ namespace DevHive.Data.Repositories
public BaseRepository(DbContext context)
{
this._context = context;
- this._context.ChangeTracker.AutoDetectChangesEnabled = false;
}
public virtual async Task<bool> AddAsync(TEntity entity)
@@ -34,11 +33,11 @@ namespace DevHive.Data.Repositories
public virtual async Task<bool> EditAsync(Guid id, TEntity newEntity)
{
- TEntity currEnt = await this.GetByIdAsync(id);
- this._context
- .Entry(currEnt)
- .CurrentValues
- .SetValues(newEntity);
+ var entry = this._context.Entry(newEntity);
+ if (entry.State == EntityState.Detached)
+ this._context.Attach(newEntity);
+
+ entry.State = EntityState.Modified;
return await this.SaveChangesAsync(_context);
}
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
index 57ae146..fe46226 100644
--- a/src/DevHive.Data/Repositories/UserRepository.cs
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
+using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
@@ -48,6 +50,41 @@ namespace DevHive.Data.Repositories
}
#endregion
+ #region Update
+ public override async Task<bool> EditAsync(Guid id, User newEntity)
+ {
+ User user = await this.GetByIdAsync(id);
+
+ user.Languages.Clear();
+ foreach (var lang in newEntity.Languages)
+ user.Languages.Add(lang);
+
+ user.Roles.Clear();
+ foreach (var role in newEntity.Roles)
+ user.Roles.Add(role);
+
+ foreach (var friend in user.Friends)
+ {
+ friend.Friends.Remove(user);
+ this._context.Entry(friend).State = EntityState.Modified;
+ }
+ user.Friends.Clear();
+ foreach (var friend in newEntity.Friends)
+ {
+ friend.Friends.Add(user);
+ user.Friends.Add(friend);
+ }
+
+ user.Technologies.Clear();
+ foreach (var tech in newEntity.Technologies)
+ user.Technologies.Add(tech);
+
+ this._context.Entry(user).State = EntityState.Modified;
+
+ return await this.SaveChangesAsync(this._context);
+ }
+ #endregion
+
#region Validations
public async Task<bool> DoesUserExistAsync(Guid id)
{