Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 632f4dec

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

Minor changes

Zobrazit rozdíly:

src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateGoalDefinition.razor
1
@inject IMediator _mediator
2
@inject IToastService toastService
3
@inject IStringLocalizer<CreateGoalDefinition> T
4
<aside class="@_aside review_detail">
5
    <div class="review_detail_header">
6
        <div>@T["Title"]</div>
7
        <div>
8
            <div class="close_button" @onclick="Close">
9
                <i class="fal fa-times"></i>
10
            </div>
11
        </div>
12
    </div>
13
    <div class="review_detail_body">
14
        <div class="input_row">
15
            <label class="input_label">@T["Name"]</label>
16
            <input type="text" @bind-value="Name" />
17
        </div>
18
        <div class="input_row">
19
            <label class="input_label">@T["User"]</label>
20
            <select asp-for="SelectedUser">
21
                @foreach (var user in UnassignedUsers)
22
                {
23
                    //<option value="" disabled>@T["SelectUser"]</option>
24
                    <option value="@user.Id">@user.Name</option>
25
                }
26
            </select>
27
        </div>
28
        <div class="input_row">
29
            <label class="input_label">@T["Hours"]</label>
30
            <input type="number" @bind-value="Hours" />
31
        </div>
32
        <div class="input_row">
33
            <label class="input_label">@T["Finance"]</label>
34
            <input type="number" @bind-value="FinanceBase"/>
35
        </div>
36
    </div>
37
    <div class="review_detail_footer">
38
        <button @onclick="Create">@T["Create"]</button>
39
        <button @onclick="Close">@T["Cancel"]</button>
40
    </div>
41
</aside>
42

  
43
<BlazorStyled.Styled @bind-Classname="@_aside">
44
    right: @(Show ? "0" : "-615")px;
45
</BlazorStyled.Styled>
46
<BlazorStyled.Styled>
47
    .input_row {
48
    margin-bottom: 24px;
49
    }
50
    .input_row select {
51
    width: 100%;
52
    padding: 12px 16px;
53
    border-radius: 4px;
54
    border: 1px solid rgb(200, 200, 200);
55
    font-size: 14px;
56
    }
57
    .input_row input:not([type="checkbox"]) {
58
    width: calc(100% - 34px);
59
    padding: 12px 16px;
60
    border-radius: 4px;
61
    border: 1px solid #C8C8C8;
62
    font-size: 14px;
63
    }
64
    .input_row label.input_label {
65
    font-size: 16px;
66
    font-weight: 700;
67
    color: #111111;
68
    padding-bottom: 4px;
69
    display: block;
70
    }
71
</BlazorStyled.Styled>
72
<BlazorStyled.Styled>
73
    .review_detail {
74
    width: 600px;
75
    height: 100%;
76
    position: fixed;
77
    top: 0;
78
    transition: .25s right;
79
    background-color: white;
80
    -webkit-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
81
    -moz-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
82
    box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
83
    }
84

  
85
    .review_detail_header > div {
86
    height: 100%;
87
    display: flex;
88
    align-items: center;
89
    }
90

  
91
    .review_detail_header {
92
    padding: 12px 24px;
93
    border-bottom: 1px solid #11111122;
94
    height: 26px;
95
    display: flex;
96
    align-items: center;
97
    justify-content: space-between;
98
    }
99

  
100
    .review_detail_body{
101
    padding: 16px 24px;
102
    height: calc(100% - 143px - 50px - 12px);
103
    overflow-y: auto;
104
    overflow-x: hidden;
105
    }
106

  
107
    .review_detail_footer{
108
    height: 36px;
109
    background-color: #F6F8F9;
110
    position: absolute;
111
    bottom: 0;
112
    left: 0;
113
    width: calc(100% - 50px);
114
    display: grid;
115
    padding: 24px;
116
    grid-template-columns: repeat(2, 1fr);
117
    }
118

  
119
    .review_detail_footer button:first-child{
120
    margin-right: 12px;
121
    }
122

  
123
    .review_detail_footer button:last-child{
124
    margin-left: 12px;
125
    }
126
    .review_button {
127
    color: red;
128
    cursor: pointer;
129
    opacity: .75;
130
    }
131

  
132
    .review_button:hover {
133
    opacity: 1;
134
    }
135

  
136
    .review_button.accepted {
137
    color: green;
138
    }
139

  
140
    .review_button:not(:last-child) {
141
    margin-right: 16px;
142
    }
143
    .review_detail_body .review_description {
144
    padding: 8px 12px;
145
    border: 1px solid white;
146
    width: calc(100% - 24px);
147
    outline: none;
148
    margin: 12px 24px 24px 24px;
149
    }
150

  
151
    .review_detail_body .review_description_title {
152
    margin: 0 24px;
153
    }
