Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 15a93f2c

Přidáno uživatelem Milan Hotovec před téměř 4 roky(ů)

Area addon

Zobrazit rozdíly:

src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateDefinitionRangeAside.razor
1

1
@inject IMediator _mediator
2
@inject IToastService toastService
3

  
2 4
<aside class="@_aside review_detail">
3 5
    <div class="review_detail_header">
4 6
        <div>
......
12 14
    </div>
13 15
    <div class="review_detail_body">
14 16
        <div class="review_description_title">Datum začátku oblasti</div>
15
        <input type="date" />
17
        <input type="date" @bind-value="From" />
16 18
        <div class="review_description_title">Datum konce oblasti</div>
17
        <input type="date" />
19
        <input type="date" @bind-value="To" />
18 20
        <div class="review_description_title">Firemní výsledek oblasti</div>
19
        <input type="number" />
21
        <input type="number" @bind-value="VariCompanySuccess" />
20 22
    </div>
21 23
    <div class="review_detail_footer">
22
        <button>Uložit</button>
24
        <button @onclick="Create">Uložit</button>
23 25
        <button @onclick="Close">Zrušit</button>
24 26
    </div>
25 27
</aside>
......
88 90

  
89 91
    private string _aside;
90 92

  
93
    public DateTime From { get; set; } = DateTime.Now;
94
    public DateTime To { get; set; } = DateTime.Now.AddDays(1);
95
    public double VariCompanySuccess { get; set; }
96

  
91 97
    [Parameter]
92 98
    public bool Show { get; set; } = false;
93 99

  
94 100
    [Parameter]
95 101
    public EventCallback CloseAside { get; set; }
96 102

  
103
    [Parameter]
104
    public EventCallback LoadAreasInView { get; set; }
105

  
106
    private async Task Create()
107
    {
108
        //TODO: Check data validity
109

  
110
        var response = await _mediator.Send(new CreateNewArea.Command(From, To, VariCompanySuccess));
111

  
112
        if (response.IsSuccess)
113
        {
114
            toastService.ShowSuccess("Oblast úspěšně vytvořena");
115
            await LoadAreasInView.InvokeAsync();
116
            await Close();
117
        }
118
        else toastService.ShowError($"Cíl se nepodařilo vytvořit {response.Errors.FirstOrDefault() ?? ""}");
119
    }
120

  
97 121
    private async Task Close()
