Beispiel #1
0
        public async Task CreateQuotationStatus(CreateQuotationStatusInput input)
        {
            using (_unitOfWorkManager.Current.SetTenantId(_session.TenantId))
            {
                input.TenantId = (int)_session.TenantId;
                var QuotationStatus = input.MapTo <QuotationStatus>();

                var val = _QuotationStatusRepository
                          .GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName).FirstOrDefault();

                if (input.New)
                {
                    val = _QuotationStatusRepository.GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName || p.New == true).FirstOrDefault();
                }
                else if (input.Submitted)
                {
                    val = _QuotationStatusRepository.GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName || p.Submitted == true).FirstOrDefault();
                }
                else if (input.Revised)
                {
                    val = _QuotationStatusRepository.GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName || p.Revised == true).FirstOrDefault();
                }
                else if (input.Won)
                {
                    val = _QuotationStatusRepository.GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName || p.Won == true).FirstOrDefault();
                }
                else if (input.Lost)
                {
                    val = _QuotationStatusRepository.GetAll().Where(p => p.QuotationStatusCode == input.QuotationStatusCode || p.QuotationStatusName == input.QuotationStatusName || p.Lost == true).FirstOrDefault();
                }

                if (val == null)
                {
                    await _QuotationStatusRepository.InsertAsync(QuotationStatus);
                }
                else
                {
                    throw new UserFriendlyException("Ooops!", "Duplicate Data Occured...");
                }
            }
        }
