コード例 #1
0
        public async Task RegisterAsync([FromBody] UserFullDto request, string invitationCode)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.NormalizeAsRequest();
            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                if (!(await((IUserDomainService)DomainService).IsUsernameValidAsync(request.Username)))
                {
                    throw new ValidateEntityPropertiesException(nameof(request.Username));
                }
                Invitation invitation = await InvitationDomainService.UseInvitationAsync(invitationCode);

                User newUser = request.MapToEntity();
                newUser.MaxSitesCount = invitation.AvailableSitesCount;
                newUser.UserRoles     = new List <UserRole>()
                {
                    new UserRole()
                    {
                        User = newUser, RoleId = invitation.RoleId
                    }
                };
                await DomainService.CreateAsync(newUser);

                await uow.CompleteAsync();
            }
        }
コード例 #2
0
 public async Task <VehicleMakesDto> GetVehicleMakes(int siteId)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         return(new VehicleMakesDto(await((IVehicleDomainService)DomainService).GetMakes(siteId)));
     }
 }
コード例 #3
0
ファイル: SiteController.cs プロジェクト: vipdrv/vipdrv-core
        public async Task <ImportVehiclesShapshot> ImportVehiclesAsync(int siteId)
        {
            string                      message;
            ImportStatusEnum            status;
            ImportVehiclesForSiteResult importResult;
            Stopwatch                   stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                using (var uow = UowManager.CurrentOrCreateNew(true))
                {
                    importResult = await((ISiteDomainService)DomainService).ImportVehiclesAsync(siteId);
                    await uow.CompleteAsync();
                }
                status  = ImportStatusEnum.Success;
                message = null;
            }
            catch (Exception ex)
            {
                status       = ImportStatusEnum.Failed;
                message      = ex.Message;
                importResult = null;
            }
            stopWatch.Stop();
            ImportVehiclesShapshot importSnapshot = new ImportVehiclesShapshot(
                stopWatch.Elapsed, status, message,
                new List <ImportVehiclesForSiteResultDto>()
            {
                new ImportVehiclesForSiteResultDto(importResult)
            });

            return(importSnapshot);
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: SiteController.cs プロジェクト: vipdrv/vipdrv-core
        protected virtual async Task <ImportVehiclesShapshot> InnerImportVehiclesAsync()
        {
            string           message;
            ImportStatusEnum status;
            IEnumerable <ImportVehiclesForSiteResult> importResults;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                using (var uow = UowManager.CurrentOrCreateNew(true))
                {
                    importResults = await((ISiteDomainService)DomainService).ImportVehiclesAsync();
                    await uow.CompleteAsync();
                }
                status  = ImportStatusEnum.Success;
                message = null;
            }
            catch (Exception ex)
            {
                status        = ImportStatusEnum.Failed;
                message       = ex.Message;
                importResults = null;
            }
            stopWatch.Stop();
            ImportVehiclesShapshot importSnapshot = new ImportVehiclesShapshot(
                stopWatch.Elapsed, status, message,
                importResults.Select(importResult => new ImportVehiclesForSiteResultDto(importResult)));

            // do not await this
            LogImportSnapshot(importSnapshot);
            return(importSnapshot);
        }
コード例 #6
0
ファイル: SiteController.cs プロジェクト: vipdrv/vipdrv-core
 public async Task ChangeContactsAsync(int id, [FromBody] ChangeContactsRequest request)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((ISiteDomainService)DomainService).ChangeContactsAsync(id, request.Value);
         await uow.CompleteAsync();
     }
 }
コード例 #7
0
 protected virtual async Task ChangeOrderAsync(TPrimaryKey id, int newValue)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((IEntityExtendedDomainService <TEntity, TPrimaryKey>)DomainService).ChangeOrderAsync(id, newValue);
         await uow.CompleteAsync();
     }
 }
コード例 #8
0
 protected virtual async Task SwapOrdersAsync(TPrimaryKey key1, TPrimaryKey key2)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((IEntityExtendedDomainService <TEntity, TPrimaryKey>)DomainService).SwapOrdersAsync(key1, key2);
         await uow.CompleteAsync();
     }
 }
コード例 #9
0
 public async Task ChangeIsResolvedAsync(int id, [FromBody] PatchBoolPropertyRequest request)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((IWidgetEventDomainService)DomainService).ChangeIsResolvedAsync(id, request.Value);
         await uow.CompleteAsync();
     }
 }
