commit 73fdd4c627e2bebe7cf680866679544deb27ae6f
Author: Silentkiller159 <milanhotovec@seznam.cz>
Date:   Sun May 16 23:57:39 2021 +0200

    Area -> Goal view + basic edit prepared

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 7e59d52..2497a57 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
@@ -97,6 +97,15 @@
     [Parameter]
     public bool Show { get; set; } = false;
 
+    private Guid _asideId = default(Guid);
+    [Parameter]
+    public Guid AsideId {
+        get { return _asideId; }
+        set { _asideId = value;
+            LoadArea();
+        }
+    }
+
     [Parameter]
     public EventCallback CloseAside { get; set; }
 
@@ -105,17 +114,54 @@
 
     private async Task Create()
     {
-        //TODO: Check data validity
+        if(AsideId != default(Guid))
+        {
+            await EditArea();
+        }
+        else
+        {
+            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($"Oblast se nepodařilo vytvořit {response.Errors.FirstOrDefault() ?? ""}");
+        }
+    }
 
-        var response = await _mediator.Send(new CreateNewArea.Command(From, To, VariCompanySuccess));
+    private async Task LoadArea()
+    {
+        if (AsideId != default(Guid))
+        {
+            var response = await _mediator.Send(new GetAreaById.Query(AsideId));
+
+            if (response.IsSuccess)
+            {
+                From = response.Result.area.From;
+                To = response.Result.area.To;
+                VariCompanySuccess = response.Result.area.VariCompanySuccess ?? 0;
+            }
+            else toastService.ShowError($"Oblast se nepodařilo načíst {response.Errors.FirstOrDefault() ?? ""}");
+        }
+    }
 
-        if (response.IsSuccess)
+    private async Task EditArea()
+    {
+        if(AsideId != default(Guid))
         {
-            toastService.ShowSuccess("Oblast úspěšně vytvořena");
-            await LoadAreasInView.InvokeAsync();
-            await Close();
+            var response = await _mediator.Send(new EditArea.Command(AsideId, From, To, VariCompanySuccess));
+
+            if (response.IsSuccess)
+            {
+                toastService.ShowSuccess("Oblast úspěšně editována");
+                await LoadAreasInView.InvokeAsync();
+                await Close();
+            }
+            else toastService.ShowError($"Oblast se nepodařilo editovat {response.Errors.FirstOrDefault() ?? ""}");
         }
-        else toastService.ShowError($"Cíl se nepodařilo vytvořit {response.Errors.FirstOrDefault() ?? ""}");
     }
 
     private async Task Close()
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/GoalDetailAside.razor b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/GoalDetailAside.razor
index e29ced4..7bab29c 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/GoalDetailAside.razor
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/GoalDetailAside.razor
@@ -1,4 +1,5 @@
 ﻿@inject IMediator _mediator
+@inject IToastService toastService
 
 <aside class="@_aside goal_detail">
     <div class="goal_detail_header">
@@ -23,10 +24,11 @@
     </div>
     <div class="goal_detail_body">
         <div class="goal_detail_area">
-            <input class="goal_name" type="text" placeholder="Zadejte název cíle" value="@DetailItem.Name" />
+            <input class="goal_name" type="text" placeholder="Zadejte název cíle" @bind-value="Name" />
             <div class="goal_description_title">Popis cíle</div>
             <textarea oninput='this.style.height = "";this.style.height = this.scrollHeight + "px"'
-                      class="goal_description" placeholder="Vyplňte popis cíle">@DetailItem.Description</textarea>
+                      class="goal_description" placeholder="Vyplňte popis cíle">@Description</textarea>
+            <button @onclick="EditGoal">Uložit změny</button>
         </div>
         <div class="goal_communication_area">
             <div class="goal_communication_item">
@@ -326,6 +328,13 @@
     [Parameter]
     public bool Show { get; set; } = false;
 
+
+    public string Name { get; set; } = "";
+
+
+    public string Description { get; set; } = "";
+
+
     private Guid _detailId;
     [Parameter]
     public Guid DetailId
