コード例 #1
0
        DeleteSubscriptionBySubscriptionId(int id)
        {
            OperationResponse <Entities.Model.Subscription.Subscription> response = new OperationResponse <Entities.Model.Subscription.Subscription>();

            try
            {
                var existsSubscription = await _unitOfWork.SubscriptionRepository.GetById(id);

                if (existsSubscription == null)
                {
                    throw new Exception("Sistemde kayıtlı bir abonelik bilgisi bulunamadı.");
                }

                var existsComputer = await _customerComputerInfoManager.GetAlreadyComputerCountsBySubscriptionId(id);

                if (existsComputer.Status == false)
                {
                    throw new Exception(existsComputer.Message);
                }

                if (existsComputer.Data > 0)
                {
                    throw new Exception("Bu abonelik silinemez çünkü kayıt edilmiş bilgisayarları var. Mevcut aboneliği kaldırmak yerine pasif hale getiriniz.");
                }

                await _unitOfWork.SubscriptionRepository.Delete(existsSubscription);

                var responseUnitOfWork = await _unitOfWork.Save();

                response.Status  = responseUnitOfWork.Status;
                response.Message = responseUnitOfWork.Message;
            }
            catch (Exception e)
            {
                response.Status  = false;
                response.Message = e.Message;
            }
            return(response);
        }
コード例 #2
0
        public async Task <OperationResponse <Entities.ViewModel.Register.RegisterComputer> > SaveRegisterComputer(
            Entities.ViewModel.Register.RegisterComputer registerComputer)
        {
            OperationResponse <Entities.ViewModel.Register.RegisterComputer> response = new OperationResponse <Entities.ViewModel.Register.RegisterComputer>();

            try
            {
                if (registerComputer == null)
                {
                    throw new Exception("RegisterComputer nesnesi null olamaz");
                }

                var valid = await new RegisterComputerValidator().ValidateAsync(registerComputer);
                if (valid.IsValid == false)
                {
                    throw new Exception(valid.GetErrorMessagesOnSingleLine());
                }

                #region Yazılım adını kontrol et ve aktif mi kontrol et?
                var softwareExistsResult = await _softwareManager.GetBySoftwareName(registerComputer.SoftwareName);

                if (softwareExistsResult.Status == false)
                {
                    throw new Exception(softwareExistsResult.Message);
                }

                if (softwareExistsResult.Data.SoftwareIsActive == false)
                {
                    throw new Exception("Bu yazılım artık aktif değil.");
                }

                #endregion


                #region Müşteriyi kontrol et ve aktif mi kontrol et?
                var customerExistsResult = await _customerManager.GetCustomerByEmail(registerComputer.CustomerEMail);

                if (customerExistsResult.Status == false)
                {
                    throw new Exception(customerExistsResult.Message);
                }

                if (customerExistsResult.Data.CustomerIsActive == false)
                {
                    throw new Exception("Bu müşteri artık aktif değil.");
                }
                #endregion

                //Subscription durumunu önce kontrol et
                var subscriptionExistsResult = await
                                               _subscriptionManager.GetBySubscriptionStatusBySoftwareIdAndCustomerId(softwareExistsResult.Data.SoftwareId,
                                                                                                                     customerExistsResult.Data.CustomerId);

                if (subscriptionExistsResult.Status == false)
                {
                    throw new Exception(subscriptionExistsResult.Message);
                }

                if (subscriptionExistsResult.Data.SubscriptionIsActive == false)
                {
                    throw new Exception("Bu abonelik artık aktif değil.");
                }

                //Lisans hakkı var ise gönderdiği HDD, MAC, Process bilgisi ile zaten o bilgisayar mı onu kontrol et
                var customerComputerInfoExists = await
                                                 _customerComputerInfoManager.GetByCustomerComputerHddAndMacAndProcessSerialCode(subscriptionExistsResult.Data.SubscriptionId,
                                                                                                                                 registerComputer.ComputerInfoHddSerialCode, registerComputer.ComputerInfoMacSerialCode,
                                                                                                                                 registerComputer.ComputerInfoProcessSerialCode);

                if (customerComputerInfoExists.Status)
                {
                    response.Status  = true;
                    response.Message = $"Lisans {subscriptionExistsResult.Data.SubScriptionEndDate.ToString("dd/MM/yyyy HH:mm:ss")} tarihine kadar aktif.";
                    return(response);
                }

                var alreadyComputerCountsResult = await _customerComputerInfoManager.GetAlreadyComputerCountsBySubscriptionId(subscriptionExistsResult.Data.SubscriptionId);

                if (alreadyComputerCountsResult.Status == false)
                {
                    throw new Exception(alreadyComputerCountsResult.Message);
                }

                //Bilgiler doğru değil ise sisteme kaydetmeden Subscription Lisans hakkı var mı kontrol et. veya hoşçakal de.
                if (subscriptionExistsResult.Data.SubScriptionLicenceCount <= alreadyComputerCountsResult.Data)
                {
                    throw new Exception($"Lisans hakkınızın tamamını kullanmışsınız {alreadyComputerCountsResult.Data}/{subscriptionExistsResult.Data.SubScriptionLicenceCount}");
                }


                //Demek ki hala kayıt edebilme hakkı var.
                var saveCustomerComputerInfo = await _customerComputerInfoManager.SaveCustomerComputerInfo(registerComputer.MapRegisterComputerToCustomerComputerInfo(subscriptionExistsResult.Data.SubscriptionId));

                if (saveCustomerComputerInfo.Status == false)
                {
                    throw new Exception(saveCustomerComputerInfo.Message);
                }

                response.Status  = true;
                response.Message = "Yeni bilgisayar sisteme tanımlandı";
            }
            catch (Exception e)
            {
                response.Status  = false;
                response.Message = e.Message;
            }

            return(response);
        }