DbSetExtension Address, Profile, User
This commit is contained in:
parent
165cdc1359
commit
68b20be91e
|
|
@ -1,18 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Addresses.Dtos;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Addresses
|
||||
{
|
||||
public static class AcAddressDbSetExtensions
|
||||
{
|
||||
public static IQueryable<TAddress> GetAddresses<TAddress>(this IAcAddressDbSetBase<TAddress> ctx) where TAddress : class, IAcAddress
|
||||
public static IQueryable<TAddress> GetAddresses<TAddress>(this IAcAddressDbSetBase<TAddress> ctx) where TAddress : class, IAcAddressDtoBase
|
||||
=> ctx.Addresses;
|
||||
|
||||
public static TAddress? GetAddressById<TAddress>(this IAcAddressDbSetBase<TAddress> ctx, Guid addressId) where TAddress : class, IAcAddress
|
||||
public static TAddress? GetAddressById<TAddress>(this IAcAddressDbSetBase<TAddress> ctx, Guid addressId) where TAddress : class, IAcAddressDtoBase
|
||||
=> ctx.GetAddresses().FirstOrDefault(x => x.Id == addressId);
|
||||
|
||||
public static bool UpdateAddress<TAddress>(this IAcAddressDbSetBase<TAddress> ctx, TAddress address) where TAddress : class, IAcAddressDtoBase
|
||||
=> ctx.Addresses.Update(address).State == EntityState.Modified;
|
||||
|
||||
public static bool RemoveAddress<TAddress>(this IAcAddressDbSetBase<TAddress> ctx, TAddress address) where TAddress : class, IAcAddressDtoBase
|
||||
=> ctx.Addresses.Remove(address).State == EntityState.Deleted;
|
||||
|
||||
public static bool RemoveAddress<TAddress>(this IAcAddressDbSetBase<TAddress> ctx, Guid addressId) where TAddress : class, IAcAddressDtoBase
|
||||
{
|
||||
var address = ctx.GetAddressById(addressId);
|
||||
|
||||
return address != null && ctx.RemoveAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ using AyCode.Interfaces.Profiles.Dtos;
|
|||
using AyCode.Interfaces.Profiles;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AyCode.Interfaces.Addresses.Dtos;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using AyCode.Interfaces.Users;
|
||||
|
||||
namespace AyCode.Database.DbSets.Profiles;
|
||||
|
||||
|
|
@ -15,9 +17,10 @@ public static class AcProfileDbSetExtensions
|
|||
=> ctx.Profiles.FirstOrDefault(u => u.Id == profileId);
|
||||
|
||||
public static bool AddProfile<TProfile>(this IAcProfileDbSetBase<TProfile> ctx, TProfile profile) where TProfile : class, IAcProfileDtoBase
|
||||
{
|
||||
return ctx.Profiles.Add(profile).State == EntityState.Added;
|
||||
}
|
||||
=> ctx.Profiles.Add(profile).State == EntityState.Added;
|
||||
|
||||
public static bool UpdateProfile<TProfile>(this IAcProfileDbSetBase<TProfile> ctx, TProfile profile) where TProfile : class, IAcProfileDtoBase
|
||||
=> ctx.Profiles.Update(profile).State == EntityState.Modified;
|
||||
|
||||
public static bool RemoveProfile<TProfile, TAddress>(this IAcProfileDbSetBase<TProfile, TAddress> ctx, TProfile profile)
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ public static class AcUserDbSetExtensions
|
|||
return ctx.Users.Add(user).State == EntityState.Added;
|
||||
}
|
||||
|
||||
public static bool UpdateUser<TUser>(this IAcUserDbSetBase<TUser> ctx, TUser user) where TUser : class, IAcUserBase
|
||||
=> ctx.Users.Update(user).State == EntityState.Modified;
|
||||
|
||||
public static bool RemoveUser<TUser, TProfile, TAddress>(this IAcUserDbSetBase<TUser, TProfile, TAddress> ctx, TUser user)
|
||||
where TUser : class, IAcUser<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
|
|
|
|||
Loading…
Reference in New Issue