@@ -357,7 +366,20 @@
         if (response.IsSuccess)
         {
             DetailItem = response.Result.item;
+            Name = DetailItem.Name;
+            Description = DetailItem.Description;
+        }
+    }
+
+    private async Task EditGoal()
+    {
+        var response = await _mediator.Send(new EditGoal.Command(DetailId, Name, Description));
+
+        if (response.IsSuccess)
+        {
+            toastService.ShowSuccess("Cíl úspěšně editován");
         }
+        else toastService.ShowError($"Cíl se nepodařilo editovat {response.Errors.FirstOrDefault() ?? ""}");
     }
 
     private async Task Close()
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 7b162a6..63e75d0 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
@@ -59,7 +59,7 @@ else
 {
     <div>Loading...</div>
 }
-<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" LoadAreasInView="LoadAreas" CloseAside="CloseAside" />
+<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" AsideId="AsideId" LoadAreasInView="LoadAreas" CloseAside="CloseAside" />
 
 <BlazorStyled.Styled>
     .flex{
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalsManagement.razor b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalsManagement.razor
index 8b58da8..ac2f122 100644
--- a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalsManagement.razor
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalsManagement.razor
@@ -1,4 +1,4 @@
-﻿@page "/goals/overview/{id}"
+﻿@page "/goals/overview/{id:guid}"
 @attribute [Authorize]
 @layout MainLayout
 @inject IMediator _mediator
@@ -17,7 +17,7 @@
         </button>
     </div>
 </div>
-@if (Ranges is not null)
+@if (Definitions is not null)
 {
     <table class="actions" style="width:100%">
         <tr>
@@ -26,19 +26,19 @@
             <th>Vytvořil</th>
             <th>Akce</th>
         </tr>
-        @foreach (var range in Ranges)
+        @foreach (var range in Definitions)
         {
             <tr>
-                <td>Nová definice</td>
-                <td>John Doe</td>
-                <td>Admin Admin</td>
+                <td>@range.Name</td>
+                <td>@range.Owner.Name</td>
+                <td>@range.Creator.Name</td>
                 <td>
                     <div class="flex">
-                        <div @onclick='() => _nav.NavigateTo("/goals/detail/test")'>
+                        <div @onclick='() => _nav.NavigateTo($"/goals/detail/{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>
@@ -47,7 +47,7 @@
             </tr>
         }
     </table>
-    @if (Ranges.Count > 0)
+    @if (Definitions.Count > 0)
     {
         <div class="pagination">
             <div class="left">
@@ -57,7 +57,7 @@
                 <button class="pagination_button"><img class="pagination_icon" src="/Resources/Icons/chevron-right.svg" /></button>
                 <button class="pagination_button"><img class="pagination_icon" src="/Resources/Icons/chevron-double-right.svg" /></button>
             </div>
-            <div class="right">Zobrazeno <b>@Ranges.Count z @Total</b></div>
+            <div class="right">Zobrazeno <b>@Definitions.Count z @Total</b></div>
         </div>
     }
 }
@@ -189,9 +189,9 @@ else
 @code {
 
     [Parameter]
-    public string Id { get; set; } = null!;
+    public Guid Id { get; set; } = default(Guid);
 
-    private List<Guid> Ranges { get; set; } = new() { Guid.NewGuid() };
+    private List<GoalDefinition> Definitions { get; set; } = new();
 
     private int PageNumber { get; set; } = 1;
 
@@ -205,4 +205,20 @@ else
 
     private void CloseAside() => (ShowAside) = (false);
 
+    private async Task GetMyDefinitions()
+    {
+        var response = await _mediator.Send(new GetAllForArea.Query(Id));
+
+        if (response.IsSuccess)
+        {
+            Definitions = response.Result.list;
+        }
+    }
+
+    protected async override Task OnInitializedAsync()
+    {
+        await base.OnInitializedAsync();
+        await GetMyDefinitions();
+    }
+
 }
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
index 2de143d..3c87414 100644
--- 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
@@ -35,11 +35,14 @@ namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands
 
             public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
             {
-                //TODO: user muze byt null, ale to my nechceme!!!
+                if(request.to <= request.from)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Zadán nevalidní rozsah!");
+                }
+
                 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)
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/EditArea.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/EditArea.cs
new file mode 100644
index 0000000..1d8681a
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/EditArea.cs
@@ -0,0 +1,57 @@
+﻿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 EditArea
+    {
+        public record Command(Guid id, DateTime from, DateTime to, double variCompany) : IBaseRequest<Response>;
+
+        public record Response(GlobalDefinitionArea item);
+
+
+        public class Handler : IBaseRequestHandler<Command, Response>
+        {
+            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
+
+            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo)
+            {
+                _gdAreaRepo = gdAreaRepo;
+            }
+
+            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
+            {
+                if(request.to <= request.from)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Zadán nevalidní rozsah!");
+                }
+
+                var item = await _gdAreaRepo.GetByIdAsync(request.id);
+                var alreadyExistingAreas = await _gdAreaRepo.GetAllWithinTimeRange(request.from, request.to);
+                alreadyExistingAreas.Remove(item); //remove, will be changed -> or it will cause error
+
+                if(alreadyExistingAreas.Count > 0)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"V zadaném rozsahu již existuje oblast!");
+                }
+
+                await _gdAreaRepo.SetFrom(request.id, item.From);;
+                await _gdAreaRepo.SetTo(request.id, item.To);
+                await _gdAreaRepo.SetVariCompanySuccess(request.id, item.VariCompanySuccess);
+
+                return RequestResponse<Response>.CreateSuccessResponse(new(item));
+            }
+        }
+
+    }
+}
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAreaById.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAreaById.cs
new file mode 100644
index 0000000..15d4551
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAreaById.cs
@@ -0,0 +1,45 @@
+﻿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 GetAreaById
+    {
+        public record Query(Guid id) : IBaseRequest<Response>;
+
+        public record Response(GlobalDefinitionArea area);
+
+
+        public class Handler : IBaseRequestHandler<Query, Response>
+        {
+            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
+
+            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo)
+            {
+                _gdAreaRepo = gdAreaRepo;
+            }
+
+            public async Task<RequestResponse<Response>> Handle(Query request, CancellationToken cancellationToken)
+            {
+                var gdArea = await _gdAreaRepo.GetByIdAsync(request.id);
+
+                if (gdArea == null)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Zadané ID není v databázi!");
+                }
+
+                return RequestResponse<Response>.CreateSuccessResponse(new(gdArea));
+            }
+        }
+    }
+}
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetAllForArea.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetAllForArea.cs
new file mode 100644
index 0000000..3f4e8ee
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetAllForArea.cs
@@ -0,0 +1,45 @@
+﻿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.GoalDefinitions.Queries
+{
+    public static class GetAllForArea
+    {
+        public record Query(Guid areaId) : IBaseRequest<Response>;
+
+        public record Response(List<GoalDefinition> list);
+
+
+        public class Handler : IBaseRequestHandler<Query, Response>
+        {
+            private readonly IGoalDefinitionRepository _goalDefinitionRepo;
+
+            public Handler(IGoalDefinitionRepository goalDefinitionRepo)
+            {
+                _goalDefinitionRepo = goalDefinitionRepo;
+            }
+
+            public async Task<RequestResponse<Response>> Handle(Query request, CancellationToken cancellationToken)
+            {
+                var goalDefs = await _goalDefinitionRepo.GetAllForAreaAsync(request.areaId);
+
+                if (goalDefs == null)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Nelze načíst definice pro oblast: {request.areaId}!");
+                }
+
+                return RequestResponse<Response>.CreateSuccessResponse(new(goalDefs));
+            }
+        }
+    }
+}
diff --git a/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/EditGoal.cs b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/EditGoal.cs
new file mode 100644
index 0000000..2479c9c
--- /dev/null
+++ b/src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/Goals/Commands/EditGoal.cs
@@ -0,0 +1,66 @@
+﻿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.Goals.Commands
+{
+    public static class EditGoal
+    {
+        public record Command(Guid goalId, string name, string description) : IBaseRequest<Response>;
+
+        public record Response();
+
+
+        public class Handler : IBaseRequestHandler<Command, Response>
+        {
+            private readonly IGoalItemRepository _goalItemRepo;
+            private readonly IGoalDefinitionRepository _goalDefinitionRepo;
+            private readonly AuthenticationStateProvider _authenticationStateProvider;
+            private readonly IDomainUserRepository _domainUserRepository;
+
+            public Handler(IGoalItemRepository goalItemRepo, IGoalDefinitionRepository goalDefinitionRepo, 
+                AuthenticationStateProvider authenticationStateProvider, IDomainUserRepository domainUserRepository)
+            {
+                _goalItemRepo = goalItemRepo;
+                _goalDefinitionRepo = goalDefinitionRepo;
+                _authenticationStateProvider = authenticationStateProvider;
+                _domainUserRepository = domainUserRepository;
+            }
+
+            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 _domainUserRepository.GetByIdAsync(id);
+
+                var goal = await _goalItemRepo.GetByIdAsync(request.goalId);
+
+                if(goal == null)
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Cíl s ID: {request.goalId} nebyl nalezen!");
+                }
+
+                if(request.name == null || request.name == "")
+                {
+                    return RequestResponse<Response>.CreateErrorResponse($"Nelze změnit název cíle");
+                }
+
+                await _goalItemRepo.SetNameAsync(request.goalId, request.name);
+                await _goalItemRepo.SetDescriptionAsync(request.goalId, request.description);
+
+                return RequestResponse<Response>.CreateSuccessResponse(new());
+            }
+        }
+
+    }
+}
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 825e270..9b09f66 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
@@ -51,7 +51,7 @@ namespace Leuze.Modules.Goal.Domain.Domains
             this.To = to;
         }
 
