コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Image,UserId,TenantId,Status")] Goods goods)
        {
            if (ModelState.IsValid)
            {
                goods.UserId = 1;
                await _repository.CreateAsync(goods);

                await _unitOfWork.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["TenantId"] = new SelectList(_context.Tenant, "Id", "Id", goods.TenantId);
            //ViewData["UserId"] = new SelectList(_context.User, "Id", "Id", goods.UserId);
            return(View(goods));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,HostName,TenantType,Connection,TenantDbType,IsActive,IsDeleted,CreateTime,DeleteTime")] Tenant tenant)
        {
            if (ModelState.IsValid)
            {
                await _repository.CreateAsync(tenant);

                await _unitOfWork.SaveChangesAsync();

                if (tenant.TenantType == TenantType.钱租户)
                {
                    System.Console.WriteLine("开始创建数据库");
                    using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379"))
                    {
                        System.Console.WriteLine("发布消息");
                        ISubscriber sub = redis.GetSubscriber();
                        sub.Publish("createtenant", tenant.Connection);
                        System.Console.WriteLine("消息发布成功");
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tenant));
        }