154

  
155
    .review_description_paragraph{
156
    margin: 12px 24px 24px 24px;
157
    }
158

  
159
    .review_detail_body .review_description:hover{
160
    border: 1px solid #EEEEEE;
161
    }
162

  
163
    .review_detail_body .review_description:focus{
164
    border: 1px solid #A8A8A8;
165
    }
166
</BlazorStyled.Styled>
167

  
168
@code {
169

  
170
    private string _aside;
171

  
172
    private Guid _asideId = default(Guid);
173

  
174
    [Parameter]
175
    public Guid AsideId
176
    {
177
        get { return _asideId; }
178
        set
179
        {
180
            _asideId = value;
181
            InitAside();
182
        }
183
    }
184

  
185
    [Parameter]
186
    public bool Show { get; set; } = false;
187

  
188
    [Parameter]
189
    public GlobalDefinitionArea Area { get; set; } = GlobalDefinitionArea.Default();
190

  
191
    [Parameter]
192
    public EventCallback CloseAside { get; set; }
193

  
194
    private string Name { get; set; } = $"";
195
    private List<UserShortDto> UnassignedUsers { get; set; } = new();
196
    public Guid SelectedUser { get; set; } = default(Guid);
197
    private double Hours { get; set; } = 0;
198
    private double FinanceBase { get; set; } = 0;
199

  
200
    private async Task InitAside()
201
    {
202
        var response = await _mediator.Send(new GetAreaById.Query(AsideId));
203

  
204
        if (response.IsSuccess)
205
        {
206
            //toastService.ShowSuccess("Oblast úspěšně vytvořena");
207
            Area = response.Result.area;
208
        }
209
        else toastService.ShowError($"Oblast se nepodařilo načíst {response.Errors.FirstOrDefault() ?? ""}");
210

  
211
        var response2 = await _mediator.Send(new GetAllUnassignedInArea.Query(AsideId));
212

  
213
        if (response2.IsSuccess)
214
        {
215
            //toastService.ShowSuccess("Oblast úspěšně vytvořena");
216
            UnassignedUsers = response2.Result.list;
217
        }
218
        else toastService.ShowError($"Seznam nepřiřazených uživatelů se nepodařilo načíst {response2.Errors.FirstOrDefault() ?? ""}");
219
    }
220

  
221
    private async Task Create()
222
    {
223
        toastService.ShowError($"Selected: {SelectedUser}");
224
    }
225

  
226
    private async Task Close()
227
    {
228
        //ResetValues();
229
        await CloseAside.InvokeAsync();
230
    }
231

  
232
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/Components/CreateGoalDefinitionAside.razor
1
@inject IMediator _mediator
2
@inject IToastService toastService
3
@inject IStringLocalizer<CreateGoalDefinitionAside> T
4
<aside class="@_aside review_detail">
5
    <div class="review_detail_header">
6
        <div>@((AsideId != default(Guid)) ? T["TitleEdit"] : T["TitleCreate"] )</div>
7
        <div>
8
            <div class="close_button" @onclick="Close">
9
                <i class="fal fa-times"></i>
10
            </div>
11
        </div>
12
    </div>
13
    <div class="review_detail_body">
14
        <div class="input_row">
15
            <label class="input_label">@T["Name"]</label>
16
            <input type="text" @bind-value="Name" />
17
        </div>
18
        @if (AsideId == default(Guid))
19
        {
20
            <div class="input_row">
21
                <label class="input_label">@T["User"]</label>
22
                <select @bind="SelectedUser">
23
                    @foreach (var user in UnassignedUsers)
24
                    {
25
                        //<option value="" disabled>@T["SelectUser"]</option>
26
                        <option value="@user.Id">@user.Name</option>
27
                    }
28
                </select>
29
            </div>
30
        }
31
        <div class="input_row">
32
            <label class="input_label">@T["Hours"]</label>
33
            <input type="number" @bind-value="Hours" />
34
        </div>
35
        <div class="input_row">
36
            <label class="input_label">@T["Finance"]</label>
37
            <input type="number" @bind-value="FinanceBase" />
38
        </div>
39
    </div>
40
    <div class="review_detail_footer">
41
        <button @onclick="Create">@T["Create"]</button>
42
        <button @onclick="Close">@T["Cancel"]</button>
43
    </div>
44
</aside>
45

  
46
<BlazorStyled.Styled @bind-Classname="@_aside">
47
    right: @(Show ? "0" : "-615")px;
48
</BlazorStyled.Styled>
49
<BlazorStyled.Styled>
50
    .input_row {
51
    margin-bottom: 24px;
52
    }
53
    .input_row select {
54
    width: 100%;
55
    padding: 12px 16px;
56
    border-radius: 4px;
57
    border: 1px solid rgb(200, 200, 200);
58
    font-size: 14px;
59
    }
60
    .input_row input:not([type="checkbox"]) {
61
    width: calc(100% - 34px);
62
    padding: 12px 16px;
63
    border-radius: 4px;
64
    border: 1px solid #C8C8C8;
65
    font-size: 14px;
66
    }
67
    .input_row label.input_label {
68
    font-size: 16px;
69
    font-weight: 700;
70
    color: #111111;
71
    padding-bottom: 4px;
72
    display: block;
73
    }
74
</BlazorStyled.Styled>
75
<BlazorStyled.Styled>
76
    .review_detail {
77
    width: 600px;
78
    height: 100%;
79
    position: fixed;
80
    top: 0;
81
    transition: .25s right;
82
    background-color: white;
83
    -webkit-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
84
    -moz-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
85
    box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
86
    }
87

  
88
    .review_detail_header > div {
89
    height: 100%;
90
    display: flex;
91
    align-items: center;
92
    }
93

  
94
    .review_detail_header {
95
    padding: 12px 24px;
96
    border-bottom: 1px solid #11111122;
97
    height: 26px;
98
    display: flex;
99
    align-items: center;
100
    justify-content: space-between;
101
    }
102

  
103
    .review_detail_body{
104
    padding: 16px 24px;
105
    height: calc(100% - 143px - 50px - 12px);
106
    overflow-y: auto;
107
    overflow-x: hidden;
108
    }
109

  
110
    .review_detail_footer{
111
    height: 36px;
112
    background-color: #F6F8F9;
113
    position: absolute;
114
    bottom: 0;
115
    left: 0;
116
    width: calc(100% - 50px);
117
    display: grid;
118
    padding: 24px;
119
    grid-template-columns: repeat(2, 1fr);
120
    }
121

  
122
    .review_detail_footer button:first-child{
123
    margin-right: 12px;
124
    }
125

  
126
    .review_detail_footer button:last-child{
127
    margin-left: 12px;
128
    }
129
    .review_button {
130
    color: red;
131
    cursor: pointer;
132
    opacity: .75;
133
    }
134

  
135
    .review_button:hover {
136
    opacity: 1;
137
    }
138

  
139
    .review_button.accepted {
140
    color: green;
141
    }
142

  
143
    .review_button:not(:last-child) {
144
    margin-right: 16px;
145
    }
146
    .review_detail_body .review_description {
147
    padding: 8px 12px;
148
    border: 1px solid white;
149
    width: calc(100% - 24px);
150
    outline: none;
151
    margin: 12px 24px 24px 24px;
152
    }
153

  
154
    .review_detail_body .review_description_title {
155
    margin: 0 24px;
156
    }
157

  
158
    .review_description_paragraph{
159
    margin: 12px 24px 24px 24px;
160
    }
161

  
162
    .review_detail_body .review_description:hover{
163
    border: 1px solid #EEEEEE;
164
    }
165

  
166
    .review_detail_body .review_description:focus{
167
    border: 1px solid #A8A8A8;
168
    }
169
</BlazorStyled.Styled>
170

  
171
@code {
172

  
173
    private string _aside;
174

  
175
    private Guid _asideId = default(Guid);
176

  
177
    [Parameter]
178
    public Guid AsideId
179
    {
180
        get { return _asideId; }
181
        set
182
        {
183
            _asideId = value;
184
            InitEdit();
185
        }
186
    }
187

  
188
    private Guid _areaId = default(Guid);
189

  
190
    [Parameter]
191
    public Guid AreaId
192
    {
193
        get { return _areaId; }
194
        set
195
        {
196
            _areaId = value;
197
            InitAside();
198
        }
199
    }
200

  
201
    [Parameter]
202
    public bool Show { get; set; } = false;
203

  
204
    [Parameter]
205
    public GlobalDefinitionArea Area { get; set; } = GlobalDefinitionArea.Default();
206

  
207
    [Parameter]
208
    public EventCallback CloseAside { get; set; }
209

  
210
    [Parameter]
211
    public EventCallback ReloadTable { get; set; }
212

  
213
    private string Name { get; set; } = $"";
214
    private List<UserShortDto> UnassignedUsers { get; set; } = new();
215
    public Guid SelectedUser { get; set; } = default(Guid);
216
    private double Hours { get; set; } = 0;
217
    private double FinanceBase { get; set; } = 0;
218

  
219
    private async Task InitAside()
220
    {
221
        if (AreaId != default(Guid))
222
        {
223
            var response = await _mediator.Send(new GetAreaById.Query(AreaId));
224

  
225
            if (response.IsSuccess)
226
            {
227
                //toastService.ShowSuccess("Oblast úspěšně vytvořena");
228
                Area = response.Result.area;
229
            }
230
            else toastService.ShowError($"Oblast se nepodařilo načíst {response.Errors.FirstOrDefault() ?? ""}");
231

  
232
            var response2 = await _mediator.Send(new GetAllUnassignedInArea.Query(AreaId));
233

  
234
            if (response2.IsSuccess)
235
            {
236
                //toastService.ShowSuccess("Oblast úspěšně vytvořena");
237
                UnassignedUsers = response2.Result.list;
238
            }
239
            else toastService.ShowError($"Seznam nepřiřazených uživatelů se nepodařilo načíst {response2.Errors.FirstOrDefault() ?? ""}");
240
        }
241
    }
242

  
243
    private async Task InitEdit()
244
    {
245
        if (AsideId != default(Guid))
246
        {
247
            var response = await _mediator.Send(new GetGoalDefinitionById.Query(AsideId));
248

  
249
            if (response.IsSuccess)
250
            {
251
                //toastService.ShowSuccess("Oblast úspěšně vytvořena");
252
                Name = response.Result.item.Name;
253
                Hours = response.Result.item.VariProjectHours ?? 0;
254
                FinanceBase = response.Result.item.FinanceBase;
255
            }
256
            else toastService.ShowError($"Definici se nepodařilo načíst {response.Errors.FirstOrDefault() ?? ""}");
257
        }
258
    }
259

  
260
    private async Task Create()
261
    {
262
        if (AsideId != default(Guid))
263
        {
264
            await Edit();
265
        }
266
        else
267
        {
268
            var response = await _mediator.Send(new CreateGoalDefinition.Command(SelectedUser, AreaId, Name, Hours, FinanceBase));
269

  
270
            if (response.IsSuccess)
271
            {
272
                toastService.ShowSuccess("Definice úspěšně založena");
273
                ReloadTable.InvokeAsync();
274
                await Close();
275
            }
276
            else toastService.ShowError($"Definici se nepodařilo vytvořit: {response.Errors.FirstOrDefault() ?? ""}");
277
            //toastService.ShowError($"Selected: {SelectedUser}");
278
        }
279
    }
280

  
281
    private async Task Edit()
282
    {
283
        var response = await _mediator.Send(new EditGoalDefinition.Command(AsideId, Name, Hours, FinanceBase));
284

  
285
        if (response.IsSuccess)
286
        {
287
            toastService.ShowSuccess("Definice úspěšně editována");
288
            ReloadTable.InvokeAsync();
289
            await Close();
290
        }
291
        else toastService.ShowError($"Definici se nepodařilo editovat: {response.Errors.FirstOrDefault() ?? ""}");
292
        //toastService.ShowError($"Selected: {SelectedUser}");
293
    }
294

  
295
    private async Task Close()
296
    {
297
        //ResetValues();
298
        await CloseAside.InvokeAsync();
299
    }
300

  
301
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalRanges.razor
31 31
                <td>@(range.VariCompanySuccess ?? 0)</td>
32 32
                <td>
33 33
                    <div class="flex">
34
                        <div @onclick="() => DownloadAreaFile(range.Id)">
34
                        <div class="button-ui" @onclick="() => DownloadAreaFile(range.Id)">
35 35
                            <i class="fal fa-download"></i>
36 36
                            @T["Export"]
37 37
                        </div>
38 38

  
39
                        <div @onclick='() => _nav.NavigateTo($"/goals/overview/{range.Id}")'>
39
                        <div class="button-ui" @onclick='() => _nav.NavigateTo($"/goals/overview/{range.Id}")'>
40 40
                            <i class="fal fa-eye"></i>
41 41
                            @T["Open"]
42 42
                        </div>
43
                        <div @onclick="() => OpenAside(range.Id)">
43
                        <div class="button-ui" @onclick="() => OpenAside(range.Id)">
44 44
                            <i class="fal fa-edit"></i>
45 45
                            @T["Edit"]
46 46
                        </div>
47
                        <div @onclick="() => RemoveArea(range.Id)">
47
                        <div class="button-ui" @onclick="() => RemoveArea(range.Id)">
48 48
                            <i class="fal fa-trash"></i>
49 49
                            @T["Remove"]
50 50
                        </div>
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Pages/GoalsManagement.razor
41 41
                <td>
42 42
                    <div class="flex">
43 43
                        <AuthorizeView Roles="TL">
44
                            <div @onclick='() => _nav.NavigateTo($"/goals/detail/{range.Id}")'>
44
                            <div  class="button-ui" @onclick='() => _nav.NavigateTo($"/goals/detail/{range.Id}")'>
45 45
                                <i class="fal fa-eye"></i>
46 46
                                @T["Open"]
47 47
                            </div>
48
                            <div @onclick="() => OpenAside(range.Id)">
48
                            <div class="button-ui" @onclick="() => OpenAside(range.Id)">
49 49
                                <i class="fal fa-edit"></i>
50 50
                                @T["Edit"]
51 51
                            </div>
52
                            <div @onclick="() => RemoveDefinition(range.Id)">
52
                            <div class="button-ui" @onclick="() => RemoveDefinition(range.Id)">
53 53
                                <i class="fal fa-trash"></i>
54 54
                                @T["Remove"]
55 55
                            </div>
......
74 74
else
75 75
{
76 76
    <div>Loading...</div>}
77
<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateGoalDefinition Show="ShowAside" AsideId="Id" CloseAside="CloseAside" />
77
<Leuze.Modules.Goal.Application.UI.Pages.Components.CreateGoalDefinitionAside Show="ShowAside" AsideId="DetailId" AreaId="Id" ReloadTable="GetMyDefinitions" CloseAside="CloseAside" />
78 78

  
79 79
<BlazorStyled.Styled>
80 80
    .button-ui {
......
203 203
@code { [Parameter]
204 204
    public Guid Id { get; set; } = default(Guid);
205 205

  
206
    public Guid DetailId { get; set; } = default(Guid);
207

  
206 208
    private List<GoalDefinition> Definitions { get; set; } = new();
207 209

  
208 210
    private int PageNumber { get; set; } = 1;
......
213 215

  
214 216
    private bool ShowAside { get; set; } = false;
215 217

  
216
    private void OpenAside(Guid id) => (ShowAside) = (true);
218
    private void OpenAside(Guid id) => (ShowAside, DetailId) = (true, id);
217 219

  
218
    private void CloseAside() => (ShowAside) = (false);
220
    private void CloseAside() => (ShowAside, DetailId) = (false, default(Guid));
219 221

  
220 222
    private async Task GetMyDefinitions()
221 223
    {
......
229 231

  
230 232
    private async Task InitAllDefinitions()
231 233
    {
232
        toastService.ShowError($"NOT IMPLEMENTED (yet) !");
234
        var response = await _mediator.Send(new CreateAllForArea.Command(Id));
235

  
236
        if (response.IsSuccess)
237
        {
238
            toastService.ShowSuccess("Definice úspěšně vytvořeny!");
239
            await GetMyDefinitions();
240
        }
241
        else toastService.ShowError($"Definice se nepodařilo vytvořit: {response.Errors.FirstOrDefault() ?? ""}");
233 242
    }
234 243

  
235 244
    private async Task RemoveDefinition(Guid id)
src/Modules/Goal/Application/Leuze.Modules.Goal.Application.UI/Resources/Pages/Components/CreateGoalDefinition.cs-CZ.resx
135 135
  <data name="SelectUser" xml:space="preserve">
136 136
    <value>Zvolte uživatele</value>
137 137
  </data>
138
  <data name="Title" xml:space="preserve">
138
  <data name="TitleCreate" xml:space="preserve">
139 139
    <value>Vytvořit definici cílů</value>
140 140
  </data>
141
  <data name="TitleEdit" xml:space="preserve">
142
    <value>Editovat definici cílů</value>
143
  </data>
141 144
  <data name="User" xml:space="preserve">
142 145
    <value>Přiřazený uživatel</value>
143 146
  </data>
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Commands/CreateAllForArea.cs
1
using Leuze.Core.Application.CQRS;
2
using Leuze.Core.Domain.Domains.Users.DTOs;
3
using Leuze.Core.Domain.Repositories;
4
using Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries;
5
using Leuze.Modules.Goal.Domain.Domains;
6
using Leuze.Modules.Goal.Domain.Repositories;
7
using MediatR;
8
using Microsoft.AspNetCore.Components.Authorization;
9
using System;
10
using System.Collections.Generic;
11
using System.Linq;
12
using System.Security.Claims;
13
using System.Text;
14
using System.Threading;
15
using System.Threading.Tasks;
16

  
17
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Commands
18
{
19
    public static class CreateAllForArea
20
    {
21
        public record Command(Guid areaId) : IBaseRequest<Response>;
22

  
23
        public record Response();
24

  
25

  
26
        public class Handler : IBaseRequestHandler<Command, Response>
27
        {
28
            private readonly IMediator _mediator;
29
            private readonly IGlobalDefinitionAreaRepository _globalDefinitionAreaRepo;
30
            private readonly IGoalDefinitionRepository _goalDefinitionRepo;
31
            private readonly AuthenticationStateProvider _authenticationStateProvider;
32
            private readonly IDomainUserRepository _domainUserRepo;
33

  
34
            public Handler(IMediator mediator, IGlobalDefinitionAreaRepository globalDefinitionAreaRepo, IGoalDefinitionRepository goalDefinitionRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
35
            {
36
                _mediator = mediator;
37
                _globalDefinitionAreaRepo = globalDefinitionAreaRepo;
38
                _goalDefinitionRepo = goalDefinitionRepo;
39
                _authenticationStateProvider = authStateProvider;
40
                _domainUserRepo = domainUserRepo;
41
            }
42

  
43
            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
44
            {
45
                //TODO: user muze byt null, ale to my nechceme!!!
46
                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
47
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
48
                var creator = await _domainUserRepo.GetByIdAsync(id);
49
                var area = await _globalDefinitionAreaRepo.GetByIdAsync(request.areaId);
50
                List<UserShortDto> usersList = new();
51

  
52
                if (creator == null)
53
                {
54
                    return RequestResponse<Response>.CreateErrorResponse($"Creator user with id: {id} not found!");
55
                }
56
                if (area == null)
57
                {
58
                    return RequestResponse<Response>.CreateErrorResponse($"Area with id: {request.areaId} not found!");
59
                }
60

  
61
                var response = await _mediator.Send(new GetAllUnassignedInArea.Query(request.areaId));
62
                if (response.IsSuccess)
63
                {
64
                    usersList = response.Result.list;
65
                }
66
                else 
67
                {
68
                    return RequestResponse<Response>.CreateErrorResponse($"Unable to obtain users list!");
69
                }
70

  
71
                foreach(var user in usersList)
72
                {
73
                    var owner = await _domainUserRepo.GetByIdAsync(user.Id);
74
                    GoalDefinition item = new(owner, creator, area, $"{owner.Name.FullName} ({area.GetShortName()})");
75

  
76
                    await _goalDefinitionRepo.AddAsync(item);
77
                }
78

  
79
                return RequestResponse<Response>.CreateSuccessResponse(new());
80
            }
81
        }
82
    }
83
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Commands/CreateGoalDefinition.cs
15 15
{
16 16
    public static class CreateGoalDefinition
17 17
    {
18
        public record Command(Guid GoalDefinitionId, string Name, string Description) : IBaseRequest<Response>;
18
        public record Command(Guid ownerId, Guid areaId, string Name, double hourVari, double FinanceBase) : IBaseRequest<Response>;
19 19

  
20
        public record Response(GoalItem item);
20
        public record Response(GoalDefinition item);
21 21

  
22 22

  
23 23
        public class Handler : IBaseRequestHandler<Command, Response>
24 24
        {
25
            private readonly IGoalItemRepository _goalItemRepo;
25
            private readonly IGlobalDefinitionAreaRepository _globalDefinitionAreaRepo;
26 26
            private readonly IGoalDefinitionRepository _goalDefinitionRepo;
27 27
            private readonly AuthenticationStateProvider _authenticationStateProvider;
28 28
            private readonly IDomainUserRepository _domainUserRepo;
29 29

  
30
            public Handler(IGoalItemRepository goalItemRepo, IGoalDefinitionRepository goalDefinitionRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
30
            public Handler(IGlobalDefinitionAreaRepository globalDefinitionAreaRepo, IGoalDefinitionRepository goalDefinitionRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
31 31
            {
32
                _goalItemRepo = goalItemRepo;
32
                _globalDefinitionAreaRepo = globalDefinitionAreaRepo;
33 33
                _goalDefinitionRepo = goalDefinitionRepo;
34 34
                _authenticationStateProvider = authStateProvider;
35 35
                _domainUserRepo = domainUserRepo;
......
37 37

  
38 38
            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
39 39
            {
40
                if (request.Name == null || request.Name == "")
41
                {
42
                    return RequestResponse<Response>.CreateErrorResponse($"Definition name cannot be empty!");
43
                }
44

  
40 45
                //TODO: user muze byt null, ale to my nechceme!!!
41 46
                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
42 47
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
43
                var user = await _domainUserRepo.GetByIdAsync(id);
44
                var goalDef = await _goalDefinitionRepo.GetByIdAsync(request.GoalDefinitionId);
48
                var creator = await _domainUserRepo.GetByIdAsync(id);
49
                var owner = await _domainUserRepo.GetByIdAsync(request.ownerId);
50
                var area = await _globalDefinitionAreaRepo.GetByIdAsync(request.areaId);
51

  
52
                if(creator == null)
53
                {
54
                    return RequestResponse<Response>.CreateErrorResponse($"Creator user with id: {id} not found!");
55
                }
56

  
57
                if (owner == null)
58
                {
59
                    return RequestResponse<Response>.CreateErrorResponse($"Owner user with id: {request.ownerId} not found!");
60
                }
45 61

  
46
                if(goalDef == null)
62
                if (area == null)
47 63
                {
48
                    return RequestResponse<Response>.CreateErrorResponse($"Goal definition with id: {request.GoalDefinitionId} not found!");
64
                    return RequestResponse<Response>.CreateErrorResponse($"Area with id: {request.areaId} not found!");
49 65
                }
50 66

  
51
                GoalItem item = new(goalDef, user, request.Name, request.Description);
67
                GoalDefinition item = new(owner, creator, area, request.Name, request.FinanceBase);
68
                item.SetVariProjectHours(request.hourVari);
52 69

  
53
                await _goalItemRepo.AddAsync(item);
70
                await _goalDefinitionRepo.AddAsync(item);
54 71

  
55 72
                return RequestResponse<Response>.CreateSuccessResponse(new(item));
56 73
            }
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Commands/EditGoalDefinition.cs
1
using Leuze.Core.Application.CQRS;
2
using Leuze.Core.Domain.Domains.Users.DTOs;
3
using Leuze.Core.Domain.Repositories;
4
using Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Queries;
5
using Leuze.Modules.Goal.Domain.Domains;
6
using Leuze.Modules.Goal.Domain.Repositories;
7
using MediatR;
8
using Microsoft.AspNetCore.Components.Authorization;
9
using System;
10
using System.Collections.Generic;
11
using System.Linq;
12
using System.Security.Claims;
13
using System.Text;
14
using System.Threading;
15
using System.Threading.Tasks;
16

  
17
namespace Leuze.Modules.Goal.Application.CQRS.GoalDefinitions.Commands
18
{
19
    public static class EditGoalDefinition
20
    {
21
        public record Command(Guid definitionId, string Name, double hourVari, double FinanceBase) : IBaseRequest<Response>;
22

  
23
        public record Response(GoalDefinition item);
24

  
25

  
26
        public class Handler : IBaseRequestHandler<Command, Response>
27
        {
28
            private readonly IGlobalDefinitionAreaRepository _globalDefinitionAreaRepo;
29
            private readonly IGoalDefinitionRepository _goalDefinitionRepo;
30
            private readonly AuthenticationStateProvider _authenticationStateProvider;
31
            private readonly IDomainUserRepository _domainUserRepo;
32

  
33
            public Handler(IGlobalDefinitionAreaRepository globalDefinitionAreaRepo, IGoalDefinitionRepository goalDefinitionRepo, AuthenticationStateProvider authStateProvider, IDomainUserRepository domainUserRepo)
34
            {
35
                _globalDefinitionAreaRepo = globalDefinitionAreaRepo;
36
                _goalDefinitionRepo = goalDefinitionRepo;
37
                _authenticationStateProvider = authStateProvider;
38
                _domainUserRepo = domainUserRepo;
39
            }
40

  
41
            public async Task<RequestResponse<Response>> Handle(Command request, CancellationToken cancellationToken)
42
            {
43
                if (request.Name == null || request.Name == "")
44
                {
45
                    return RequestResponse<Response>.CreateErrorResponse($"Definition name cannot be empty!");
46
                }
47

  
48
                //TODO: user muze byt null, ale to my nechceme!!!
49
                var state = await _authenticationStateProvider.GetAuthenticationStateAsync();
50
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
51
                var creator = await _domainUserRepo.GetByIdAsync(id);
52
                var definition = await _goalDefinitionRepo.GetByIdAsync(request.definitionId);
53

  
54
                if (creator == null)
55
                {
56
                    return RequestResponse<Response>.CreateErrorResponse($"Creator user with id: {id} not found!");
57
                }
58

  
59
                if (definition == null)
60
                {
61
                    return RequestResponse<Response>.CreateErrorResponse($"Definition with id: {request.definitionId} not found!");
62
                }
63

  
64
                
65
                definition.SetName(request.Name);
66
                definition.SetVariProjectHours(request.hourVari);
67
                definition.SetFinanceBase(request.FinanceBase);
68

  
69
                await _goalDefinitionRepo.UpdateRepo();
70

  
71
                return RequestResponse<Response>.CreateSuccessResponse(new(definition));
72
            }
73
        }
74
    }
75
}
src/Modules/Goal/Application/Leuze.Modules.Goal.Application/CQRS/GoalDefinitions/Queries/GetAllUnassignedInArea.cs
40 40
                var id = Guid.Parse(state.User!.FindFirst(ClaimTypes.NameIdentifier)!.Value);
41 41
                var user = await _domainUserRepo.GetByIdAsync(id);
42 42

  
43
                //TODO: Change with list of TL and MA only
43 44
                //var goalDefs = await _goalDefinitionRepo.GetAllForAreaAsync(request.areaId);
44 45
                var allUsers = await _domainUserRepo.GetListAsync(id);
46
                //allUsers = allUsers.Where(o => o.) //Remove admins
45 47
                var areaDefs = await _goalDefinitionRepo.GetAllForAreaAsync(request.areaId);
46 48
                var assignedList = areaDefs.Select(o => new UserShortDto(o.Owner.UserId, o.Owner.Name.FullName)).ToList();
47 49

  
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Domains/GlobalDefinitionArea.cs
55 55
        {
56 56
            this.VariCompanySuccess = vari;
57 57
        }
58

  
59
        public string GetShortName()
60
        {
61
            return $"{From.ToShortDateString()}-{To.ToShortDateString()}";
62
        }
58 63
    }
59 64
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/ICommentRepository.cs
23 23
        Task<bool> EditAsync(Guid id, string text);
24 24
        Task<bool> SetPrivate(Guid id);
25 25
        Task<bool> SetPublic(Guid id);
26

  
27
        Task<bool> UpdateRepo();
26 28
    }
27 29
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGlobalDefinitionAreaRepository.cs
26 26

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

  
29

  
29
        Task<bool> UpdateRepo();
30 30
    }
31 31
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalDefinitionRepository.cs
33 33
        Task<bool> LockByOwner(Guid id);
34 34
        Task<bool> LockBySupervisor(Guid id);
35 35
        Task<bool> LocksReset(Guid id);
36

  
37
        Task<bool> UpdateRepo();
36 38
    }
37 39
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalItemRepository.cs
34 34
        Task<bool> LockBySupervisor(Guid id);
35 35
        Task<bool> LocksReset(Guid id);
36 36

  
37
        Task<bool> UpdateRepo();
38

  
37 39
    }
38 40
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IGoalUpdateRepository.cs
19 19
        Task<List<GoalUpdate>> GetAllForGoalAsync(Guid goalId);
20 20

  
21 21
        Task<List<GoalUpdate>> GetAllAsync();
22

  
23
        Task<bool> UpdateRepo();
22 24
    }
23 25
}
src/Modules/Goal/Domain/Leuze.Modules.Goal.Domain/Repositories/IReviewRepository.cs
19 19
        Task<List<Review>> GetAllForGoalAsync(Guid goalId);
20 20

  
21 21
        Task<List<Review>> GetAllAsync();
22

  
23
        Task<bool> UpdateRepo();
22 24
    }
23 25
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/DependencyInjection.cs
54 54
            {
55 55
                var context = serviceScope.ServiceProvider.GetRequiredService<LeuzeDbContext>();
56 56
                var appSettings = serviceScope.ServiceProvider.GetRequiredService<IOptions<AppSettings>>().Value;
57

  
57
                
58 58
                //TODO: This is debug delet this
59 59
                var user = context.Set<DomainUser>().Where(item => item.EmailAddress.Email == "ma@test.cz").FirstOrDefault();
60 60
                GlobalDefinitionArea area = new GlobalDefinitionArea(user, DateTime.Now, DateTime.Now.AddDays(10));
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/CommentRepository.cs
78 78
            await storageContext.SaveChangesAsync();
79 79
            return true;
80 80
        }
81

  
82
        public async Task<bool> UpdateRepo()
83
        {
84
            await storageContext.SaveChangesAsync();
85
            return true;
86
        }
81 87
    }
82 88
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GlobalDefinitionAreaRepository.cs
78 78
        {
79 79
            return await dbSet.Where(item => ((from >= item.From && from <= item.To) || (to <= item.To && to >= item.From))).ToListAsync();
80 80
        }
81

  
82
        public async Task<bool> UpdateRepo()
83
        {
84
            await storageContext.SaveChangesAsync();
85
            return true;
86
        }
81 87
    }
82 88
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalDefinitionRepository.cs
114 114
            await storageContext.SaveChangesAsync();
115 115
            return true;
116 116
        }
117

  
118
        public async Task<bool> UpdateRepo()
119
        {
120
            await storageContext.SaveChangesAsync();
121
            return true;
122
        }
117 123
    }
118 124
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalItemRepository.cs
118 118
            await storageContext.SaveChangesAsync();
119 119
            return true;
120 120
        }
121

  
122
        public async Task<bool> UpdateRepo()
123
        {
124
            await storageContext.SaveChangesAsync();
125
            return true;
126
        }
121 127
    }
122 128
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/GoalUpdateRepository.cs
50 50
        {
51 51
            return dbSet.ToList(); //TODO: Await??
52 52
        }
53

  
54
        public async Task<bool> UpdateRepo()
55
        {
56
            await storageContext.SaveChangesAsync();
57
            return true;
58
        }
53 59
    }
54 60
}
src/Modules/Goal/Infrastructure/Leuze.Modules.Goal.Infrastructure.Persistence/Repositories/ReviewRepository.cs
50 50
        {
51 51
            return dbSet.ToList(); //TODO: Await??
52 52
        }
53

  
54
        public async Task<bool> UpdateRepo()
55
        {
56
            await storageContext.SaveChangesAsync();
57
            return true;
58
        }
53 59
    }
54 60
}

Také k dispozici: Unified diff