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(); } }
public async Task <VehicleMakesDto> GetVehicleMakes(int siteId) { using (var uow = UowManager.CurrentOrCreateNew(true)) { return(new VehicleMakesDto(await((IVehicleDomainService)DomainService).GetMakes(siteId))); } }
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); }
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)); }
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); }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
public async Task DeleteInvitationAsync(int id) { using (var uow = UowManager.CurrentOrCreateNew(true)) { await InvitationDomainService.DeleteAsync(id); await uow.CompleteAsync(); } }
/// <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(); } }
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(); } }
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(); } }
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); }
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)); } }
/// <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); }
/// <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)); }
/// <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)); }
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; } }
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(); } }
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()); }
/// <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)); }
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); }
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))); }
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); }