Beispiel #2
0
        public async Task <RegisterTenantOutput> RegisterTenant(RegisterTenantInput input)
        {
            try
            {
                if (input.EditionId.HasValue)
                {
                    await CheckEditionSubscriptionAsync(input.EditionId.Value, input.SubscriptionStartType, input.Gateway, input.PaymentId);
                }
                else
                {
                    await CheckRegistrationWithoutEdition();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            try
            {
                using (CurrentUnitOfWork.SetTenantId(null))
                {
                    CheckTenantRegistrationIsEnabled();

                    if (UseCaptchaOnRegistration())
                    {
                        await _recaptchaValidator.ValidateAsync(input.CaptchaResponse);
                    }

                    //Getting host-specific settings
                    var isNewRegisteredTenantActiveByDefault = await SettingManager.GetSettingValueForApplicationAsync <bool>(AppSettings.TenantManagement.IsNewRegisteredTenantActiveByDefault);

                    var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueForApplicationAsync <bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin);

                    DateTime?subscriptionEndDate = null;
                    var      isInTrialPeriod     = false;

                    if (input.EditionId.HasValue)
                    {
                        isInTrialPeriod = input.SubscriptionStartType == SubscriptionStartType.Trial;

                        if (isInTrialPeriod)
                        {
                            var edition = (SubscribableEdition)await _editionManager.GetByIdAsync(input.EditionId.Value);

                            subscriptionEndDate = Clock.Now.AddDays(edition.TrialDayCount ?? 0);
                        }
                    }

                    var tenantId = await _tenantManager.CreateWithAdminUserAsync(
                        input.TenancyName,
                        input.Name,
                        input.AdminPassword,
                        input.AdminEmailAddress,
                        null,
                        isNewRegisteredTenantActiveByDefault,
                        input.EditionId,
                        false,
                        true,
                        subscriptionEndDate,
                        isInTrialPeriod,
                        AppUrlService.CreateEmailActivationUrlFormat(input.TenancyName),
                        input.TenantTypeId
                        );

                    Tenant tenant;

                    if (input.SubscriptionStartType == SubscriptionStartType.Paid)
                    {
                        if (!input.Gateway.HasValue)
                        {
                            throw new Exception("Gateway is missing!");
                        }

                        var payment = await _subscriptionPaymentRepository.GetByGatewayAndPaymentIdAsync(
                            input.Gateway.Value,
                            input.PaymentId
                            );

                        tenant = await _tenantManager.UpdateTenantAsync(
                            tenantId,
                            true,
                            false,
                            payment.PaymentPeriodType,
                            payment.EditionId,
                            EditionPaymentType.NewRegistration);

                        await _subscriptionPaymentRepository.UpdateByGatewayAndPaymentIdAsync(input.Gateway.Value,
                                                                                              input.PaymentId, tenantId, SubscriptionPaymentStatus.Completed);
                    }
                    else
                    {
                        tenant = await TenantManager.GetByIdAsync(tenantId);
                    }

                    await _appNotifier.NewTenantRegisteredAsync(tenant);

                    if (input.EditionId.HasValue && input.Gateway.HasValue && !input.PaymentId.IsNullOrEmpty())
                    {
                        _paymentCache.RemoveCacheItem(input.Gateway.Value, input.PaymentId);
                    }



                    CreateMileInputDto mob = new CreateMileInputDto();
                    mob.Code        = "LD";
                    mob.Name        = "Lead";
                    mob.TenantId    = tenantId;
                    mob.Id          = 0;
                    mob.IsQuotation = false;
                    var milestone2 = mob.MapTo <MileStone>();
                    await _MilestoneRepository.InsertAsync(milestone2);

                    CreateMileInputDto mobj = new CreateMileInputDto();
                    mobj.Code        = "QL";
                    mobj.Name        = "Qualified";
                    mobj.TenantId    = tenantId;
                    mobj.Id          = 0;
                    mobj.IsQuotation = false;
                    var milestone = mobj.MapTo <MileStone>();
                    await _MilestoneRepository.InsertAsync(milestone);

                    CreateMileInputDto QT = new CreateMileInputDto();
                    QT.Code        = "QT";
                    QT.Name        = "Qouted";
                    QT.TenantId    = tenantId;
                    QT.Id          = 0;
                    QT.IsQuotation = true;
                    var Qouted = QT.MapTo <MileStone>();
                    await _MilestoneRepository.InsertAsync(Qouted);

                    CreateMileInputDto NG = new CreateMileInputDto();
                    NG.Code        = "NG";
                    NG.Name        = "Negotiation";
                    NG.TenantId    = tenantId;
                    NG.Id          = 0;
                    NG.IsQuotation = true;
                    var Negotiation = NG.MapTo <MileStone>();
                    await _MilestoneRepository.InsertAsync(Negotiation);

                    CreateMileInputDto CL = new CreateMileInputDto();
                    CL.Code        = "CL";
                    CL.Name        = "Closed";
                    CL.TenantId    = tenantId;
                    CL.Id          = 0;
                    CL.IsQuotation = true;
                    var Closed = CL.MapTo <MileStone>();
                    await _MilestoneRepository.InsertAsync(Closed);

                    CreateQuotationStatusInput QS1 = new CreateQuotationStatusInput();
                    QS1.QuotationStatusCode = "NW";
                    QS1.QuotationStatusName = "New";
                    QS1.New      = true;
                    QS1.TenantId = tenantId;
                    QS1.Id       = 0;
                    var QS1s = QS1.MapTo <QuotationStatus>();
                    await _QuotationStatusRepository.InsertAsync(QS1s);

                    CreateQuotationStatusInput QS2 = new CreateQuotationStatusInput();
                    QS2.QuotationStatusCode = "SU";
                    QS2.QuotationStatusName = "Submitted";
                    QS2.Submitted           = true;
                    QS2.TenantId            = tenantId;
                    QS2.Id = 0;
                    var QS2s = QS2.MapTo <QuotationStatus>();
                    await _QuotationStatusRepository.InsertAsync(QS2s);

                    CreateQuotationStatusInput QS3 = new CreateQuotationStatusInput();
                    QS3.QuotationStatusCode = "WO";
                    QS3.QuotationStatusName = "Won";
                    QS3.Won      = true;
                    QS3.TenantId = tenantId;
                    QS3.Id       = 0;
                    var QS3s = QS3.MapTo <QuotationStatus>();
                    await _QuotationStatusRepository.InsertAsync(QS3s);

                    CreateQuotationStatusInput QS4 = new CreateQuotationStatusInput();
                    QS4.QuotationStatusCode = "LO";
                    QS4.QuotationStatusName = "Lost";
                    QS4.Lost     = true;
                    QS4.TenantId = tenantId;
                    QS4.Id       = 0;
                    var QS4s = QS4.MapTo <QuotationStatus>();
                    await _QuotationStatusRepository.InsertAsync(QS4s);

                    CreateQuotationStatusInput QS5 = new CreateQuotationStatusInput();
                    QS5.QuotationStatusCode = "RE";
                    QS5.QuotationStatusName = "Revised";
                    QS5.Revised             = true;
                    QS5.TenantId            = tenantId;
                    QS5.Id = 0;
                    var QS5s = QS5.MapTo <QuotationStatus>();
                    await _QuotationStatusRepository.InsertAsync(QS5s);


                    return(new RegisterTenantOutput
                    {
                        TenantId = tenant.Id,
                        TenancyName = input.TenancyName,
                        Name = input.Name,
                        UserName = AbpUserBase.AdminUserName,
                        EmailAddress = input.AdminEmailAddress,
                        IsActive = tenant.IsActive,
                        IsEmailConfirmationRequired = isEmailConfirmationRequiredForLogin,
                        IsTenantActive = tenant.IsActive
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }