commit 15a93f2c7eccbbe774fce92eaa1ecc165a95cb66
Author: Silentkiller159 <milanhotovec@seznam.cz>
Date:   Sat May 15 11:51:26 2021 +0200

    Area addon

diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateDefinitionRangeAside.razor b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateDefinitionRangeAside.razor
index 3eb45cc..7e59d52 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateDefinitionRangeAside.razor
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateDefinitionRangeAside.razor
@@ -1,4 +1,6 @@
-﻿
+﻿@inject IMediator _mediator
+@inject IToastService toastService
+
 <aside class="@_aside review_detail">
     <div class="review_detail_header">
         <div>
@@ -12,14 +14,14 @@
     </div>
     <div class="review_detail_body">
         <div class="review_description_title">Datum začátku oblasti</div>
-        <input type="date" />
+        <input type="date" @bind-value="From" />
         <div class="review_description_title">Datum konce oblasti</div>
-        <input type="date" />
+        <input type="date" @bind-value="To" />
         <div class="review_description_title">Firemní výsledek oblasti</div>
-        <input type="number" />
+        <input type="number" @bind-value="VariCompanySuccess" />
     </div>
     <div class="review_detail_footer">
-        <button>Uložit</button>
+        <button @onclick="Create">Uložit</button>
         <button @onclick="Close">Zrušit</button>
     </div>
 </aside>
@@ -88,12 +90,34 @@
 
     private string _aside;
 
+    public DateTime From { get; set; } = DateTime.Now;
+    public DateTime To { get; set; } = DateTime.Now.AddDays(1);
+    public double VariCompanySuccess { get; set; }
+
     [Parameter]
     public bool Show { get; set; } = false;
 
     [Parameter]
     public EventCallback CloseAside { get; set; }
 