コード例 #10
0
ファイル: LeadController.cs プロジェクト: vipdrv/vipdrv-core
 public async Task PatchIsReachedByManagerAsync([FromBody] PatchBoolPropertyRequest request, int id)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((ILeadDomainService)DomainService).ChangeIsReachedByManagerAsync(id, request.Value);
         await uow.CompleteAsync();
     }
 }
コード例 #11
0
        public async Task DeleteInvitationAsync(int id)
        {
            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                await InvitationDomainService.DeleteAsync(id);

                await uow.CompleteAsync();
            }
        }
コード例 #12
0
        /// <summary>
        /// Is used as inner delete method for entity
        /// </summary>
        /// <param name="id">entity id</param>
        /// <returns>deletion task</returns>
        protected virtual async Task InnerDeleteAsync(TPrimaryKey id)
        {
            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                await DomainService.DeleteAsync(id);

                await uow.CompleteAsync();
            }
        }
コード例 #13
0
 public async Task PatchPassword([FromBody] PatchAvatarRequest request, int id)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((IUserDomainService)DomainService)
         .UpdateAvatarAsync(id, request.NewAvatarUrl);
         await uow.CompleteAsync();
     }
 }
コード例 #14
0
 public async Task PatchPersonalInfo([FromBody] PatchPersonalInfoRequest request, int id)
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         await((IUserDomainService)DomainService)
         .UpdatePersonalInfoAsync(id, request.FirstName, request.SecondName, request.Email, request.PhoneNumber);
         await uow.CompleteAsync();
     }
 }
コード例 #15
0
ファイル: SiteController.cs プロジェクト: vipdrv/vipdrv-core
        public async Task <SiteWeekSchedule> GetWeekScheduleAsync(int id)
        {
            SiteWeekSchedule schedule;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                schedule = new SiteWeekSchedule(id, await((ISiteDomainService)DomainService).RetrieveWeekSchedule(id));
            }
            return(schedule);
        }
コード例 #16
0
 public async Task <IEnumerable <VehicleModelInfoDto> > GetVehicleModels(int siteId, string make, string sorting = "Name asc")
 {
     using (var uow = UowManager.CurrentOrCreateNew(true))
     {
         return((await((IVehicleDomainService)DomainService)
                 .GetModels(siteId, make))
                .Select(vehicleModelInfo => new VehicleModelInfoDto(vehicleModelInfo))
                .AsQueryable()
                .OrderBy(sorting));
     }
 }
コード例 #17
0
        /// <summary>
        /// Is used as inner get method for entity (returns full version of entity)
        /// </summary>
        /// <param name="id">entity id</param>
        /// <returns>entity as result of task</returns>
        protected virtual async Task <TEntityFullDto> InnerGetAsync(TPrimaryKey id)
        {
            TEntity entity;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                entity = await DomainService.RetrieveAsync(id);
            }
            TEntityFullDto response = new TEntityFullDto();

            response.MapFromEntity(entity);
            response.NormalizeAsResponse();
            return(response);
        }
コード例 #18
0
        /// <summary>
        /// Is used as inner update method for entity (updates entity and returns it back via <see cref="InnerGetAsync(TPrimaryKey)"/>)
        /// </summary>
        /// <param name="request">request</param>
        /// <returns>updated entity as result of task</returns>
        /// <exception cref="ArgumentNullException">Thrown when request is null</exception>
        protected virtual async Task <TEntityFullDto> InnerUpdateAsync(TEntityFullDto request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("Request");
            }
            request.NormalizeAsRequest();
            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                await DomainService.UpdateAsync(request.MapToEntity());

                await uow.CompleteAsync();
            }
            return(await InnerGetAsync(request.Id));
        }
コード例 #19
0
        /// <summary>
        /// Is used to retrieve all entities via filters and sorting as paged result
        /// </summary>
        /// <param name="filter">filter</param>
        /// <param name="sorting">sorting as string like "prop1 asc, prop2 desc"</param>
        /// <param name="page">page number (starts from 0)</param>
        /// <param name="pageSize">page size (count of elements on the page)</param>
        /// <returns>object with retrieved items and total count</returns>
        protected virtual async Task <GetAllResponse <TEntityDto> > InnerGetAllAsync(Expression <Func <TEntity, bool> > filter, string sorting, uint page, uint pageSize)
        {
            int             totalCount;
            IList <TEntity> entities;
            int             skip = (int)(page * pageSize);
            int             take = (int)pageSize;

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

                totalCount = take > 0 || skip > 0 && (entities.Count == take || skip != 0) ? await DomainService.GetTotalCountAsync(filter) : entities.Count;
            }
            return(new GetAllResponse <TEntityDto>(MapEntitiesToDtos <TEntity, TEntityDto>(entities), totalCount));
        }
