/// <summary> /// Creates a valid <see cref="AddCustomEntityCommand"/> for the /// <see cref="TestCustomEntityDefinition"/> without the option to publish. /// </summary> /// <param name="uniqueData"> /// Unique data to use in creating the Title and UrlSlug property. /// </param> public AddCustomEntityCommand CreateAddCommand(string uniqueData) { var command = new AddCustomEntityCommand() { Title = uniqueData, CustomEntityDefinitionCode = TestCustomEntityDefinition.Code, Model = new TestCustomEntityDataModel(), UrlSlug = SlugFormatter.ToSlug(uniqueData) }; return(command); }
public async Task ExecuteAsync(BookingRequestCommand command, IExecutionContext executionContext) { using (var scope = DomainRepository.Transactions().CreateScope()) { var tenantCategory = await TenantCategoryProvider.GetTenantCategoryById(command.TenantCategoryId.Value); DateTime lastAllowedArrivalDate = DateTime.Now.AddMonths(tenantCategory.AllowedBookingFutureMonths); if (command.ArrivalDate.Value >= lastAllowedArrivalDate || command.DepartureDate.Value >= lastAllowedArrivalDate) { throw new ValidationErrorException(new ValidationError($"Den valgte lejertype kan ikke reservere mere end {tenantCategory.AllowedBookingFutureMonths} måneder ud i fremtiden. Dvs. senest {lastAllowedArrivalDate.ToShortDateString()}.", nameof(command.ArrivalDate))); } int bookingNumber = await SequenceNumberGenerator.NextNumber("BookingNumber"); var booking = new BookingDataModel { BookingNumber = bookingNumber, ArrivalDate = command.ArrivalDate.Value, DepartureDate = command.DepartureDate.Value, OnlySelectedWeekdays = command.OnlySelectedWeekdays, SelectedWeekdays = command.SelectedWeekdays, TenantCategoryId = command.TenantCategoryId.Value, TenantName = command.TenantName, Purpose = command.Purpose, ContactName = command.ContactName, ContactPhone = command.ContactPhone, ContactAddress = command.ContactAddress, ContactCity = command.ContactCity, ContactEMail = command.ContactEMail, Comments = command.Comments, RentalPrice = null, // To be set later Deposit = BookingSettings.StandardDeposit, BookingState = BookingDataModel.BookingStateType.Requested }; await booking.AddLogEntry(CurrentUserProvider, "Reservationen blev indsendt af lejer."); await SendConfirmationMail(booking); await SendNotificationMail(booking); var addCommand = new AddCustomEntityCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, Model = booking, Title = booking.MakeTitle(), Publish = true, }; await DomainRepository.WithElevatedPermissions().CustomEntities().AddAsync(addCommand); await scope.CompleteAsync(); } }
private AddCustomEntityCommand MapCommand( DuplicateCustomEntityCommand command, CustomEntityVersion customEntityVersionToDuplicate ) { EntityNotFoundException.ThrowIfNull(customEntityVersionToDuplicate, command.CustomEntityToDuplicateId); var addCustomEntityCommand = new AddCustomEntityCommand(); addCustomEntityCommand.Title = command.Title; addCustomEntityCommand.LocaleId = command.LocaleId; addCustomEntityCommand.UrlSlug = command.UrlSlug; addCustomEntityCommand.CustomEntityDefinitionCode = customEntityVersionToDuplicate.CustomEntity.CustomEntityDefinitionCode; addCustomEntityCommand.Model = _customEntityDataModelMapper.Map(addCustomEntityCommand.CustomEntityDefinitionCode, customEntityVersionToDuplicate.SerializedData); return(addCustomEntityCommand); }
public async Task <int> AddAsync(AddCustomEntityCommand command) { await ExtendableContentRepository.ExecuteCommandAsync(command); return(command.OutputCustomEntityId); }
public async Task ExecuteAsync(ImportBookingsCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); DataSet bookings = new DataSet(); bookings.ReadXml(command.ReadyToReadInput); var groupedBookings = bookings.Tables[0].Rows .Cast <DataRow>() .GroupBy(row => row["AftaleID"].ToString()); int count = 0; foreach (var bookingGroup in groupedBookings) { try { int bookingNumber = Convert.ToInt32(bookingGroup.Key); string startStr = bookingGroup.Min(b => b["Dato"].ToString()); DateTime arrivalDate = DateTime.SpecifyKind(DateTime.Parse(startStr), DateTimeKind.Utc); string endStr = bookingGroup.Max(b => b["Dato"].ToString()); DateTime departureDate = DateTime.SpecifyKind(DateTime.Parse(endStr), DateTimeKind.Utc); DataRow row = bookingGroup.First(); string status = row["Status"].ToString(); string origin1 = row["HvorDuFra"].ToString(); string origin2 = row["Fra"].ToString(); string purpose = row["Formaal"].ToString(); string contactName = row["KontaktPerson"].ToString(); string contactEmail = row["Email"].ToString(); string contactAddress = row["Adresse"].ToString(); string comments = row["Bem"].ToString(); decimal.TryParse(row["AftaltLeje"].ToString(), out decimal rentalPrice); int tenantCategoryId = GetTenantCategory(origin1); BookingDataModel booking = new BookingDataModel { BookingNumber = bookingNumber, ArrivalDate = arrivalDate, DepartureDate = departureDate, OnlySelectedWeekdays = false, SelectedWeekdays = new List <WeekdayType>(), TenantCategoryId = tenantCategoryId, TenantName = origin2, Purpose = purpose, ContactName = contactName, ContactPhone = "", ContactAddress = contactAddress, ContactCity = "", ContactEMail = contactEmail, Comments = "Importeret i 2021 fra gammelt bookingsystem\n\n" + comments, RentalPrice = Math.Abs(rentalPrice), Deposit = 0, BookingState = BookingDataModel.BookingStateType.Closed, IsApproved = true, IsCheckedOut = true, WelcomeLetterIsSent = true }; if (booking.ArrivalDate.Value.Year >= 2021) { if (status == "Forespørgsel") { booking.BookingState = BookingDataModel.BookingStateType.Requested; booking.IsApproved = false; booking.WelcomeLetterIsSent = false; booking.IsCheckedOut = false; } else if (status == "Bekræftet") { booking.BookingState = BookingDataModel.BookingStateType.Approved; booking.IsApproved = true; booking.WelcomeLetterIsSent = false; booking.IsCheckedOut = false; } else if (status == "Nøgle sendt") { booking.BookingState = BookingDataModel.BookingStateType.Approved; booking.IsApproved = true; booking.WelcomeLetterIsSent = true; booking.IsCheckedOut = false; } } var addCommand = new AddCustomEntityCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, Model = booking, Title = booking.MakeTitle(), Publish = true }; await DomainRepository.WithElevatedPermissions().CustomEntities().AddAsync(addCommand); if (++count >= 10000) { break; } } catch (ValidationException ex) { if (ex.ValidationResult is CompositeValidationResult vres) { throw new Exception($"Failed to validate booking number {bookingGroup.Key}: {vres.Results?.FirstOrDefault()}.", ex); } else { throw new Exception($"Failed to validate booking number {bookingGroup.Key}: {ex.ValidationResult?.ErrorMessage} ({ex.ValidationResult?.MemberNames?.FirstOrDefault()}).", ex); } } catch (Exception ex) { throw new Exception($"Failed to import booking number {bookingGroup.Key}.", ex); } } //return Task.CompletedTask; }
public Task <JsonResult> Post([ModelBinder(BinderType = typeof(CustomEntityDataModelCommandModelBinder))] AddCustomEntityCommand command) { return(_apiResponseHelper.RunCommandAsync(command)); }
public async Task <IActionResult> Post([ModelBinder(BinderType = typeof(CustomEntityDataModelCommandModelBinder))] AddCustomEntityCommand command) { return(await _apiResponseHelper.RunCommandAsync(this, command)); }