Beispiel #1
0
        public async Task <GetAllResponse <InvitationDto> > GetAllCreatedInvitationsAsync(int id, uint page = 0, uint pageSize = 0, string sorting = null)
        {
            Expression <Func <Invitation, bool> > filter = (entity) => entity.InvitatorId == id;
            int totalCount;
            IList <Invitation> entities;
            int skip = (int)(page * pageSize);
            int take = (int)pageSize;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                entities = await InvitationDomainService.RetrieveAllAsync(filter, sorting, skip, take);

                totalCount = take > 0 || skip > 0 && (entities.Count == take || skip != 0) ?
                             await InvitationDomainService.GetTotalCountAsync(filter) :
                             entities.Count;
            }
            List <InvitationDto> entityDtos = new List <InvitationDto>(entities.Count);

            foreach (Invitation entity in entities)
            {
                InvitationDto entityDto = new InvitationDto();
                entityDto.MapFromEntity(entity);
                entityDto.NormalizeAsResponse();
                entityDtos.Add(entityDto);
            }
            return(new GetAllResponse <InvitationDto>(entityDtos, totalCount));
        }
Beispiel #2
0
        public async Task <InvitationDto> CreateInvitationAsync([FromBody] InvitationDto request)
        {
            string origin;

            try
            {
                Microsoft.Extensions.Primitives.StringValues origins;
                Request.Headers.TryGetValue("Origin", out origins);
                origin = origins[0];
            }
            catch
            {
                Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                throw new ArgumentException("Origin");
            }

            Invitation entity;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                entity = await InvitationDomainService.CreateAsync(request.MapToEntity());

                await uow.CompleteAsync();
            }
            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                entity = await InvitationDomainService.RetrieveAsync(entity.Id);
            }

            SendGrid.Response sendDealerInvitationEmailResponse = await TestDriveEmailService
                                                                  .SendDealerInvitationEmail(
                new EmailAddress(entity.Email, string.Empty),
                new DealerInvitationEmailTemplate($"{origin}/#/registration/{entity.InvitationCode}"));

            InvitationDto dto = new InvitationDto();

            dto.MapFromEntity(entity);
            return(dto);
        }