Skip to content

Commit

Permalink
Merge pull request #40 from bentran1vn/Fix/DuplicateCertificate
Browse files Browse the repository at this point in the history
Fix/duplicate certificate
  • Loading branch information
bentran1vn authored Nov 11, 2024
2 parents 358d6a9 + ee603a9 commit 212126d
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,43 @@ public async Task<Result> Handle(Command.CreateMentorSkillsCommand request, Canc

if (mentor is null) return Result.Failure(new Error("404", $"Not Mentor with Id: {request.MentorId}"));

var mentorSkills = await _mentorSkillsRepository.FindSingleAsync(x => x.SkillId.Equals(request.SkillId) && x.UserId.Equals(request.MentorId), cancellationToken);

var mentorSkill = new Domain.Entities.MentorSkills()
{
Id = Guid.NewGuid(),
SkillId = request.SkillId,
UserId = request.MentorId,
};

_mentorSkillsRepository.Add(mentorSkill);

var tasks = request.ProductImages.Select(x => _mediaService.UploadImageAsync(x));
var result = await Task.WhenAll(tasks);

List<Certificate> certificates;

var certificates = result.Select(x => new Certificate()
if (mentorSkills is null)
{
Id = Guid.NewGuid(),
MentorSkillsId = mentorSkill.Id,
Name = "12312",
Description = "123123",
ImageUrl = x
}).ToList();
_mentorSkillsRepository.Add(mentorSkill);
certificates = result.Select(x => new Certificate()
{
Id = Guid.NewGuid(),
MentorSkillsId = mentorSkill.Id,
Name = "12312",
Description = "123123",
ImageUrl = x
}).ToList();
}
else
{
certificates = result.Select(x => new Certificate()
{
Id = Guid.NewGuid(),
MentorSkillsId = mentorSkills.Id,
Name = "12312",
Description = "123123",
ImageUrl = x
}).ToList();
}

_cetificateRepository.AddRange(certificates);

Expand Down

0 comments on commit 212126d

Please sign in to comment.