コード例 #20
0
 public async Task PatchPassword([FromBody] PatchPasswordRequest request, int id)
 {
     try
     {
         using (var uow = UowManager.CurrentOrCreateNew(true))
         {
             await((IUserDomainService)DomainService)
             .UpdatePasswordAsync(id, request.OldPassword, request.NewPassword);
             await uow.CompleteAsync();
         }
     }
     catch (PasswordIsNotValidException)
     {
         Response.StatusCode = (int)HttpStatusCode.Unauthorized;
     }
 }
コード例 #21
0
        public async Task CreateAsync([FromBody] WidgetEventFullDto request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            request.NormalizeAsRequest();

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

                await uow.CompleteAsync();
            }
        }
コード例 #22
0
ファイル: LeadController.cs プロジェクト: vipdrv/vipdrv-core
        public async Task <string> ExportDataToExcelAsync([FromBody] LeadGetAllRequest request, uint?page = null, uint?pageSize = null)
        {
            Uri      fileUrl;
            TimeSpan timeZoneOffset = TimeSpan.Zero;
            string   fileName       = $"TestDrive-Leads-{DateTime.UtcNow.FormatUtcDateTimeToUserFriendlyString(timeZoneOffset, "yyyyMMddHHmmss")}";
            string   worksheetsName = "leads";

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                ExcelExportSettings <Lead> settings = new ExcelExportSettings <Lead>(
                    fileName, worksheetsName,
                    DomainService, ContentManager,
                    ExcelExportLeadOptionsProvider.GetEntityOptions((r) => r.UseByDefault, (key) => key, timeZoneOffset),
                    BuildRetrieveManyFilter(request), request.Sorting, page ?? 0 * pageSize ?? 0, pageSize);
                fileUrl = await ExcelExportService <Lead> .ExportDataAsync(settings);
            }
            return(fileUrl.ToString());
        }
コード例 #23
0
        /// <summary>
        /// Is used as inner create method for entity (creates entity and returns it back via <see cref="InnerGetAsync(TPrimaryKey)"/>)
        /// </summary>
        /// <param name="request">request</param>
        /// <returns>created entity as result of task</returns>
        /// <exception cref="ArgumentNullException">Thrown when request is null</exception>
        protected virtual async Task <TEntityFullDto> InnerCreateAsync(TEntityFullDto request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.NormalizeAsRequest();
            TPrimaryKey entityId;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                TEntity stubEntity = await DomainService.CreateAsync(request.MapToEntity());

                await uow.CompleteAsync();

                entityId = stubEntity.Id;
            }
            return(await InnerGetAsync(entityId));
        }
コード例 #24
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);
        }
コード例 #25
0
ファイル: SiteController.cs プロジェクト: vipdrv/vipdrv-core
        public async Task <SiteAggregatedInfoDto> GetSiteAggregatedInfoAsync(int id)
        {
            int              defaultSkip    = 0;
            int              defaultTake    = 100;
            string           defaultSorting = "order asc";
            Site             siteEntity;
            IList <Beverage> beverageEntities;
            IList <Expert>   expertEntities;
            IList <Route>    routeEntities;

            using (var uow = UowManager.CurrentOrCreateNew(true))
            {
                Task <Site> getSiteEntityTask = DomainService.RetrieveAsync(id);
                Task <IList <Beverage> > getBeverageEntitiesTask = BeverageDomainService.RetrieveAllAsync((entity) => entity.IsActive && entity.SiteId == id, defaultSorting, defaultSkip, defaultTake);
                Task <IList <Expert> >   getExpertEntitiesTask   = ExpertDomainService.RetrieveAllAsync((entity) => entity.IsActive && entity.SiteId == id, defaultSorting, defaultSkip, defaultTake);
                Task <IList <Route> >    getRouteEntitiesTask    = RouteDomainService.RetrieveAllAsync((entity) => entity.IsActive && entity.SiteId == id, defaultSorting, defaultSkip, defaultTake);
                await Task.WhenAll(getSiteEntityTask, getBeverageEntitiesTask, getExpertEntitiesTask, getRouteEntitiesTask);

                siteEntity       = await getSiteEntityTask;
                beverageEntities = await getBeverageEntitiesTask;
                expertEntities   = (await getExpertEntitiesTask);
                routeEntities    = await getRouteEntitiesTask;
            }
            SiteFullDto siteDto = new SiteFullDto();

            siteDto.MapFromEntity(siteEntity);
            siteDto.NormalizeAsResponse();
            if (siteEntity.ShuffleExperts)
            {
                expertEntities.Shuffle();
            }
            return(new SiteAggregatedInfoDto(
                       siteDto,
                       MapEntitiesToDtos <Beverage, BeverageDto>(beverageEntities),
                       MapEntitiesToDtos <Expert, ExpertDto>(expertEntities),
                       MapEntitiesToDtos <Route, RouteDto>(routeEntities)));
        }
