Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2b275a7
DataBaseLayer
PirogStanislav Aug 3, 2021
fb219a3
AddMultiPublish
PirogStanislav Aug 9, 2021
21338e3
RepairedDB
PirogStanislav Aug 9, 2021
71bfa43
MigrationFix
PirogStanislav Aug 10, 2021
3994b11
AddController
PirogStanislav Aug 13, 2021
7c38b43
AddMultiEventForm
PirogStanislav Aug 16, 2021
526cb53
Merge
PirogStanislav Aug 16, 2021
8cab6c3
AddFrontEndMultiiEvent
PirogStanislav Aug 23, 2021
3d107fb
Commit
PirogStanislav Aug 31, 2021
75e1600
MagicWork
PirogStanislav Sep 7, 2021
6aaef08
AddStyles
PirogStanislav Sep 7, 2021
952c9bf
WorkVersion
PirogStanislav Sep 7, 2021
559b74b
PreFinish
PirogStanislav Sep 7, 2021
e18e72f
AddMaps
PirogStanislav Sep 7, 2021
25d79aa
MEdiatorCommit
PirogStanislav Sep 8, 2021
213ba33
AproximalityWork
PirogStanislav Sep 8, 2021
7a31ba0
ChangeMultiEdit
PirogStanislav Sep 14, 2021
ab42434
It is work!
PirogStanislav Sep 16, 2021
742daf7
Refacoring
PirogStanislav Sep 28, 2021
36eb750
DeleteMultiEdit
PirogStanislav Sep 29, 2021
9b11bf8
AddTest
PirogStanislav Oct 3, 2021
880d186
Merge branch 'development' into AddMultiEventStatus
PirogStanislav Oct 3, 2021
d9451cf
FixCodeSmells
PirogStanislav Oct 3, 2021
4bfa418
KillCodeSmels
PirogStanislav Oct 4, 2021
27d5c72
ChangeNaming
PirogStanislav Oct 4, 2021
11b45af
FrontendFix
PirogStanislav Oct 4, 2021
46e100c
DataPickerAndCheckboxes
PirogStanislav Oct 6, 2021
d1352d4
DeleteTrash
PirogStanislav Oct 6, 2021
4310966
NormalizedAgainstValidate
PirogStanislav Oct 7, 2021
98d9a19
DataPickerFix
PirogStanislav Oct 7, 2021
259922b
NewDTOValidation
PirogStanislav Oct 11, 2021
012877e
ValidationChanges
PirogStanislav Oct 13, 2021
3a66d03
ModifateValidation
PirogStanislav Oct 18, 2021
f5df0c2
Fix problem with Nullable value
PirogStanislav Oct 18, 2021
42bd961
Return contracts
PirogStanislav Oct 21, 2021
88146c2
DeleteMigrations
PirogStanislav Oct 22, 2021
0438fd0
Merge branch 'development' into AddMultiEventStatus
PirogStanislav Oct 22, 2021
7795e79
Add migrations
PirogStanislav Oct 22, 2021
005fe6e
koma
PirogStanislav Oct 22, 2021
03ea62b
ChangeGetById
PirogStanislav Oct 30, 2021
1d75e9c
ChangeProfille
PirogStanislav Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions EventsExpress.Core/DTOs/ChildEventDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using EventsExpress.Db.Entities;
using EventsExpress.Db.Enums;
using Microsoft.AspNetCore.Http;
using NetTopologySuite.Geometries;

namespace EventsExpress.Core.DTOs
{
public class ChildEventDto
{
public Guid Id { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public DateTime? DateFrom { get; set; }

public DateTime? DateTo { get; set; }

public Point Point { get; set; }

public LocationType Type { get; set; }

public Uri OnlineMeeting { get; set; }

public EventStatus EventStatus { get; set; }

public bool? IsMultiEvent { get; set; }
}
}
4 changes: 4 additions & 0 deletions EventsExpress.Core/DTOs/EventDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ public class EventDto
public IEnumerable<Guid> OwnerIds { get; set; }

public IEnumerable<User> Owners { get; set; }

public bool? IsMultiEvent { get; set; }

public IEnumerable<ChildEventDto> Events { get; set; }
}
}
2 changes: 1 addition & 1 deletion EventsExpress.Core/IServices/IEventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IEventService