-        public void SetVariCompanySuccess(double vari)
+        public void SetVariCompanySuccess(double? vari)
         {
             this.VariCompanySuccess = vari;
         }
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 95073d2..d04bafb 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
@@ -21,7 +21,7 @@ namespace Leuze.Modules.Goal.Domain.Repositories
 
         Task<bool> SetTo(Guid id, DateTime to);
 
-        Task<bool> SetVariCompanySuccess(Guid id, double vari);
+        Task<bool> SetVariCompanySuccess(Guid id, double? vari);
 
 
         Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to);
diff --git a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs
index 53d00b2..0033b9d 100644
--- a/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs
+++ b/src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs
@@ -12,6 +12,8 @@ namespace Leuze.Modules.Goal.Domain.Repositories
     {
         Task<List<GoalDefinition>> GetAllForUserAsync(Guid userId);
 
+        Task<List<GoalDefinition>> GetAllForAreaAsync(Guid areaId);
+
         Task<List<GoalDefinition>> GetAllAsync();
 
         Task<GoalDefinition> GetByIdAsync(Guid id);
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 46cc571..78641d9 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
@@ -47,7 +47,7 @@ namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
             return true;
         }
 
-        public async Task<bool> SetVariCompanySuccess(Guid id, double vari)
+        public async Task<bool> SetVariCompanySuccess(Guid id, double? vari)
         {
             GlobalDefinitionArea item = await dbSet.FindAsync(id);
             if (item == null) return false;
@@ -76,16 +76,7 @@ namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
 
         public async Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to)
         {
-            GlobalDefinitionArea gdArea = dbSet.FirstOrDefault();
-            if(gdArea != null)
-            {
-                Console.WriteLine(gdArea.From >= from);
-                Console.WriteLine(gdArea.From <= to);
-                Console.WriteLine(gdArea.To >= from);
-                Console.WriteLine(gdArea.To <= 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();
+            return await dbSet.Where(item => ((from >= item.From && from <= item.To) || (to <= item.To && to >= item.From))).ToListAsync();
         }
     }
 }
diff --git a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs
index f231796..dc3eaa9 100644
--- a/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs
+++ b/src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs
@@ -38,6 +38,11 @@ namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
             return true;
         }
 
+        public async Task<List<GoalDefinition>> GetAllForAreaAsync(Guid areaId)
+        {
+            return await dbSet.Include(item => item.Creator).Include(item => item.Owner).Where(item => item.GDAreaId == areaId).ToListAsync();
+        }
+
         public async Task<List<GoalDefinition>> GetAllForUserAsync(Guid userId)
         {
             return await dbSet.Include(item => item.Creator).Include(item => item.Goals).Include(item => item.GDArea).Where(item => item.OwnerId == userId).ToListAsync();
