فهرست منبع

setup dbcontext

USRINGENICO\fmorel 3 سال پیش
والد
کامیت
29880cea48

+ 1 - 0
.gitignore

@@ -8,3 +8,4 @@ __pycache__
 /Dotnet/Warhammer/obj
 /Dotnet/Warhammer/wwwroot
 /Dotnet/.vs/Warhammer
+/Dotnet/Warhammer/bin/Release/netcoreapp3.1

+ 81 - 0
Dotnet/Warhammer/DataLayer/AbstractRepository.cs

@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using Warhammer.DataLayer.Interfaces;
+using Warhammer.Models;
+
+namespace Warhammer.DataLayer
+{
+    public class AbstractRepository<T> : IAbstractRepository<T> where T : BaseEntity
+    {
+
+        #region Fields
+
+        protected DeathwatchDbContext DeathwatchDbContext;
+
+        #endregion
+
+        public AbstractRepository(DeathwatchDbContext deathwatchDbContext)
+        {
+            DeathwatchDbContext = deathwatchDbContext;
+        }
+
+        #region Public Methods
+
+        public async Task<T> GetById(Guid id)
+        {
+            return await DeathwatchDbContext.Set<T>().FindAsync(id);
+        }
+
+        public async Task<T> FirstOrDefault(Expression<Func<T, bool>> predicate)
+        {
+            return await DeathwatchDbContext.Set<T>().FirstOrDefaultAsync(predicate);
+        }
+
+        public async Task Add(T entity)
+        {
+            // await DeathwatchDbContext.AddAsync(entity);
+            await DeathwatchDbContext.Set<T>().AddAsync(entity);
+            await DeathwatchDbContext.SaveChangesAsync();
+        }
+
+        public Task Update(T entity)
+        {
+            // In case AsNoTracking is used
+            DeathwatchDbContext.Entry(entity).State = EntityState.Modified;
+            return DeathwatchDbContext.SaveChangesAsync();
+        }
+
+        public Task Remove(T entity)
+        {
+            DeathwatchDbContext.Set<T>().Remove(entity);
+            return DeathwatchDbContext.SaveChangesAsync();
+        }
+
+        public async Task<IEnumerable<T>> GetAll()
+        {
+            return await DeathwatchDbContext.Set<T>().ToListAsync();
+        }
+
+        public async Task<IEnumerable<T>> GetWhere(Expression<Func<T, bool>> predicate)
+        {
+            return await DeathwatchDbContext.Set<T>().Where(predicate).ToListAsync();
+        }
+
+        public Task<int> CountAll()
+        {
+            return DeathwatchDbContext.Set<T>().CountAsync();
+        }
+
+        public Task<int> CountWhere(Expression<Func<T, bool>> predicate)
+        {
+            return DeathwatchDbContext.Set<T>().CountAsync(predicate);
+        }
+
+        #endregion
+
+    }
+}

+ 3 - 1
Dotnet/Warhammer/DataLayer/DeathwatchDbContext.cs

@@ -1,5 +1,6 @@
 using Microsoft.EntityFrameworkCore;
 using Warhammer.Models;
+using Warhammer.Models.Weapons;
 
 namespace Warhammer.DataLayer
 {
@@ -18,7 +19,8 @@ namespace Warhammer.DataLayer
 
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
-            modelBuilder.Entity<Player>().ToTable("Players").HasKey(p => p.Name);
+            modelBuilder.Entity<Player>().HasMany(s => s.Weapons);
+            modelBuilder.Entity<Weapon>().HasMany(w => w.Players);
         }
     }
 }

+ 26 - 0
Dotnet/Warhammer/DataLayer/Interfaces/IAbstractRepository.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using Warhammer.Models;
+
+namespace Warhammer.DataLayer.Interfaces
+{
+    public interface IAbstractRepository<T> where T : BaseEntity
+    {
+        Task<T> GetById(Guid id);
+        Task<T> FirstOrDefault(Expression<Func<T, bool>> predicate);
+
+        Task Add(T entity);
+        Task Update(T entity);
+        Task Remove(T entity);
+
+        Task<IEnumerable<T>> GetAll();
+        Task<IEnumerable<T>> GetWhere(Expression<Func<T, bool>> predicate);
+
+        Task<int> CountAll();
+        Task<int> CountWhere(Expression<Func<T, bool>> predicate);
+
+
+    }
+}