Task<Guid> EditNextEvent(EventDto eventDTO);

Task<Guid> Edit(EventDto e);
Task<Guid> Edit(EventDto eventInstance);

Task<Guid> Publish(Guid eventId);

Expand Down
90 changes: 66 additions & 24 deletions EventsExpress.Core/Services/EventService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using EventsExpress.Core.DTOs;
Expand Down Expand Up @@ -221,15 +222,14 @@ public async Task<Guid> CreateNextEvent(Guid eventId)
return createResult;
}

public async Task<Guid> Edit(EventDto e)
private async Task<Guid> InternalEdit(EventDto e)
{
var ev = Context.Events
.Include(e => e.EventLocation)
.Include(e => e.Categories)
.ThenInclude(c => c.Category)
.Include(e => e.EventSchedule)
.FirstOrDefault(x => x.Id == e.Id);

if (e.OnlineMeeting != null || e.Point != null)
{
var locationDTO = Mapper.Map<EventDto, LocationDto>(e);
Expand Down Expand Up @@ -267,6 +267,7 @@ public async Task<Guid> Edit(EventDto e)
ev.DateFrom = e.DateFrom;
ev.DateTo = e.DateTo;
ev.IsPublic = e.IsPublic;
ev.IsMultiEvent = e.IsMultiEvent;

var eventCategories = e.Categories?.Select(x => new EventCategory { Event = ev, CategoryId = x.Id })
.ToList();
Expand All @@ -278,7 +279,42 @@ public async Task<Guid> Edit(EventDto e)
return ev.Id;
}

public async Task<Guid> Publish(Guid eventId)
public async Task<Guid> Edit(EventDto eventInstance)
{
if (eventInstance.Events.CollectionIsNullOrEmpty())
{
await InternalEdit(eventInstance);
}
else
{
eventInstance.IsMultiEvent = true;
await InternalEdit(eventInstance);
ChildEventDto[] childEventDtos = eventInstance.Events.ToArray();
EventDto[] childs = new EventDto[childEventDtos.Length];
for (int i = 0; i < childEventDtos.Length; i++)
{
childs[i] = Mapper.Map<ChildEventDto, EventDto>(childEventDtos[i]);
childs[i].Id = CreateDraft();
childs[i].IsMultiEvent = true;
childs[i].Inventories = eventInstance.Inventories;
childs[i].IsPublic = eventInstance.IsPublic;
childs[i].IsReccurent = eventInstance.IsReccurent;
childs[i].MaxParticipants = eventInstance.MaxParticipants;
childs[i].Categories = eventInstance.Categories;
Context.MultiEventStatus.Add(
new MultiEventStatus
{
ParentId = eventInstance.Id,
ChildId = childs[i].Id,
});
await InternalEdit(childs[i]);
}
}

return eventInstance.Id;
}

private void InternalPublish(Guid eventId)
{
var ev = Context.Events
.Include(e => e.EventLocation)
Expand All @@ -292,33 +328,36 @@ public async Task<Guid> Publish(Guid eventId)
throw new EventsExpressException("Not found");
}

Dictionary<string, string> exept = new Dictionary<string, string>();
var result = _validator.Validate(ev);

if (result.IsValid)
{
ev.StatusHistory.Add(
ev.StatusHistory.Add(
new EventStatusHistory
{
EventStatus = EventStatus.Active,
CreatedOn = DateTime.UtcNow,
UserId = CurrentUserId(),
});
await Context.SaveChangesAsync();
EventDto dtos = Mapper.Map<Event, EventDto>(ev);
await _mediator.Publish(new EventCreatedMessage(dtos));
return ev.Id;
}
else
}

public async Task<Guid> Publish(Guid eventId)
{
var ev = Context.Events.FirstOrDefault(x => x.Id == eventId);
InternalPublish(eventId);
if (ev.IsMultiEvent == true)
{
var p = result.Errors.Select(e => new KeyValuePair<string, string>(e.PropertyName, e.ErrorMessage));
foreach (var x in p)
var childsId = Context.MultiEventStatus
.Where(x => x.ParentId == eventId)
.Select(x => x.ChildId)
.ToArray();

foreach (var item in childsId)
{
exept.Add(x.Key, x.Value);
InternalPublish(item);
}

throw new EventsExpressException("validation failed", exept);
}

await Context.SaveChangesAsync();
EventDto dtos = Mapper.Map<Event, EventDto>(ev);
await _mediator.Publish(new EventCreatedMessage(dtos));
return eventId;
}

public async Task<Guid> EditNextEvent(EventDto eventDTO)
Expand All @@ -340,8 +379,7 @@ public async Task<Guid> EditNextEvent(EventDto eventDTO)

public EventDto EventById(Guid eventId)
{
var res = Mapper.Map<EventDto>(
Context.Events
var request = Context.Events
.Include(e => e.EventLocation)
.Include(e => e.Owners)
.ThenInclude(o => o.User)
Expand All @@ -355,9 +393,13 @@ public EventDto EventById(Guid eventId)
.ThenInclude(u => u.Relationships)
.Include(e => e.StatusHistory)
.Include(e => e.EventSchedule)
.FirstOrDefault(x => x.Id == eventId));
.Include(e => e.ChildEvents)
.ThenInclude(e => e.ChildEvent)
.ThenInclude(e => e.EventLocation)
.FirstOrDefault(x => x.Id == eventId);

return res;
var res = Mapper.Map<EventDto>(request);
return res;
}

public IEnumerable<EventDto> GetAll(EventFilterViewModel model, out int count)
Expand Down
21 changes: 21 additions & 0 deletions EventsExpress.Db/Configurations/MultiEventStatusConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace EventsExpress.Db.Configurations
{
using EventsExpress.Db.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public class MultiEventStatusConfiguration : IEntityTypeConfiguration<MultiEventStatus>
{
public void Configure(EntityTypeBuilder<MultiEventStatus> builder)
{
builder.HasOne(e => e.ParentEvent)
.WithMany(ec => ec.ChildEvents)
.HasForeignKey(e => e.ParentId)
.OnDelete(DeleteBehavior.ClientCascade);
builder.HasOne(e => e.ChildEvent)
.WithMany(ec => ec.ParentEvents)
.HasForeignKey(e => e.ChildId)
.OnDelete(DeleteBehavior.ClientCascade);
}
}
}
2 changes: 2 additions & 0 deletions EventsExpress.Db/EF/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public AppDbContext(DbContextOptions<AppDbContext> options, ISecurityContext sec

public DbSet<Event> Events { get; set; }

public DbSet<MultiEventStatus> MultiEventStatus { get; set; }

public DbSet<EventOwner> EventOwners { get; set; }

public DbSet<EventLocation> EventLocations { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions EventsExpress.Db/Entities/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Event : BaseEntity
[Track]
public Guid? EventLocationId { get; set; }

[Track]
public bool? IsMultiEvent { get; set; }

public virtual EventSchedule EventSchedule { get; set; }

public virtual EventLocation EventLocation { get; set; }
Expand All @@ -44,5 +47,9 @@ public class Event : BaseEntity
public virtual ICollection<Inventory> Inventories { get; set; }

public virtual ICollection<EventStatusHistory> StatusHistory { get; set; }

public virtual ICollection<MultiEventStatus> ChildEvents { get; set; }

public virtual ICollection<MultiEventStatus> ParentEvents { get; set; }
}
}
24 changes: 24 additions & 0 deletions EventsExpress.Db/Entities/MultiEventStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using EventsExpress.Db.EF;
using EventsExpress.Db.Enums;

namespace EventsExpress.Db.Entities
{
[Track]
public class MultiEventStatus
{
[Track]
public Guid Id { get; set; }

[Track]
public Guid ParentId { get; set; }

public virtual Event ChildEvent { get; set; }

public virtual Event ParentEvent { get; set; }

[Track]
public Guid ChildId { get; set; }
}
}
9 changes: 8 additions & 1 deletion EventsExpress.Db/EventsExpress.Db.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Migrations\20210809082522_MultiEventConfigurations.cs" />
<Compile Remove="Migrations\20210809082522_MultiEventConfigurations.Designer.cs" />
<Compile Remove="Migrations\20210809083119_AddMultiEvent.cs" />
<Compile Remove="Migrations\20210809083119_AddMultiEvent.Designer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
Expand Down
Loading