예제 #1
0
 public void CreateTenantAdminPermission(string tenantId)
 {
     PermissionBuilder.Build(BusinessDbContext.Create(), tenantId);
 }
 public ProductCategoryController() : base(new BaseService <ProductCategory, ProductCategoryRequestModel, ProductCategoryViewModel>(new BaseRepository <ProductCategory>(BusinessDbContext.Create())))
 {
 }
예제 #3
0
 public DealerController() : base(new BaseService <Dealer, DealerRequestModel, DealerViewModel>(new BaseRepository <Dealer>(BusinessDbContext.Create())))
 {
 }
예제 #4
0
 public ProductGroupQueryController() : base(new BaseService <M, Rm, Vm>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
예제 #5
0
 public ShopQueryController()
 {
     shopService = new ShopService(new BaseRepository <M>(BusinessDbContext.Create()));
 }
        public async Task <IHttpActionResult> CreateTenant(TenantViewModel model)
        {
            model.TenancyName = model.Name.ToTenancyName();
            if (!string.IsNullOrWhiteSpace(model.TenancyName))
            {
                ModelState.Remove("model.TenancyName");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool isReservedName = _service.IsReservedName(model.TenancyName);

            if (isReservedName)
            {
                return(BadRequest($"Sorry, {model.TenancyName} is reserved. Please select another name"));
            }

            //if (model.SubscriptionEndTime == null) return BadRequest("Subscription end time can not be null. Please select a package.");

            var isTenantExist = _service.IsTenantExist(model.TenancyName);

            if (isTenantExist)
            {
                return(BadRequest("Company name '" + model.Name + "' already exist. Please try with different one."));
            }

            //bool isEmailExist = _tenantManager.IsEmailExist(model.Email);
            //if (isEmailExist) return BadRequest(model.Email + " email address already exist.");

            if (model.PasswordHash != model.RetypePassword)
            {
                return(BadRequest("Password and confirm password could not match."));
            }

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                model.Id = Guid.NewGuid().ToString();
            }
            model.Active = true;

            if (model.IsLifeTimeSubscription)
            {
                model.SubscriptionEndTime = null;
            }

            string tenantId = model.Id;
            string companyId;
            string branchId;
            string subscriptionId;
            string adminRoleId;

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TransactionManager.MaximumTimeout
                }))
                {
                    tenantId = _tenantManager.CreateTenant(model);

                    companyId = _tenantManager.CreateTenantCompany(tenantId, model.Name, model.Email, model.PhoneNumber);
                    //_tenantManager.CreateTenantCompanySettings(tenantId, company);

                    branchId = _tenantManager.CreateTenantHeadOfficeBranch(tenantId, companyId);
                    //_tenantManager.CreateTenantHeadOfficeWarehouse(tenantId, companyId);

                    subscriptionId = _tenantManager.CreateTenantSubscription(model, tenantId, companyId, branchId, model.IsLifeTimeSubscription);

                    _tenantManager.UpdateSubscriptionId(tenantId, subscriptionId);

                    //_tenantManager.CreateSupplier(tenantId, tenantCompanyId);


                    adminRoleId = _tenantManager.CreateTenantRole(tenantId, companyId);

                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Error(e.ToString());

                await _tenantManager.RollbackAsync(tenantId);

                return(BadRequest("Registration failed! please try again."));
            }


            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TimeSpan.MaxValue
                }))
                {
                    var userId = _tenantManager.CreateTenantAdminUser(model, tenantId, companyId, branchId, adminRoleId);
                    _tenantManager.CreateTenantAdminPermission(tenantId);

                    BusinessModelSeedDataManager.CreateFiscalYear(BusinessDbContext.Create(), tenantId);

                    scope.Complete();

                    var smsResponseModel = _smsService.SendOneToOneSingleSmsUsingApi(model.PhoneNumber, SmsHelper.TenantRegistrationMessage);

                    _tenantManager.ConfirmCompanyMobileNumber(smsResponseModel, companyId);
                    await _tenantManager.ConfirmAdminMobileNumberAsync(smsResponseModel, userId);
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Error(e.ToString());

                await _tenantManager.RollbackAsync(tenantId);

                return(BadRequest("Registration failed! please try again."));
            }


            try
            {
                if (string.IsNullOrWhiteSpace(companyId) || string.IsNullOrWhiteSpace(tenantId))
                {
                    throw new Exception("Company Id or Tenant Id can not be null");
                }

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
                                                                     new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TransactionManager.MaximumTimeout
                }))
                {
                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Error(e.ToString());

                await _tenantManager.RollbackAsync(tenantId);

                return(BadRequest("Registration failed! please try again."));
            }



            return(Ok(model));
        }
 public ProductGroupController() : base(new BaseService <M, ProductGroupRequestModel, ProductGroupViewModel>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
 public HookDetailQueryController() : base(new BaseService <HookDetail, HookDetailRequestModel, HookDetailViewModel>(new BaseRepository <HookDetail>(BusinessDbContext.Create())))
 {
 }
예제 #9
0
 public EmployeeInfoQueryController() : base(new BaseService <EmployeeInfo, EmployeeInfoRequestModel, EmployeeInfoViewModel>(new BaseRepository <EmployeeInfo>(BusinessDbContext.Create())))
 {
 }
예제 #10
0
 // dependency injection
 public LevelController()
     : base(new BaseService <Level, LevelRequestModel, LevelViewModel>(new BaseRepository <Level>(BusinessDbContext.Create())))
 {
 }
 public AccountHeadController() : base(new BaseService <AccountHead, AccountHeadRequestModel, AccountHeadViewModel>(
                                           new BaseRepository <AccountHead>(BusinessDbContext.Create())))
 {
 }
예제 #12
0
 public WarehouseController() : base(new BaseService <Warehouse, WarehouseRequestModel, WarehouseViewModel>(
                                         new BaseRepository <Warehouse>(BusinessDbContext.Create())))
 {
 }
        public IHttpActionResult UpdateDues(DealerProductDetailUpdateModel model)
        {
            DealerProductService service = new DealerProductService(new BaseRepository <DealerProduct>(BusinessDbContext.Create()));

            AddCommonValues(model, model.Transaction);

            foreach (var entity in model.DealerProductTransactions)
            {
                AddCommonValues(model, entity);
                entity.TransactionId = model.Transaction.Id;
            }

            bool updated = service.UpdateDues(model);

            return(Ok(updated));
        }
 public DealerProductController() : base(new BaseService <DealerProduct, DealerProductRequestModel, DealerProductViewModel>(new BaseRepository <DealerProduct>(BusinessDbContext.Create())))
 {
 }
예제 #15
0
 public DamageController() : base(new BaseService <Damage, DamageRequestModel, DamageViewModel>(new BaseRepository <Damage>(BusinessDbContext.Create())))
 {
 }
 public PurchaseQueryController() : base(new Service(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
예제 #17
0
 public CourseController()
     : base(new BaseService <Course, CourseRequestModel, CourseViewModel>(new BaseRepository <Course>(BusinessDbContext.Create())))
 {
 }
예제 #18
0
 public CustomerFeedbackController() : base(new BaseService <M, RM, VM>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
예제 #19
0
 public CustomerController() : base(new CustomerService(new BaseRepository <Customer>(BusinessDbContext.Create())))
 {
 }
예제 #20
0
 public InstallmentQueryController()
     : base(new BaseService <M, Rm, Vm>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
 public CustomerAddressQueryController() : base(new BaseService <M, Rm, Vm>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
 public ProductDetailQueryController() : base(new ProductDetailService(new BaseRepository <ProductDetail>(BusinessDbContext.Create())))
 {
 }
 public BrandQueryController() : base(new BaseService <M, BrandRequestModel, BrandViewModel>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
 public AccountHeadQueryController() : base(new BaseService <M, Rm, Vm>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
 public TransactionQueryController() : base(new BaseService <Transaction, TransactionRequestModel, TransactionViewModel>(new BaseRepository <Transaction>(BusinessDbContext.Create())))
 {
 }
예제 #26
0
 public SmsController() : base(new BaseService <Sms, SmsRequestModel, SmsViewModel>(new BaseRepository <Sms>(BusinessDbContext.Create())))
 {
 }
예제 #27
0
        public override bool Add(M purchase)
        {
            foreach (var detail in purchase.PurchaseDetails)
            {
                detail.Id          = Guid.NewGuid().ToString();
                detail.PurchaseId  = purchase.Id;
                detail.Created     = purchase.Created;
                detail.CreatedFrom = purchase.CreatedFrom;
                detail.CreatedBy   = purchase.CreatedBy;
                detail.Modified    = purchase.Modified;
                detail.ModifiedBy  = purchase.ModifiedBy;
                detail.ShopId      = purchase.ShopId;
                detail.WarehouseId = purchase.WarehouseId;
            }

            purchase.State = PurchaseStates.Received.ToString();
            using (TransactionScope scope = new TransactionScope())
            {
                bool added = base.Add(purchase);
                if (added)
                {
                    UpdateProductDetail(purchase);
                    AddTransaction(purchase);

                    SupplierProductService supplierProductService = new SupplierProductService(new BaseRepository <SupplierProduct>(BusinessDbContext.Create()));
                    supplierProductService.UpsertProductsBySupplier(purchase);
                }
                scope.Complete();
            }

            UpdateProductReport(purchase);
            UpdateAccountReport(purchase);
            return(true);
        }
예제 #28
0
 public SmsHistoryQueryController() : base(new BaseService <SmsHistory, SmsHistoryRequestModel, SmsHistoryViewModel>(new BaseRepository <SmsHistory>(BusinessDbContext.Create())))
 {
 }
 public OperationLogQueryController() : base(new BaseService <M, Rm, Vm>(new BaseRepository <M>(BusinessDbContext.Create())))
 {
 }
예제 #30
0
 public MyShopController()
 {
     Service = new BaseService <Shop, ShopRequestModel, ShopSuperAdminViewModel>(new BaseRepository <Shop>(BusinessDbContext.Create()));
 }