From a6f4af29c29e2922b77773e76e989d383ff6d894 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 2 Nov 2016 11:27:12 +0100 Subject: [PATCH] WIP chat connections --- Yavsc/Controllers/HomeController.cs | 2 +- Yavsc/Hubs/ChatHub.cs | 82 +- .../20161101234703_chatConnection.Designer.cs | 804 ++++++++++++++++++ .../20161101234703_chatConnection.cs | 317 +++++++ .../ApplicationDbContextModelSnapshot.cs | 51 +- Yavsc/Startup/Startup.cs | 6 +- Yavsc/Views/Home/Chat.cshtml | 6 +- 7 files changed, 1247 insertions(+), 21 deletions(-) create mode 100644 Yavsc/Migrations/20161101234703_chatConnection.Designer.cs create mode 100644 Yavsc/Migrations/20161101234703_chatConnection.cs diff --git a/Yavsc/Controllers/HomeController.cs b/Yavsc/Controllers/HomeController.cs index 18057bf8..db33c231 100644 --- a/Yavsc/Controllers/HomeController.cs +++ b/Yavsc/Controllers/HomeController.cs @@ -54,7 +54,7 @@ namespace Yavsc.Controllers if (User.Identity.IsAuthenticated) { ViewBag.IsAuthenticated=true; string uid = User.GetUserId(); - ViewBag.Contacts = DbContext.Contacts.Include(c=>c.User).Where(c=>c.OwnerId == uid) + ViewBag.Contacts = DbContext.Contacts.Where(c=>c.OwnerId == uid) ; } else ViewBag.IsAuthenticated=false; return View(); diff --git a/Yavsc/Hubs/ChatHub.cs b/Yavsc/Hubs/ChatHub.cs index 13b3ec9e..d64e253f 100644 --- a/Yavsc/Hubs/ChatHub.cs +++ b/Yavsc/Hubs/ChatHub.cs @@ -22,47 +22,103 @@ using System.Threading.Tasks; using Microsoft.AspNet.SignalR; using System.Collections.Generic; using System.Linq; +using Yavsc.Models; +using Yavsc.Model.Chat; +using System; namespace Yavsc { public class ChatHub : Hub { + public override Task OnConnected() { bool isAuth = false; - string userId = null; + string userName = null; if (Context.User != null) { isAuth = Context.User.Identity.IsAuthenticated; - userId = Context.User.Identity.Name; + userName = Context.User.Identity.Name; var group = isAuth ? "authenticated" : "anonymous"; // Log ("Cx: " + group); Groups.Add(Context.ConnectionId, group); + if (isAuth) + { + using (var db = new ApplicationDbContext()) { + var user = db.Users.Single(u => u.UserName == userName); + if (user.Connections==null) + user.Connections = new List(); + user.Connections.Add(new Connection + { + ConnectionID = Context.ConnectionId, + UserAgent = Context.Request.Headers["User-Agent"], + Connected = true + }); + db.SaveChanges(); + } + + } } else Groups.Add(Context.ConnectionId, "anonymous"); - Clients.Group("authenticated").notify("connected", Context.ConnectionId, userId); + Clients.Group("authenticated").notify("connected", Context.ConnectionId, userName); - list.Add(new UserInfo - { - ConnectionId = Context.ConnectionId, - UserName = userId - }); + list.Add(new UserInfo + { + ConnectionId = Context.ConnectionId, + UserName = userName + }); return base.OnConnected(); } + public override Task OnDisconnected(bool stopCalled) { - string userId = Context.User?.Identity.Name; - Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userId); - list.Remove(list.Single(c=>c.ConnectionId==Context.ConnectionId)); + string userName = Context.User?.Identity.Name; + if (userName != null) + { + using (var db = new ApplicationDbContext()) { + var user = db.Users.Single(u => u.UserName == userName); + var cx = user.Connections.SingleOrDefault(c => c.ConnectionID == Context.ConnectionId); + if (cx != null) + { + if (stopCalled) + { + user.Connections.Remove(cx); + } + else + { + cx.Connected = false; + } + db.SaveChanges(); + } + } + } + Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userName); + list.Remove(list.Single(c => c.ConnectionId == Context.ConnectionId)); return base.OnDisconnected(stopCalled); } public override Task OnReconnected() { + string userName = Context.User?.Identity.Name; + if (userName != null) + { + using (var db = new ApplicationDbContext()) { + var user = db.Users.Single(u => u.UserName == userName); + if (user.Connections!=null) { + var cx = user.Connections.SingleOrDefault(c => c.ConnectionID == Context.ConnectionId); + if (cx != null) + { + cx.Connected = true; + db.SaveChanges(); + } + } + } + } + return base.OnReconnected(); } @@ -95,9 +151,11 @@ namespace Yavsc public string UserName { get; set; } + public string Avatar { get; set; } + } - static List list = new List(); + static List list = new List(); [Authorize] public IEnumerable GetUserList() { diff --git a/Yavsc/Migrations/20161101234703_chatConnection.Designer.cs b/Yavsc/Migrations/20161101234703_chatConnection.Designer.cs new file mode 100644 index 00000000..ba38ecd3 --- /dev/null +++ b/Yavsc/Migrations/20161101234703_chatConnection.Designer.cs @@ -0,0 +1,804 @@ +using System; +using Microsoft.Data.Entity; +using Microsoft.Data.Entity.Infrastructure; +using Microsoft.Data.Entity.Metadata; +using Microsoft.Data.Entity.Migrations; +using Yavsc.Models; + +namespace Yavsc.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20161101234703_chatConnection")] + partial class chatConnection + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0-rc1-16348"); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b => + { + b.Property("Id"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .HasAnnotation("Relational:Name", "RoleNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasAnnotation("Relational:TableName", "AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasAnnotation("Relational:TableName", "AspNetUserRoles"); + }); + + modelBuilder.Entity("Yavsc.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("Latitude"); + + b.Property("Longitude"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Model.Chat.Connection", b => + { + b.Property("ConnectionID"); + + b.Property("ApplicationUserId"); + + b.Property("Connected"); + + b.Property("UserAgent"); + + b.HasKey("ConnectionID"); + }); + + modelBuilder.Entity("Yavsc.Model.ClientProviderInfo", b => + { + b.Property("UserId"); + + b.Property("Avatar"); + + b.Property("BillingAddressId"); + + b.Property("ChatHubConnectionId"); + + b.Property("EMail"); + + b.Property("Phone"); + + b.Property("Rate"); + + b.Property("UserName"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => + { + b.Property("UserId"); + + b.Property("ContactCredits"); + + b.Property("Credits"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Activity", b => + { + b.Property("Code") + .HasAnnotation("MaxLength", 512); + + b.Property("ActorDenomination"); + + b.Property("Description"); + + b.Property("ModeratorGroupName"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("Photo"); + + b.HasKey("Code"); + }); + + modelBuilder.Entity("Yavsc.Models.ApplicationUser", b => + { + b.Property("Id"); + + b.Property("AccessFailedCount"); + + b.Property("Avatar") + .HasAnnotation("MaxLength", 512); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("DedicatedGoogleCalendar"); + + b.Property("Email") + .HasAnnotation("MaxLength", 256); + + b.Property("EmailConfirmed"); + + b.Property("FullName") + .HasAnnotation("MaxLength", 512); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedUserName") + .HasAnnotation("MaxLength", 256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("PostalAddressId"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasAnnotation("Relational:Name", "EmailIndex"); + + b.HasIndex("NormalizedUserName") + .HasAnnotation("Relational:Name", "UserNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetUsers"); + }); + + modelBuilder.Entity("Yavsc.Models.Auth.Client", b => + { + b.Property("Id"); + + b.Property("Active"); + + b.Property("DisplayName"); + + b.Property("LogoutRedirectUri") + .HasAnnotation("MaxLength", 100); + + b.Property("RedirectUri"); + + b.Property("RefreshTokenLifeTime"); + + b.Property("Secret"); + + b.Property("Type"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Auth.RefreshToken", b => + { + b.Property("Id"); + + b.Property("ClientId") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("ExpiresUtc"); + + b.Property("IssuedUtc"); + + b.Property("ProtectedTicket") + .IsRequired(); + + b.Property("Subject") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.BalanceImpact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BalanceId") + .IsRequired(); + + b.Property("ExecDate"); + + b.Property("Impact"); + + b.Property("Reason") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.CommandLine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArticleId"); + + b.Property("Count"); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("EstimateId"); + + b.Property("EstimateTemplateId"); + + b.Property("UnitaryCost"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.Estimate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AttachedFilesString"); + + b.Property("AttachedGraphicsString"); + + b.Property("ClientApprouvalDate"); + + b.Property("ClientId") + .IsRequired(); + + b.Property("CommandId"); + + b.Property("CommandType"); + + b.Property("Description"); + + b.Property("LatestValidationDate"); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("Status"); + + b.Property("Title"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.EstimateTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("Title"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.ExceptionSIREN", b => + { + b.Property("SIREN"); + + b.HasKey("SIREN"); + }); + + modelBuilder.Entity("Yavsc.Models.Blog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("Content"); + + b.Property("Modified"); + + b.Property("Photo"); + + b.Property("Posted") + .ValueGeneratedOnAdd() + .HasAnnotation("Relational:GeneratedValueSql", "LOCALTIMESTAMP"); + + b.Property("Rate"); + + b.Property("Title"); + + b.Property("Visible"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Booking.BookQuery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClientId") + .IsRequired(); + + b.Property("CreationDate") + .ValueGeneratedOnAdd() + .HasAnnotation("Relational:GeneratedValueSql", "LOCALTIMESTAMP"); + + b.Property("EventDate"); + + b.Property("LocationId"); + + b.Property("PerformerId") + .IsRequired(); + + b.Property("Previsional"); + + b.Property("ValidationDate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Circle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ApplicationUserId"); + + b.Property("Name"); + + b.Property("OwnerId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.CircleMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CircleId"); + + b.Property("MemberId") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Contact", b => + { + b.Property("OwnerId"); + + b.Property("UserId"); + + b.Property("ApplicationUserId"); + + b.HasKey("OwnerId", "UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => + { + b.Property("DeviceId"); + + b.Property("DeclarationDate") + .ValueGeneratedOnAdd() + .HasAnnotation("Relational:GeneratedValueSql", "LOCALTIMESTAMP"); + + b.Property("DeviceOwnerId"); + + b.Property("GCMRegistrationId") + .IsRequired(); + + b.Property("Model"); + + b.Property("Platform"); + + b.Property("Version"); + + b.HasKey("DeviceId"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.BaseProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Discriminator") + .IsRequired(); + + b.Property("Name"); + + b.Property("Public"); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:DiscriminatorProperty", "Discriminator"); + + b.HasAnnotation("Relational:DiscriminatorValue", "BaseProduct"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Service", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ContextId"); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("Public"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.OAuth.OAuth2Tokens", b => + { + b.Property("UserId"); + + b.Property("AccessToken"); + + b.Property("Expiration"); + + b.Property("ExpiresIn"); + + b.Property("RefreshToken"); + + b.Property("TokenType"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.PostTag", b => + { + b.Property("PostId"); + + b.Property("TagId"); + + b.HasKey("PostId", "TagId"); + }); + + modelBuilder.Entity("Yavsc.Models.Skill", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Rate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Tag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.PerformerProfile", b => + { + b.Property("PerformerId"); + + b.Property("AcceptGeoLocalization"); + + b.Property("AcceptNotifications"); + + b.Property("AcceptPublicContact"); + + b.Property("Active"); + + b.Property("ActivityCode") + .IsRequired(); + + b.Property("MaxDailyCost"); + + b.Property("MinDailyCost"); + + b.Property("OfferId"); + + b.Property("OrganizationAddressId"); + + b.Property("Rate"); + + b.Property("SIREN") + .IsRequired() + .HasAnnotation("MaxLength", 14); + + b.Property("WebSite"); + + b.HasKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Product", b => + { + b.HasBaseType("Yavsc.Models.Market.BaseProduct"); + + b.Property("Depth"); + + b.Property("Height"); + + b.Property("Price"); + + b.Property("Weight"); + + b.Property("Width"); + + b.HasAnnotation("Relational:DiscriminatorValue", "Product"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Model.Chat.Connection", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Model.ClientProviderInfo", b => + { + b.HasOne("Yavsc.Location") + .WithMany() + .HasForeignKey("BillingAddressId"); + }); + + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithOne() + .HasForeignKey("Yavsc.Models.AccountBalance", "UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.ApplicationUser", b => + { + b.HasOne("Yavsc.Location") + .WithMany() + .HasForeignKey("PostalAddressId"); + }); + + modelBuilder.Entity("Yavsc.Models.BalanceImpact", b => + { + b.HasOne("Yavsc.Models.AccountBalance") + .WithMany() + .HasForeignKey("BalanceId"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.CommandLine", b => + { + b.HasOne("Yavsc.Models.Market.BaseProduct") + .WithMany() + .HasForeignKey("ArticleId"); + + b.HasOne("Yavsc.Models.Billing.Estimate") + .WithMany() + .HasForeignKey("EstimateId"); + + b.HasOne("Yavsc.Models.Billing.EstimateTemplate") + .WithMany() + .HasForeignKey("EstimateTemplateId"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.Estimate", b => + { + b.HasOne("Yavsc.Models.Booking.BookQuery") + .WithMany() + .HasForeignKey("CommandId"); + }); + + modelBuilder.Entity("Yavsc.Models.Blog", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("AuthorId"); + }); + + modelBuilder.Entity("Yavsc.Models.Booking.BookQuery", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ClientId"); + + b.HasOne("Yavsc.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Circle", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.CircleMember", b => + { + b.HasOne("Yavsc.Models.Circle") + .WithMany() + .HasForeignKey("CircleId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("MemberId"); + }); + + modelBuilder.Entity("Yavsc.Models.Contact", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("DeviceOwnerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Service", b => + { + b.HasOne("Yavsc.Models.Activity") + .WithMany() + .HasForeignKey("ContextId"); + }); + + modelBuilder.Entity("Yavsc.Models.PostTag", b => + { + b.HasOne("Yavsc.Models.Blog") + .WithMany() + .HasForeignKey("PostId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.PerformerProfile", b => + { + b.HasOne("Yavsc.Models.Activity") + .WithMany() + .HasForeignKey("ActivityCode"); + + b.HasOne("Yavsc.Models.Market.Service") + .WithMany() + .HasForeignKey("OfferId"); + + b.HasOne("Yavsc.Location") + .WithMany() + .HasForeignKey("OrganizationAddressId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("PerformerId"); + }); + } + } +} diff --git a/Yavsc/Migrations/20161101234703_chatConnection.cs b/Yavsc/Migrations/20161101234703_chatConnection.cs new file mode 100644 index 00000000..21d91356 --- /dev/null +++ b/Yavsc/Migrations/20161101234703_chatConnection.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using Microsoft.Data.Entity.Migrations; + +namespace Yavsc.Migrations +{ + public partial class chatConnection : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim_IdentityRole_RoleId", table: "AspNetRoleClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim_ApplicationUser_UserId", table: "AspNetUserClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin_ApplicationUser_UserId", table: "AspNetUserLogins"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_IdentityRole_RoleId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_ApplicationUser_UserId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_AccountBalance_ApplicationUser_UserId", table: "AccountBalance"); + migrationBuilder.DropForeignKey(name: "FK_BalanceImpact_AccountBalance_BalanceId", table: "BalanceImpact"); + migrationBuilder.DropForeignKey(name: "FK_CommandLine_Estimate_EstimateId", table: "CommandLine"); + migrationBuilder.DropForeignKey(name: "FK_BookQuery_ApplicationUser_ClientId", table: "BookQuery"); + migrationBuilder.DropForeignKey(name: "FK_BookQuery_PerformerProfile_PerformerId", table: "BookQuery"); + migrationBuilder.DropForeignKey(name: "FK_CircleMember_Circle_CircleId", table: "CircleMember"); + migrationBuilder.DropForeignKey(name: "FK_CircleMember_ApplicationUser_MemberId", table: "CircleMember"); + migrationBuilder.DropForeignKey(name: "FK_PostTag_Blog_PostId", table: "PostTag"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_Activity_ActivityCode", table: "PerformerProfile"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_Location_OrganizationAddressId", table: "PerformerProfile"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_ApplicationUser_PerformerId", table: "PerformerProfile"); + migrationBuilder.CreateTable( + name: "Connection", + columns: table => new + { + ConnectionID = table.Column(nullable: false), + ApplicationUserId = table.Column(nullable: true), + Connected = table.Column(nullable: false), + UserAgent = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Connection", x => x.ConnectionID); + table.ForeignKey( + name: "FK_Connection_ApplicationUser_ApplicationUserId", + column: x => x.ApplicationUserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( + name: "ClientProviderInfo", + columns: table => new + { + UserId = table.Column(nullable: false), + Avatar = table.Column(nullable: true), + BillingAddressId = table.Column(nullable: true), + ChatHubConnectionId = table.Column(nullable: true), + EMail = table.Column(nullable: true), + Phone = table.Column(nullable: true), + Rate = table.Column(nullable: false), + UserName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ClientProviderInfo", x => x.UserId); + table.ForeignKey( + name: "FK_ClientProviderInfo_Location_BillingAddressId", + column: x => x.BillingAddressId, + principalTable: "Location", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.AddForeignKey( + name: "FK_IdentityRoleClaim_IdentityRole_RoleId", + table: "AspNetRoleClaims", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserClaim_ApplicationUser_UserId", + table: "AspNetUserClaims", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserLogin_ApplicationUser_UserId", + table: "AspNetUserLogins", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_IdentityRole_RoleId", + table: "AspNetUserRoles", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_ApplicationUser_UserId", + table: "AspNetUserRoles", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_AccountBalance_ApplicationUser_UserId", + table: "AccountBalance", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_BalanceImpact_AccountBalance_BalanceId", + table: "BalanceImpact", + column: "BalanceId", + principalTable: "AccountBalance", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_CommandLine_Estimate_EstimateId", + table: "CommandLine", + column: "EstimateId", + principalTable: "Estimate", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_BookQuery_ApplicationUser_ClientId", + table: "BookQuery", + column: "ClientId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_BookQuery_PerformerProfile_PerformerId", + table: "BookQuery", + column: "PerformerId", + principalTable: "PerformerProfile", + principalColumn: "PerformerId", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_CircleMember_Circle_CircleId", + table: "CircleMember", + column: "CircleId", + principalTable: "Circle", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_CircleMember_ApplicationUser_MemberId", + table: "CircleMember", + column: "MemberId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PostTag_Blog_PostId", + table: "PostTag", + column: "PostId", + principalTable: "Blog", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_Activity_ActivityCode", + table: "PerformerProfile", + column: "ActivityCode", + principalTable: "Activity", + principalColumn: "Code", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_Location_OrganizationAddressId", + table: "PerformerProfile", + column: "OrganizationAddressId", + principalTable: "Location", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_ApplicationUser_PerformerId", + table: "PerformerProfile", + column: "PerformerId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim_IdentityRole_RoleId", table: "AspNetRoleClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim_ApplicationUser_UserId", table: "AspNetUserClaims"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin_ApplicationUser_UserId", table: "AspNetUserLogins"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_IdentityRole_RoleId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole_ApplicationUser_UserId", table: "AspNetUserRoles"); + migrationBuilder.DropForeignKey(name: "FK_AccountBalance_ApplicationUser_UserId", table: "AccountBalance"); + migrationBuilder.DropForeignKey(name: "FK_BalanceImpact_AccountBalance_BalanceId", table: "BalanceImpact"); + migrationBuilder.DropForeignKey(name: "FK_CommandLine_Estimate_EstimateId", table: "CommandLine"); + migrationBuilder.DropForeignKey(name: "FK_BookQuery_ApplicationUser_ClientId", table: "BookQuery"); + migrationBuilder.DropForeignKey(name: "FK_BookQuery_PerformerProfile_PerformerId", table: "BookQuery"); + migrationBuilder.DropForeignKey(name: "FK_CircleMember_Circle_CircleId", table: "CircleMember"); + migrationBuilder.DropForeignKey(name: "FK_CircleMember_ApplicationUser_MemberId", table: "CircleMember"); + migrationBuilder.DropForeignKey(name: "FK_PostTag_Blog_PostId", table: "PostTag"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_Activity_ActivityCode", table: "PerformerProfile"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_Location_OrganizationAddressId", table: "PerformerProfile"); + migrationBuilder.DropForeignKey(name: "FK_PerformerProfile_ApplicationUser_PerformerId", table: "PerformerProfile"); + migrationBuilder.DropTable("Connection"); + migrationBuilder.DropTable("ClientProviderInfo"); + migrationBuilder.AddForeignKey( + name: "FK_IdentityRoleClaim_IdentityRole_RoleId", + table: "AspNetRoleClaims", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserClaim_ApplicationUser_UserId", + table: "AspNetUserClaims", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserLogin_ApplicationUser_UserId", + table: "AspNetUserLogins", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_IdentityRole_RoleId", + table: "AspNetUserRoles", + column: "RoleId", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_IdentityUserRole_ApplicationUser_UserId", + table: "AspNetUserRoles", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_AccountBalance_ApplicationUser_UserId", + table: "AccountBalance", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_BalanceImpact_AccountBalance_BalanceId", + table: "BalanceImpact", + column: "BalanceId", + principalTable: "AccountBalance", + principalColumn: "UserId", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_CommandLine_Estimate_EstimateId", + table: "CommandLine", + column: "EstimateId", + principalTable: "Estimate", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_BookQuery_ApplicationUser_ClientId", + table: "BookQuery", + column: "ClientId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_BookQuery_PerformerProfile_PerformerId", + table: "BookQuery", + column: "PerformerId", + principalTable: "PerformerProfile", + principalColumn: "PerformerId", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_CircleMember_Circle_CircleId", + table: "CircleMember", + column: "CircleId", + principalTable: "Circle", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_CircleMember_ApplicationUser_MemberId", + table: "CircleMember", + column: "MemberId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_PostTag_Blog_PostId", + table: "PostTag", + column: "PostId", + principalTable: "Blog", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_Activity_ActivityCode", + table: "PerformerProfile", + column: "ActivityCode", + principalTable: "Activity", + principalColumn: "Code", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_Location_OrganizationAddressId", + table: "PerformerProfile", + column: "OrganizationAddressId", + principalTable: "Location", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_PerformerProfile_ApplicationUser_PerformerId", + table: "PerformerProfile", + column: "PerformerId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index 0b838640..e37be847 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -113,6 +113,40 @@ namespace Yavsc.Migrations b.HasKey("Id"); }); + modelBuilder.Entity("Yavsc.Model.Chat.Connection", b => + { + b.Property("ConnectionID"); + + b.Property("ApplicationUserId"); + + b.Property("Connected"); + + b.Property("UserAgent"); + + b.HasKey("ConnectionID"); + }); + + modelBuilder.Entity("Yavsc.Model.ClientProviderInfo", b => + { + b.Property("UserId"); + + b.Property("Avatar"); + + b.Property("BillingAddressId"); + + b.Property("ChatHubConnectionId"); + + b.Property("EMail"); + + b.Property("Phone"); + + b.Property("Rate"); + + b.Property("UserName"); + + b.HasKey("UserId"); + }); + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => { b.Property("UserId"); @@ -274,7 +308,8 @@ namespace Yavsc.Migrations b.Property("Count"); b.Property("Description") - .IsRequired(); + .IsRequired() + .HasAnnotation("MaxLength", 512); b.Property("EstimateId"); @@ -620,6 +655,20 @@ namespace Yavsc.Migrations .HasForeignKey("UserId"); }); + modelBuilder.Entity("Yavsc.Model.Chat.Connection", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Model.ClientProviderInfo", b => + { + b.HasOne("Yavsc.Location") + .WithMany() + .HasForeignKey("BillingAddressId"); + }); + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => { b.HasOne("Yavsc.Models.ApplicationUser") diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index 978d7eb0..c17da74e 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -222,7 +222,7 @@ namespace Yavsc IOptions siteSettings, IOptions localizationOptions, IOptions oauth2SettingsContainer, - RoleManager _roleManager, + RoleManager roleManager, ILoggerFactory loggerFactory) { Startup.UserFilesDirName = siteSettings.Value.UserFiles.DirName; @@ -279,10 +279,10 @@ namespace Yavsc Constants.FrontOfficeGroupName, Constants.StarHunterGroupName }) - if (!await _roleManager.RoleExistsAsync(roleName)) + if (!await roleManager.RoleExistsAsync(roleName)) { var role = new IdentityRole { Name = roleName }; - var resultCreate = await _roleManager.CreateAsync(role); + var resultCreate = await roleManager.CreateAsync(role); if (!resultCreate.Succeeded) { throw new Exception("The role '{roleName}' does not exist and could not be created."); diff --git a/Yavsc/Views/Home/Chat.cshtml b/Yavsc/Views/Home/Chat.cshtml index 7451cc07..185c151c 100644 --- a/Yavsc/Views/Home/Chat.cshtml +++ b/Yavsc/Views/Home/Chat.cshtml @@ -37,9 +37,7 @@
- - - + @section scripts { @@ -131,7 +129,7 @@ $('#discussion').append('
  • ' + htmlEncode(tag) ); console.log(res); }; - $("#GetUsersBtn").click(getUsers); + getUsers(); });