SKE-53 method createCompetition
This commit is contained in:
parent
8a8226dad1
commit
b75d8893c6
@ -0,0 +1,47 @@
|
|||||||
|
using Abp.Authorization;
|
||||||
|
using Abp.Domain.Repositories;
|
||||||
|
using Abp.Domain.Uow;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SystemKonkursow.Competition.CompetitionCategory.Dto;
|
||||||
|
|
||||||
|
namespace SystemKonkursow.Competition.CompetitionCategory
|
||||||
|
{
|
||||||
|
public class CompetitionAppService : SystemKonkursowAppServiceBase
|
||||||
|
{
|
||||||
|
private readonly IRepository<Domain.CompetitionCategory, int> _competitionCategoryRepository;
|
||||||
|
private readonly IRepository<Domain.Competition, long> _competitionRepository;
|
||||||
|
|
||||||
|
public CompetitionAppService(IRepository<Domain.CompetitionCategory, int> competitionCategoryRepository,
|
||||||
|
IRepository<Domain.Competition, long> competitionRepository)
|
||||||
|
{
|
||||||
|
_competitionCategoryRepository = competitionCategoryRepository;
|
||||||
|
_competitionRepository = competitionRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[AbpAuthorize]
|
||||||
|
[UnitOfWork]
|
||||||
|
public async Task<long> CreateCompetition(CreateCompetitionDto createCompetitionDto)
|
||||||
|
{
|
||||||
|
var user = await GetCurrentUserAsync();
|
||||||
|
|
||||||
|
var mappedCompetition = ObjectMapper.Map<Domain.Competition>(createCompetitionDto);
|
||||||
|
|
||||||
|
mappedCompetition.CreatorUserId = user.Id;
|
||||||
|
|
||||||
|
var newCompetitionId = await _competitionRepository.InsertAndGetIdAsync(mappedCompetition);
|
||||||
|
|
||||||
|
foreach (int categoryId in createCompetitionDto.CategoriesId)
|
||||||
|
{
|
||||||
|
var competitionCategory = new Domain.CompetitionCategory
|
||||||
|
{
|
||||||
|
CategoryId = categoryId,
|
||||||
|
CompetitionId = newCompetitionId
|
||||||
|
};
|
||||||
|
|
||||||
|
await _competitionCategoryRepository.InsertAsync(competitionCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newCompetitionId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto
|
|||||||
.ForMember(dest => dest.MaxClass, opt => opt.MapFrom(src => src.Competition.MaxClass))
|
.ForMember(dest => dest.MaxClass, opt => opt.MapFrom(src => src.Competition.MaxClass))
|
||||||
.ForMember(dest => dest.CreationTime, opt => opt.MapFrom(src => src.Competition.CreationTime))
|
.ForMember(dest => dest.CreationTime, opt => opt.MapFrom(src => src.Competition.CreationTime))
|
||||||
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName));
|
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName));
|
||||||
|
|
||||||
|
CreateMap<CreateCompetitionDto, Domain.Competition>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SystemKonkursow.Competition.CompetitionCategory.Dto
|
||||||
|
{
|
||||||
|
public class CreateCompetitionDto
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
|
public DateTime EndDate { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string Prize { get; set; }
|
||||||
|
|
||||||
|
public int MinClass { get; set; }
|
||||||
|
|
||||||
|
public int MaxClass { get; set; }
|
||||||
|
|
||||||
|
public List<int> CategoriesId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user