コード例 #26
0
ファイル: LeadController.cs プロジェクト: vipdrv/vipdrv-core
        public async Task <LeadFullDto> CompleteBookingAsync(int siteId, [FromBody] CompleteBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            LeadFullDto leadFullDto = request.MapToLeadFullDto(siteId);

            leadFullDto.NormalizeAsRequest();
            Lead createdLead;

            using (var uow = UowManager.CurrentOrCreateNew())
            {
                Session.UserId = (await SiteDomainService.RetrieveAsync(siteId)).UserId;
                Lead stubEntity = await DomainService.CreateAsync(leadFullDto.MapToEntity());

                await uow.CompleteAsync();

                createdLead = await DomainService.RetrieveAsync(stubEntity.Id, false);
            }
            LeadFullDto createLeadFullDto = new LeadFullDto();

            createLeadFullDto.MapFromEntity(createdLead);

            #region Send EMAIL notifications

            Task <SendGrid.Response> sendCompleteBookingEmailTask = TestDriveEmailService
                                                                    .SendCompleteBookingEmail(
                new EmailAddress(createdLead.UserEmail, $"{createdLead.FirstName} {createdLead.SecondName}"),
                new CompleteBookingEmailTemplate(createdLead, request.TimeZoneOffset));

            Task <SendGrid.Response> sendNewLeadNotificationEmailTask = TestDriveEmailService
                                                                        .SendNewLeadNotificationEmail(
                createdLead.Site.EmailAdresses.Select(r => new EmailAddress(r)).ToList(),
                new NewLeadNotificationEmailTemplate(createdLead, request.TimeZoneOffset));

            Task <SendGrid.Response> sendAdfEmailTask = TestDriveEmailService
                                                        .SendAdfEmail(
                createdLead.Site.AdfEmailAdresses.Select(r => new EmailAddress(r)).ToList(),
                new EleadAdfTemplate(createdLead, request.BookingVehicle, request.TimeZoneOffset));

            await Task.WhenAll(sendCompleteBookingEmailTask, sendNewLeadNotificationEmailTask, sendAdfEmailTask);

            // responses can be analyzed below via send...EmailTask.Result

            #endregion

            #region Send SMS notifications

            await SmsService.SendSms(createdLead.Site.PhoneNumbers, new NewLeadNotificationSmsTemplate(createdLead, request.TimeZoneOffset));

            #endregion

            #region Sales person notifications

            if (createdLead.Expert != null && !String.IsNullOrWhiteSpace(createdLead.Expert.Email))
            {
                await TestDriveEmailService.SendNewLeadNotificationEmail(
                    new List <EmailAddress>() { new EmailAddress(createdLead.Expert.Email) },
                    new ExpertNotificationEmailTemplate(createdLead, request.TimeZoneOffset));
            }

            if (createdLead.Expert != null && !String.IsNullOrWhiteSpace(createdLead.Expert.PhoneNumber) && createdLead.Site.Id != 1070)
            {
                await SmsService.SendSms(new List <string>() { createdLead.Expert.PhoneNumber },
                                         new NewLeadNotificationSmsTemplate(createdLead, request.TimeZoneOffset));
            }

            #endregion

            return(createLeadFullDto);
        }