+ 8 - 0
Dotnet/Warhammer/DataLayer/Interfaces/IPlayerRepository.cs

@@ -0,0 +1,8 @@
+using Warhammer.Models;
+
+namespace Warhammer.DataLayer.Interfaces
+{
+    public interface IPlayerRepository : IAbstractRepository<Player>
+    {
+    }
+}

+ 1 - 1
Dotnet/Warhammer/Models/BaseEntity.cs

@@ -1,7 +1,7 @@
 using System;
 using System.ComponentModel.DataAnnotations;
 
-namespace Domain.BackOffice
+namespace Warhammer.Models
 {
     public class BaseEntity
     {

+ 2 - 2
Dotnet/Warhammer/Models/Player.cs

@@ -1,7 +1,6 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
-using Domain.BackOffice;
 using Warhammer.Models.Weapons;
 using Warhammer.Service;
 
@@ -24,6 +23,8 @@ namespace Warhammer.Models
         public int SOC { get; set; }
         public int MF { get; set; }
 
+        public ICollection<Weapon> Weapons { get; set; }
+
         public int Initiative()
         {
             return DiceService.RollDices(1, 10) + DiceService.Bonus(AG);
@@ -40,6 +41,5 @@ namespace Warhammer.Models
         public bool TestSOC() { return DiceService.RollDices(1, 100) <= SOC; }
         public bool TestMF() { return DiceService.RollDices(1, 100) <= MF; }
 
-        public IList Weapons { get; set; }
     }
 }

+ 25 - 2
Dotnet/Warhammer/Models/Weapons/Sword.cs

@@ -1,7 +1,30 @@
-namespace Warhammer.Models.Weapons
+using System.Linq;
+using Warhammer.Service;
+
+namespace Warhammer.Models.Weapons
 {
     public class Sword : Weapon
     {
+
+        //public virtual object sword_damage()
+        //{
+        //    return this.RollDices(1, 10) + 3 + this.MF;
+        //}
+
+
+        public int FastAttack(int cc)
+        {
+            var damage = 0;
+            for (int i = 0; i < 2; i++)
+            {
+                if (DiceService.RollDices(1, 100) <= cc)
+                {
+                    damage += DiceService.RollDices(1, 10) + 3 + cc;
+                }
+            }
+            return damage;
+        }
+
         public override int DamageAmount(int successDegree)
         {
             throw new System.NotImplementedException();
@@ -9,7 +32,7 @@
 
         public override int Attack(int bonusCc, int cc, string amo = null, bool? isHorde = null)
         {
-            throw new System.NotImplementedException();
+            return DiceService.RollDices(1, 10) + 3 + cc;
         }
     }
 }

+ 4 - 1
Dotnet/Warhammer/Models/Weapons/Weapon.cs

@@ -1,4 +1,4 @@
-using Domain.BackOffice;
+using System.Collections.Generic;
 using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
 
 namespace Warhammer.Models.Weapons
@@ -16,7 +16,10 @@ namespace Warhammer.Models.Weapons
         public string Rch { get; set; }
         public string Attribute { get; set; }
 
+        public ICollection<Player> Players { get; set; }
+
         public abstract int Attack(int bonusStat, int stat, string amo = null, bool? isHorde = null);
+
         public abstract int DamageAmount(int successDegree);
 
     }

+ 30 - 0
Dotnet/Warhammer/Properties/PublishProfiles/DeathwatchWebApp - Web Deploy.pubxml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This file is used by the publish/package process of your Web project. You can customize the behavior of this process
+by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project>
+  <PropertyGroup>
+    <WebPublishMethod>MSDeploy</WebPublishMethod>
+    <ResourceId>/subscriptions/b83edada-b419-4bc0-b626-7bd2c6e2a027/resourceGroups/Deathwatch/providers/Microsoft.Web/sites/DeathwatchWebApp</ResourceId>
+    <ResourceGroup>Deathwatch</ResourceGroup>
+    <PublishProvider>AzureWebSite</PublishProvider>
+    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
+    <LastUsedPlatform>Any CPU</LastUsedPlatform>
+    <SiteUrlToLaunchAfterPublish>https://deathwatchwebapp.azurewebsites.net</SiteUrlToLaunchAfterPublish>
+    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
+    <ExcludeApp_Data>false</ExcludeApp_Data>
+    <ProjectGuid>cac4117f-9daa-4631-8afe-7cb1fe2183f6</ProjectGuid>
+    <MSDeployServiceURL>deathwatchwebapp.scm.azurewebsites.net:443</MSDeployServiceURL>
+    <DeployIisAppPath>DeathwatchWebApp</DeployIisAppPath>
+    <RemoteSitePhysicalPath />
+    <SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
+    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
+    <EnableMSDeployBackup>true</EnableMSDeployBackup>
+    <EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
+    <UserName>$DeathwatchWebApp</UserName>
+    <_SavePWD>true</_SavePWD>
+    <_DestinationType>AzureWebSite</_DestinationType>
+    <InstallAspNetCoreSiteExtension>false</InstallAspNetCoreSiteExtension>
+  </PropertyGroup>
+</Project>

+ 12 - 0
Dotnet/Warhammer/Properties/PublishProfiles/DeathwatchWebApp - Web Deploy.pubxml.user

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This file is used by the publish/package process of your Web project. You can customize the behavior of this process
+by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project>
+  <PropertyGroup>
+    <TimeStampOfAssociatedLegacyPublishXmlFile />
+    <EncryptedPassword>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA3aukXzos7UmpDo1WnIZ1xAAAAAACAAAAAAADZgAAwAAAABAAAACnCoiGSbWN4HGb1PUIKKGPAAAAAASAAACgAAAAEAAAAIG73dxboIaK3CVSNKerN42AAAAA3LbNVHirj20WPofbvToIRGwRPHoijX74t4vOUZxDXEInDt0xUdMB4oZkV07T7GlntblCn4XNlSTnq0lRwIY13PwmpkiX9utIpM6ji386dxAgk8h5KztgX9hTEBdFjHFaBmTbm8zzSNMN16F83b57ZacyTfgqYQ+dLyMbZ4spf9EUAAAAgvEaFmvL4fAV0i0g/9K19hrwZ8A=</EncryptedPassword>
+    <History>True|2022-09-21T19:17:52.2079741Z;</History>
+  </PropertyGroup>
+</Project>

+ 113 - 0
Dotnet/Warhammer/Properties/ServiceDependencies/DeathwatchWebApp - Web Deploy/profile.arm.json

@@ -0,0 +1,113 @@
+{
+  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
+  "contentVersion": "1.0.0.0",
+  "metadata": {
+    "_dependencyType": "compute.appService.windows"
+  },
+  "parameters": {
+    "resourceGroupName": {
+      "type": "string",
+      "defaultValue": "Deathwatch",
+      "metadata": {
+        "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
+      }
+    },
+    "resourceGroupLocation": {
+      "type": "string",
+      "defaultValue": "ukwest",
+      "metadata": {
+        "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
+      }
+    },
+    "resourceName": {
+      "type": "string",
+      "defaultValue": "DeathwatchWebApp",
+      "metadata": {
+        "description": "Name of the main resource to be created by this template."
+      }
+    },
+    "resourceLocation": {
+      "type": "string",
+      "defaultValue": "[parameters('resourceGroupLocation')]",
+      "metadata": {
+        "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
+      }
+    }
+  },
+  "variables": {
+    "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+    "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]"
+  },
+  "resources": [
+    {
+      "type": "Microsoft.Resources/resourceGroups",
+      "name": "[parameters('resourceGroupName')]",
+      "location": "[parameters('resourceGroupLocation')]",
+      "apiVersion": "2019-10-01"
+    },
+    {
+      "type": "Microsoft.Resources/deployments",
+      "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+      "resourceGroup": "[parameters('resourceGroupName')]",
+      "apiVersion": "2019-10-01",
+      "dependsOn": [
+        "[parameters('resourceGroupName')]"
+      ],
+      "properties": {
+        "mode": "Incremental",
+        "template": {
+          "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+          "contentVersion": "1.0.0.0",
+          "resources": [
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[parameters('resourceName')]",
+              "type": "Microsoft.Web/sites",
+              "apiVersion": "2015-08-01",
+              "tags": {
+                "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
+              },
+              "dependsOn": [
+                "[variables('appServicePlan_ResourceId')]"
+              ],
+              "kind": "app",
+              "properties": {
+                "name": "[parameters('resourceName')]",
+                "kind": "app",
+                "httpsOnly": true,
+                "reserved": false,
+                "serverFarmId": "[variables('appServicePlan_ResourceId')]",
+                "siteConfig": {
+                  "metadata": [
+                    {
+                      "name": "CURRENT_STACK",
+                      "value": "dotnetcore"
+                    }
+                  ]
+                }
+              },
+              "identity": {
+                "type": "SystemAssigned"
+              }
+            },
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[variables('appServicePlan_name')]",
+              "type": "Microsoft.Web/serverFarms",
+              "apiVersion": "2015-08-01",
+              "sku": {
+                "name": "S1",
+                "tier": "Standard",
+                "family": "S",
+                "size": "S1"
+              },
+              "properties": {
+                "name": "[variables('appServicePlan_name')]"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ]
+}

+ 0 - 18
Dotnet/Warhammer/Service/DiceService.cs

@@ -26,23 +26,5 @@ namespace Warhammer.Service
             return sum;
         }
 
-        //public virtual object sword_damage()
-        //{
-        //    return this.RollDices(1, 10) + 3 + this.MF;
-        //}
-
-        //public virtual object fast_attack()
-        //{
-        //    var damage = 0;
-        //    foreach (var i in Enumerable.Range(0, 2))
-        //    {
-        //        if (this.test_cc())
-        //        {
-        //            damage += this.sword_damage();
-        //            Console.WriteLine(String.Format("Sword damage % i penetration 4", damage));
-        //        }
-        //    }
-        //    return damage;
-        //}
     }
 }

+ 24 - 0
Dotnet/Warhammer/Service/Interfaces/IPlayerService.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using Warhammer.Models;
+
+namespace Warhammer.Service.Interfaces
+{
+    public interface IPlayerService
+    {
+        Task<Player> GetById(Guid id);
+        Task<Player> FirstOrDefault(Expression<Func<Player, bool>> predicate);
+
+        Task Add(Player entity);
+        Task Update(Player entity);
+        Task Remove(Player entity);
+
+        Task<IEnumerable<Player>> GetAll();
+        Task<IEnumerable<Player>> GetWhere(Expression<Func<Player, bool>> predicate);
+
+        Task<int> CountAll();
+        Task<int> CountWhere(Expression<Func<Player, bool>> predicate);
+    }
+}

+ 65 - 0
Dotnet/Warhammer/Service/PlayerService.cs

@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using Warhammer.DataLayer.Interfaces;
+using Warhammer.Models;
+using Warhammer.Service.Interfaces;
+
+namespace Warhammer.Service
+{
+    public class PlayerService : IPlayerService
+    {
+        private readonly IPlayerRepository _playerRepository;
+
+        public PlayerService(IPlayerRepository playerRepository)
+        {
+            _playerRepository = playerRepository;
+        }
+
+        public Task Add(Player entity)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<int> CountAll()
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<int> CountWhere(Expression<Func<Player, bool>> predicate)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<Player> FirstOrDefault(Expression<Func<Player, bool>> predicate)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<IEnumerable<Player>> GetAll()
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<Player> GetById(Guid id)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task<IEnumerable<Player>> GetWhere(Expression<Func<Player, bool>> predicate)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task Remove(Player entity)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Task Update(Player entity)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 7 - 7
Dotnet/Warhammer/Startup.cs

@@ -29,16 +29,16 @@ namespace Warhammer
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
         {
-            if (env.IsDevelopment())
-            {
-                app.UseDeveloperExceptionPage();
-            }
-            else
-            {
+            //if (env.IsDevelopment())
+            //{
+            //    app.UseDeveloperExceptionPage();
+            //}
+            //else
+            //{
                 app.UseExceptionHandler("/Home/Error");
                 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                 app.UseHsts();
-            }
+            //}
 
             app.UseHttpsRedirection();
             app.UseStaticFiles();

+ 2 - 1
Dotnet/Warhammer/Warhammer.csproj.user

@@ -3,7 +3,7 @@
   <PropertyGroup>
     <View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
     <View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
-    <WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
+    <WebStackScaffolding_ViewDialogWidth>650.4</WebStackScaffolding_ViewDialogWidth>
     <WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
     <WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
     <WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
@@ -12,6 +12,7 @@
     <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
     <WebStackScaffolding_ControllerDialogWidth>650</WebStackScaffolding_ControllerDialogWidth>
     <ActiveDebugProfile>IIS Express</ActiveDebugProfile>
+    <NameOfLastUsedPublishProfile>C:\Repositories\Warhammer\Deathwatch\Dotnet\Warhammer\Properties\PublishProfiles\DeathwatchWebApp - Web Deploy.pubxml</NameOfLastUsedPublishProfile>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
     <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>