98 122
    {
99 123
        //ResetValues();
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor
23 23
        @foreach (var range in Ranges)
24 24
        {
25 25
            <tr>
26
                <td>24.4.2021</td>
27
                <td>23.4.2022</td>
28
                <td>-</td>
26
                <td>@range.From.ToShortDateString()</td>
27
                <td>@range.To.ToShortDateString()</td>
28
                <td>@(range.VariCompanySuccess ?? 0)</td>
29 29
                <td>
30 30
                    <div class="flex">
31
                        <div @onclick='() => _nav.NavigateTo("/goals/overview/test")'>
31
                        <div @onclick='() => _nav.NavigateTo($"/goals/overview/{range.Id}")'>
32 32
                            <i class="fal fa-eye"></i>
33 33
                            Zobrazit
34 34
                        </div>
35
                        <div @onclick="() => OpenAside(range)">
35
                        <div @onclick="() => OpenAside(range.Id)">
36 36
                            <i class="fal fa-edit"></i>
37 37
                            Upravit
38 38
                        </div>
......
59 59
{
60 60
    <div>Loading...</div>
61 61
}
62
<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" CloseAside="CloseAside" />
62
<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateDefinitionRangeAside Show="ShowAside" LoadAreasInView="LoadAreas" CloseAside="CloseAside" />
63 63

  
64 64
<BlazorStyled.Styled>
65 65
    .flex{
......
177 177
    [Parameter]
178 178
    public string Id { get; set; } = null!;
179 179

  
180
    private List<Guid> Ranges { get; set; } = new() { Guid.NewGuid() };
180
    private List<GlobalDefinitionArea> Ranges { get; set; } = new() { };
181 181

  
182 182
    private int PageNumber { get; set; } = 1;
183 183

  
......
193 193

  
194 194
    private void CloseAside() => (AsideId, ShowAside) = (default(Guid), false);
195 195

  
196
    private async Task LoadAreas()
197
    {
198
        var response = await _mediator.Send(new GetAllAreas.Query());
199

  
200
        if (response.IsSuccess)
201
        {
202
            Ranges = response.Result.list;
203
        }
204
    }
205

  
206
    protected async override Task OnInitializedAsync()
207
    {
208
        await base.OnInitializedAsync();
209
        await LoadAreas();
210
    }
211

  
196 212
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/_Imports.razor
27 27
@using Leuze.Modules.Goal.Application.CQRS.Goals.Commands
28 28
@using Leuze.Modules.Goal.Application.CQRS.Goals.Queries
29 29
@using Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries
30
@using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands
31
@using Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Queries
30 32
@using Leuze.Modules.Goal.Domain.Domains
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Commands/CreateNewArea.cs
1
using Leuze.Core.Application.CQRS;
2
using Leuze.Core.Domain.Repositories;
3
using Leuze.Modules.Goal.Domain.Domains;
4
using Leuze.Modules.Goal.Domain.Repositories;
5
using Microsoft.AspNetCore.Components.Authorization;
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
using System.Security.Claims;
10
using System.Text;
11
using System.Threading;
12
using System.Threading.Tasks;
13

  
14
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Commands
15
{
16
    public static class CreateNewArea
17
    {
18
        public record Command(DateTime from, DateTime to, double variCompany) : IBaseRequest<Response>;
19

  
20
        public record Response(GlobalDefinitionArea item);
21

  
22

  
23
        public class Handler : IBaseRequestHandler<Command, Response>
24
        {
25
            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
26
            private readonly AuthenticationStateProvider _authenticationStateProvider;
27
            private readonly IDomainUserRepository _domainUserRepo;
28

  
29
            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
30
            {
31
                _gdAreaRepo = gdAreaRepo;
32
                _authenticationStateProvider = authStateProvider;
33
                _domainUserRepo = domainUserRepo;
34
            }
35

  
36
            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
37
            {
38
                //TODO: user muze byt null, ale to my nechceme!!!
39
                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
40
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
41
                var user = await _domainUserRepo.GetByIdAsync(id);
42
                var allAreas = await _gdAreaRepo.GetAllAsync();
43
                var alreadyExistingAreas = await _gdAreaRepo.GetAllWithinTimeRange(request.from, request.to);
44

  
45
                if(alreadyExistingAreas.Count > 0)
46
                {
47
                    return RequestResponse<Response>.CreateErrorResponse($"V zadaném rozsahu již existuje oblast!");
48
                }
49

  
50
                GlobalDefinitionArea item = new GlobalDefinitionArea(user, request.from, request.to);
51

  
52
                await _gdAreaRepo.AddAsync(item);
53

  
54
                return RequestResponse<Response>.CreateSuccessResponse(new(item));
55
            }
56
        }
57

  
58
    }
59
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitionAreas/Queries/GetAllAreas.cs
1
using Leuze.Core.Application.CQRS;
2
using Leuze.Core.Domain.Repositories;
3
using Leuze.Modules.Goal.Domain.Domains;
4
using Leuze.Modules.Goal.Domain.Repositories;
5
using Microsoft.AspNetCore.Components.Authorization;
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
using System.Security.Claims;
10
using System.Text;
11
using System.Threading;
12
using System.Threading.Tasks;
13

  
14
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitionAreas.Queries
15
{
16
    public static class GetAllAreas
17
    {
18
        public record Query() : IBaseRequest<Response>;
19

  
20
        public record Response(List<GlobalDefinitionArea> list);
21

  
22

  
23
        public class Handler : IBaseRequestHandler<Query, Response>
24
        {
25
            private readonly IGlobalDefinitionAreaRepository _gdAreaRepo;
26
            private readonly AuthenticationStateProvider _authenticationStateProvider;
27
            private readonly IDomainUserRepository _domainUserRepository;
28

  
29
            public Handler(IGlobalDefinitionAreaRepository gdAreaRepo,
30
                AuthenticationStateProvider authenticationStateProvider, IDomainUserRepository domainUserRepository)
31
            {
32
                _gdAreaRepo = gdAreaRepo;
33
                _authenticationStateProvider = authenticationStateProvider;
34
                _domainUserRepository = domainUserRepository;
35
            }
36

  
37
            public async Task<RequestResponse<Response>> Handle(Query request, CancellationToken cancellationToken)
38
            {
39
                /*
40
                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
41
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
42
                */
43
                var gdAreas = await _gdAreaRepo.GetAllAsync();
44

  
45
                if (gdAreas == null)
46
                {
47
                    return RequestResponse<Response>.CreateErrorResponse($"Goal definition areas empty!");
48
                }
49

  
50
                return RequestResponse<Response>.CreateSuccessResponse(new(gdAreas));
51
            }
52
        }
53
    }
54
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetGoalDefinitionById.cs
11 11
using System.Threading;
12 12
using System.Threading.Tasks;
13 13

  
14
namespace Leuze.Modules.Goal.Application.CQRS.Goals.Queries
14
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries
15 15
{
16 16
    public static class GetGoalDefinitionById
17 17
    {
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs
13 13
        private GlobalDefinitionArea()
14 14
        {
15 15

  
16
        }
17
        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to) : this(creator, from, to, 0)
18
        {
16 19
        }
17 20

  
18
        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to)
21
        public GlobalDefinitionArea(DomainUser creator, DateTime from, DateTime to, double variCompany)
19 22
        {
20 23
            this.Creator = creator;
21 24
            this.CreatorId = creator.UserId;
22 25
            this.From = from;
23 26
            this.To = to;
24
            this.VariCompanySuccess = 0;
27
            this.VariCompanySuccess = variCompany;
25 28
        }
26 29

  
27 30
        public static GlobalDefinitionArea Default()
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs
23 23

  
24 24
        Task<bool> SetCompanyVariSetVariCompanySuccess(Guid id, double vari);
25 25

  
26

  
27
        Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to);
28

  
29

  
26 30
    }
27 31
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Extensions/RepositoriesExtension.cs
16 16
        public static void AddRepositories(this IServiceCollection services)
17 17
        {
18 18
            services.AddTransient<ICommentRepository,CommentRepository>();
19
            services.AddTransient<IGlobalDefinitionAreaRepository,GlobalDefinitionAreaRepository>();
19 20
            services.AddTransient<IGoalDefinitionRepository,GoalDefinitionRepository>();
20 21
            services.AddTransient<IGoalItemRepository,GoalItemRepository>();
21 22
            services.AddTransient<IGoalUpdateRepository,GoalUpdateRepository>();
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs
1
using ExtCore.Data.EntityFramework;
1
using AutoMapper;
2
using ExtCore.Data.Abstractions;
3
using Leuze.Core.Infrastructure.Persistence;
2 4
using Leuze.Modules.Goal.Domain.Domains;
3 5
using Leuze.Modules.Goal.Domain.Repositories;
4 6
using Microsoft.EntityFrameworkCore;
......
10 12

  
11 13
namespace Leuze.Modules.Goal.Infrastructure.Persistence.Repositories
12 14
{
13
    class GlobalDefinitionAreaRepository : RepositoryBase<GlobalDefinitionArea>, IGlobalDefinitionAreaRepository
15
    public class GlobalDefinitionAreaRepository : RepositoryBase<GlobalDefinitionArea>, IGlobalDefinitionAreaRepository
14 16
    {
17
        public GlobalDefinitionAreaRepository(IStorageContext context, IMapper mapper) : base(context, mapper)
18
        {
19
        }
20

  
15 21
        public async Task<bool> AddAsync(GlobalDefinitionArea gdArea)
16 22
        {
17 23
            await dbSet.AddAsync(gdArea);
......
67 73
            await storageContext.SaveChangesAsync();
68 74
            return true;
69 75
        }
76

  
77
        public async Task<List<GlobalDefinitionArea>> GetAllWithinTimeRange(DateTime from, DateTime to)
78
        {
79
            //return await dbSet.Where(item => ((item.From >= from && item.From <= to) || (item.To <= to && item.To >= from))).ToListAsync();
80
            return await dbSet.Where(item => ((item.From >= from && item.From <= to) || (item.To <= to && item.To >= from))).ToListAsync();
81
        }
70 82
    }
71 83
}
src/Presentation/Leuze.App/Leuze.App.csproj
18 18
    <DocumentationFile>..\..\..\docs\Leuze.App.xml</DocumentationFile>
19 19
  </PropertyGroup>
20 20

  
21
  <ItemGroup>
22
    <Content Remove="wwwroot\Resources\Icons\microsoft-logo.svg" />
23
  </ItemGroup>
24

  
25 21
  <ItemGroup>
26 22
    <Resource Include="wwwroot\Resources\Icons\microsoft-logo.svg">
27 23
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
......
55 51
    <ProjectReference Include="..\..\Core\Infrastructure\Leuze.Core.Infrastructure.Persistence\Leuze.Core.Infrastructure.Persistence.csproj" />
56 52
  </ItemGroup>
57 53

  
54
  <ItemGroup>
55
    <Content Update="wwwroot\Resources\Icons\microsoft-logo.svg">
56
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
57
    </Content>
58
  </ItemGroup>
59

  
58 60
</Project>

Také k dispozici: Unified diff