+    [Parameter]
+    public EventCallback LoadAreasInView { get; set; }
+
+    private async Task Create()
+    {
+        //TODO: Check data validity
+
+        var response = await _mediator.Send(new CreateNewArea.Command(From, To, VariCompanySuccess));
+
+        if (response.IsSuccess)
+        {
+            toastService.ShowSuccess("Oblast úspěšně vytvořena");
+            await LoadAreasInView.InvokeAsync();
+            await Close();
+        }
+        else toastService.ShowError($"Cíl se nepodařilo vytvořit {response.Errors.FirstOrDefault() ?? ""}");
+    }
+
     private async Task Close()
     {
         //ResetValues();
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor
index d40c931..7b162a6 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor
@@ -23,16 +23,16 @@
         @foreach (var range in Ranges)
         {
             <tr>
-                <td>24.4.2021</td>
-                <td>23.4.2022</td>
-                <td>-</td>
+                <td>@range.From.ToShortDateString()</td>
+                <td>@range.To.ToShortDateString()</td>
+                <td>@(range.VariCompanySuccess ?? 0)</td>
                 <td>
                     <div class="flex">
-                        <div @onclick='() => _nav.NavigateTo("/goals/overview/test")'>
+                        <div @onclick='() => _nav.NavigateTo($"/goals/overview/{range.Id}")'>
                             <i class="fal fa-eye"></i>
                             Zobrazit
                         </div>
-                        <div @onclick="() => OpenAside(range)">
+                        <div @onclick="() => OpenAside(range.Id)">
                             <i class="fal fa-edit"></i>
                             Upravit
                         </div>
@@ -59,7 +59,7 @@ else
 {
     <div>Loading...</div>
 }
-<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" CloseAside="CloseAside" />
+<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" LoadAreasInView="LoadAreas" CloseAside="CloseAside" />
 
 <BlazorStyled.Styled>
     .flex{
@@ -177,7 +177,7 @@ else
     [Parameter]
     public string Id { get; set; } = null!;
 
-    private List<Guid> Ranges { get; set; } = new() { Guid.NewGuid() };
+    private List<GlobalDefinitionArea> Ranges { get; set; } = new() { };
 
     private int PageNumber { get; set; } = 1;
 
@@ -193,4 +193,20 @@ else
 
     private void CloseAside() => (AsideId, ShowAside) = (default(Guid), false);
 
+    private async Task LoadAreas()
+    {
+        var response = await _mediator.Send(new GetAllAreas.Query());
+
+        if (response.IsSuccess)
+        {
+            Ranges = response.Result.list;
+        }
+    }
+
+    protected async override Task OnInitializedAsync()
+    {
+        await base.OnInitializedAsync();
+        await LoadAreas();
+    }
+
 }
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/_Imports.razor b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/_Imports.razor
index 8bc45af..9080888 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/_Imports.razor
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/_Imports.razor
@@ -27,4 +27,6 @@
 @using Leuze.Modules.Goal.Application.CQRS.Goals.Commands
 @using Leuze.Modules.Goal.Application.CQRS.Goals.Queries
 @using Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries
+@using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands
+@using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Queries
 @using Leuze.Modules.Goal.Domain.Domains
\ No newline at end of file
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/CreateNewArea.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/CreateNewArea.cs
new file mode 100644
index 0000000..6fc38b6
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/CreateNewArea.cs
@@ -0,0 +1,59 @@
+﻿using Leuze.Core.Application.CQRS;
+using Leuze.Core.Domain.Repositories;
+using Leuze.Modules.Goal.Domain.Domains;
+using Leuze.Modules.Goal.Domain.Repositories;
+using Microsoft.AspNetCore.Components.Authorization;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Claims;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands
+{
+    public static class CreateNewArea
+    {
+        public record Command(DateTime from, DateTime to, double variCompany) : IBaseRequest<Response>;
+
+        public record Response(GlobalDefinitionArea item);
+
+
+        public class Handler : IBaseRequestHandler<Command, Response>
+        {
+            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
+            private readonly AuthenticationStateProvider _authenticationStateProvider;
+            private readonly IDomainUserRepository _domainUserRepo;
+
+            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
+            {
+                _gdAreaRepo = gdAreaRepo;
+                _authenticationStateProvider = authStateProvider;
+                _domainUserRepo = domainUserRepo;
+            }
+
+            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
+            {
+                //TODO: user muze byt null, ale to my nechceme!!!
+                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
+                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
+                var user = await _domainUserRepo.GetByIdAsync(id);
+                var allAreas = await _gdAreaRepo.GetAllAsync();
+                var alreadyExistingAreas = await _gdAreaRepo.GetAllWithinTimeRange(request.from, request.to);
+
+                if(alreadyExistingAreas.Count > 0)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"V zadaném rozsahu již existuje oblast!");
+                }
+
+                GlobalDefinitionArea item = new GlobalDefinitionArea(user, request.from, request.to);
+
+                await _gdAreaRepo.AddAsync(item);
+
+                return RequestResponse<Response>.CreateSuccessResponse(new(item));
+            }
+        }
+
+    }
+}
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAllAreas.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAllAreas.cs
new file mode 100644
index 0000000..07dafc3
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAllAreas.cs
@@ -0,0 +1,54 @@
+﻿using Leuze.Core.Application.CQRS;
+using Leuze.Core.Domain.Repositories;
+using Leuze.Modules.Goal.Domain.Domains;
+using Leuze.Modules.Goal.Domain.Repositories;
+using Microsoft.AspNetCore.Components.Authorization;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Claims;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Queries
+{
+    public static class GetAllAreas
+    {
+        public record Query() : IBaseRequest<Response>;
+
+        public record Response(List<GlobalDefinitionArea> list);
+
+
+        public class Handler : IBaseRequestHandler<Query, Response>
+        {
+            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
+            private readonly AuthenticationStateProvider _authenticationStateProvider;
+            private readonly IDomainUserRepository _domainUserRepository;
+
+            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo,
+                AuthenticationStateProvider authenticationStateProvider, IDomainUserRepository domainUserRepository)
+            {
+                _gdAreaRepo = gdAreaRepo;
+                _authenticationStateProvider = authenticationStateProvider;
+                _domainUserRepository = domainUserRepository;
+            }
+
+            public async Task<RequestResponse<Response>> Handle(Query request, CancellationToken cancellationToken)
+            {
+                /*
+                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
+                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
+                */
+                var gdAreas = await _gdAreaRepo.GetAllAsync();
+
+                if (gdAreas == null)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Goal definition areas empty!");
+                }
+
+                return RequestResponse<Response>.CreateSuccessResponse(new(gdAreas));
+            }
+        }
+    }
+}
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetGoalDefinitionById.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetGoalDefinitionById.cs
index ad5f008..f90dd7d 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetGoalDefinitionById.cs
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetGoalDefinitionById.cs
@@ -11,7 +11,7 @@ using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 
-namespace Leuze.Modules.Goal.Application.CQRS.Goals.Queries
+namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries
 {
     public static class GetGoalDefinitionById
     {
diff --git a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs
index a582616..825e270 100644
--- a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs
+++ b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs
@@ -13,15 +13,18 @@ namespace Leuze.Modules.Goal.Domain.Domains
         private GlobalDefinitionArea()
         {
 
+        }
+        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to) : this(creator, from, to, 0)
+        {
         }
 
-        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to)
+        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to, double variCompany)
         {
             this.Creator = creator;
             this.CreatorId = creator.UserId;
             this.From = from;
             this.To = to;
-            this.VariCompanySuccess = 0;
+            this.VariCompanySuccess = variCompany;
         }
 
         public static GlobalDefinitionArea Default()
