Skip to content

Commit

Permalink
App modules added
Browse files Browse the repository at this point in the history
  • Loading branch information
mateanticevic committed Apr 7, 2020
1 parent 77a1ecc commit c7062b4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Model.Database.Main.User.User GetUser(string token)
{
return db.AccessTokens.Include(x => x.User)
.ThenInclude(x => x.DefaultCurrency)
.Include(x => x.User)
.SingleOrDefault(x => x.Token == token && x.IsActive)
.User;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectIvy.Business/Handlers/User/UserHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public View.User Get(int? id = null)
var userEntity = db.Users.Include(x => x.UserRoles)
.ThenInclude(x => x.Role)
.Include(x => x.DefaultCurrency)
.Include(x => x.Modules)
.Include("Modules.Module")
.SingleOrDefault(x => x.Id == id);

return new View.User(userEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<GoogleCloudDialogflowV2WebhookResponse> CreateExpense(GoogleCl
CurrencyId = string.IsNullOrEmpty(currencyId) ? User.DefaultCurrency.Code : currencyId,
Comment = (string)request.QueryResult.Parameters["description"],
Date = (DateTime)request.QueryResult.Parameters["date"],
ExpenseTypeId = (string)request.QueryResult.Parameters["expense-type"],
ExpenseTypeId = ((string)request.QueryResult.Parameters["expense-type"]).Replace(" ", "-"),
NeedsReview = true,
PaymentTypeId = (string)request.QueryResult.Parameters["payment-type"]
};
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task<GoogleCloudDialogflowV2WebhookResponse> GetExpenseSum(GoogleCl
{
var binding = new ExpenseSumGetBinding(request.ToFilteredBinding());

binding.TypeId = request.QueryResult.Parameters.ContainsKey("ExpenseType") ? ((JArray)request.QueryResult.Parameters["ExpenseType"]).Select(x => (string)x) : null;
binding.TypeId = request.QueryResult.Parameters.ContainsKey("ExpenseType") ? ((JArray)request.QueryResult.Parameters["ExpenseType"]).Select(x => ((string)x).Replace(" ", "-")) : null;

decimal sum = await _expenseHandler.SumAmount(binding);

Expand Down
3 changes: 3 additions & 0 deletions src/ProjectIvy.Data/DbContexts/MainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<UserRole>()
.HasKey(x => new { x.UserId, x.RoleId });

modelBuilder.Entity<UserModule>()
.HasKey(x => new { x.UserId, x.ModuleId });

modelBuilder.Entity<UserRole>()
.HasOne(x => x.User)
.WithMany(x => x.UserRoles);
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectIvy.Model/Database/Main/App/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ProjectIvy.Model.Database.Main.App
{
[Table("Application", Schema = "App")]
[Table(nameof(Application), Schema = nameof(App))]
public class Application : IHasValueId
{
[Key]
Expand Down
16 changes: 16 additions & 0 deletions src/ProjectIvy.Model/Database/Main/App/Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ProjectIvy.Model.Database.Main.App
{
[Table(nameof(Module), Schema = nameof(App))]
public class Module : IHasValueId
{
[Key]
public int Id { get; set; }

public string ValueId { get; set; }

public string Name { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/ProjectIvy.Model/Database/Main/User/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public class User : IHasCreatedModified
public ICollection<UserRole> UserRoles { get; set; }

public ICollection<Tracking.Tracking> Trackings { get; set; }

public ICollection<UserModule> Modules { get; set; }
}
}
21 changes: 21 additions & 0 deletions src/ProjectIvy.Model/Database/Main/User/UserModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;

namespace ProjectIvy.Model.Database.Main.User
{
[Table(nameof(UserModule), Schema = nameof(User))]
public class UserModule
{
public int UserId { get; set; }

public int ModuleId { get; set; }

public bool IsActive { get; set; }

public DateTime AvailableFrom { get; set; }

public User User { get; set; }

public App.Module Module { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/ProjectIvy.Model/View/User/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public User(DatabaseModel.User.User x)
Email = x.Email;
Username = x.Username;
Roles = x.UserRoles.Select(y => new Role.Role(y.Role));
Modules = x.Modules.Where(x => x.IsActive).Select(x => x.Module.ValueId);
}

public Currency.Currency DefaultCurrency { get; set; }
Expand All @@ -27,5 +28,7 @@ public User(DatabaseModel.User.User x)
public string Username { get; set; }

public IEnumerable<Role.Role> Roles { get; set; }

public IEnumerable<string> Modules { get; set; }
}
}

0 comments on commit c7062b4

Please sign in to comment.