diff --git a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs
index db416ef..527b6f7 100644
--- a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs
+++ b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs
@@ -23,5 +23,9 @@ namespace Leuze.Modules.Goal.Domain.Repositories
 
         Task<bool> SetCompanyVariSetVariCompanySuccess(Guid id, double vari);
 
+
+        Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to);
+
+
     }
 }
diff --git a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs
index 03a464c..e17c60a 100644
--- a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs
+++ b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs
@@ -16,6 +16,7 @@ namespace Leuze.Modules.Goal.Infrastructure.Persistence.Extensions
         public static void AddRepositories(this IServiceCollection services)
         {
             services.AddTransient<ICommentRepository,CommentRepository>();
+            services.AddTransient<IGlobalDefinitionAreaRepository,GlobalDefinitionAreaRepository>();
             services.AddTransient<IGoalDefinitionRepository,GoalDefinitionRepository>();
             services.AddTransient<IGoalItemRepository,GoalItemRepository>();
             services.AddTransient<IGoalUpdateRepository,GoalUpdateRepository>();
diff --git a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs
index 8330f21..4a499e0 100644
--- a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs
+++ b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs
@@ -1,4 +1,6 @@
-﻿using ExtCore.Data.EntityFramework;
+﻿using AutoMapper;
+using ExtCore.Data.Abstractions;
+using Leuze.Core.Infrastructure.Persistence;
 using Leuze.Modules.Goal.Domain.Domains;
 using Leuze.Modules.Goal.Domain.Repositories;
 using Microsoft.EntityFrameworkCore;
@@ -10,8 +12,12 @@ using System.Threading.Tasks;
 
 namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
 {
-    class GlobalDefinitionAreaRepository : RepositoryBase<GlobalDefinitionArea>, IGlobalDefinitionAreaRepository
+    public class GlobalDefinitionAreaRepository : RepositoryBase<GlobalDefinitionArea>, IGlobalDefinitionAreaRepository
     {
+        public GlobalDefinitionAreaRepository(IStorageContext context, IMapper mapper) : base(context, mapper)
+        {
+        }
+
         public async Task<bool> AddAsync(GlobalDefinitionArea gdArea)
         {
             await dbSet.AddAsync(gdArea);
@@ -67,5 +73,11 @@ namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
             await storageContext.SaveChangesAsync();
             return true;
         }
+
+        public async Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to)
+        {
+            //return await dbSet.Where(item => ((item.From >= from && item.From <= to) || (item.To <= to && item.To >= from))).ToListAsync();
+            return await dbSet.Where(item => ((item.From >= from && item.From <= to) || (item.To <= to && item.To >= from))).ToListAsync();
+        }
     }
 }
diff --git a/src/Presentation/Leuze.App/Leuze.App.csproj b/src/Presentation/Leuze.App/Leuze.App.csproj
index 1ae7a76..d905b63 100644
--- a/src/Presentation/Leuze.App/Leuze.App.csproj
+++ b/src/Presentation/Leuze.App/Leuze.App.csproj
@@ -18,10 +18,6 @@
     <DocumentationFile>..\..\..\docs\Leuze.App.xml</DocumentationFile>
   </PropertyGroup>
 
-  <ItemGroup>
-    <Content Remove="wwwroot\Resources\Icons\microsoft-logo.svg" />
-  </ItemGroup>
-
   <ItemGroup>
     <Resource Include="wwwroot\Resources\Icons\microsoft-logo.svg">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -55,4 +51,10 @@
     <ProjectReference Include="..\..\Core\Infrastructure\Leuze.Core.Infrastructure.Persistence\Leuze.Core.Infrastructure.Persistence.csproj" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="wwwroot\Resources\Icons\microsoft-logo.svg">
+      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
 </Project>
