コード例 #1
0
        public async Task CanUpdateTenant()
        {
            var client = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            //Init model
            var command = new UpdateTenantCommand
            {
                Id          = Guid.Parse("f3878709-3cba-4ed3-4c03-08d70375909d"),
                HostName    = "omega2",
                Name        = "test update",
                Description = "desc",
                UpdatedBy   = 1
            };

            var json = JsonConvert.SerializeObject(command);

            // The endpoint or route of the controller action.
            var httpResponse = await client.PutAsync("/Tenant", new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson));

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
コード例 #2
0
        public async Task <IActionResult> Put(Guid id, [FromBody] UpdateTenantCommand command)
        {
            command.Id = id;
            await _mediator.Send(command);

            return(Ok());
        }
コード例 #3
0
        public async Task <IActionResult> Edit(TenantDetailVM tenantDetailVM)
        {
            var updateTenantCommand = new UpdateTenantCommand()
            {
                TenantId     = tenantDetailVM.TenantId,
                Name         = tenantDetailVM.Name,
                DBConnection = tenantDetailVM.DBConnection
            };
            //var updateTenantCommand = _mapper.Map<UpdateTenantCommand>(tenantDetailVM);
            var tenant = await Mediator.Send(updateTenantCommand);

            return(RedirectToAction("List"));
        }
コード例 #4
0
        public async Task <IActionResult> Update(Guid id, UpdateTenantCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(View(command));
            }
            await Mediator.Send(command);

            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
        public async Task ShouldThrowErrorWhenInvalidInformation()
        {
            var command = new UpdateTenantCommand
            {
                Id          = _testTenantGuid,
                Name        = "TestTenant#02",
                HostName    = "localhost2",
                Description = "test desc",
                UpdatedBy   = 1,
                Logo        = new byte[] { 1 }
            };

            await Assert.ThrowsAsync <ObjectAlreadyExistsException>(async() =>
                                                                    await _commandHandler.Handle(command, CancellationToken.None));
        }
コード例 #6
0
        public async Task <IActionResult> Put([FromBody] UpdateTenantCommand command)
        {
            try
            {
                await _mediator.Send(command);

                return(Ok());
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound());
            }
            catch (ArgumentException argumentException)
            {
                return(BadRequest(argumentException.Message));
            }
        }
コード例 #7
0
        public async Task ShouldGetModelForValidInformation()
        {
            var command = new UpdateTenantCommand
            {
                Id          = _testTenantGuid,
                Name        = "testto1",
                HostName    = "localhost5",
                Description = "test desc",
                UpdatedBy   = 1,
                Logo        = new byte[] { 1 }
            };

            var tenantModel = await _commandHandler.Handle(command, CancellationToken.None);

            Assert.Null(tenantModel.Errors);

            Assert.Equal(command.Name, tenantModel.Items.Single().Name, ignoreCase: true);
        }
コード例 #8
0
        public async Task <bool> Handle(UpdateTenantCommand message, CancellationToken cancellationToken)
        {
            var tenant = await _repository.GetById(message.Id) ?? throw new KeyNotFoundException();

            tenant.UpdateInfos(message.Description, message.LogoUri);
            if (message.Enabled)
            {
                tenant.Enable();
            }
            else
            {
                tenant.Disable();
            }

            await _repository.SaveAsync(tenant);

            return(true);
        }
コード例 #9
0
        public async Task <bool> Handle(UpdateTenantCommand message, CancellationToken cancellationToken)
        {
            var tenant = await _repository.GetById(message.Id) ?? throw new NotFoundException();

            tenant.UpdateInfos(message.Description, message.LogoUri, message.EmailSignature);
            if (message.Enabled)
            {
                tenant.Enable();
            }
            else
            {
                tenant.Disable();
            }

            tenant.CreatedAt = DateTime.Now;
            tenant.UpdatedAt = DateTime.Now;
            tenant.CreatedBy = tenant.CreatedBy == Guid.Empty ? _identityService.GetUserIdentity() : tenant.CreatedBy;
            tenant.UpdatedBy = _identityService.GetUserIdentity();

            await _repository.SaveAsync(tenant);

            return(true);
        }
コード例 #10
0
ファイル: TenantController.cs プロジェクト: fossabot/honoplay
        public async Task <ActionResult <ResponseModel <UpdateTenantModel> > > Put([FromBody] UpdateTenantCommand command)
        {
            try
            {
                var userId = Claims[ClaimTypes.Sid].ToInt();
                command.UpdatedBy = userId;

                var updateTenantModel = await Mediator.Send(command);

                return(Ok(updateTenantModel));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <UpdateTenantModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }
コード例 #11
0
ファイル: TenantsController.cs プロジェクト: nminhduc/jarvis
        public async Task <IActionResult> PutAsync([FromRoute] Guid code, [FromBody] UpdateTenantCommand model)
        {
            var userCode   = _workContext.GetUserCode();
            var repoTenant = _uow.GetRepository <ITenantRepository>();
            var tenant     = await repoTenant.GetByCodeAsync(code);

            if (tenant == null)
            {
                return(NotFound());
            }

            if (tenant.IsEnable)
            {
                throw new Exception("Chi nhánh đã tạo đăng ký phát hành không thể sửa!");
            }

            var info = await repoTenant.GetInfoByCodeAsync(code);

            if (info == null)
            {
                return(NotFound());
            }

            if ((await repoTenant.QueryHostByHostNameAsync(model.HostName)).Any(x => x.Code != code))
            {
                throw new Exception("Tên miền đã bị trùng");
            }

            var hosts = await repoTenant.GetHostByCodeAsync(code);

            if (hosts.Count == 0)
            {
                return(NotFound());
            }

            var news = model.HostName.Split(';');

            var deletes = new List <TenantHost>();

            foreach (var item in hosts)
            {
                var delete = news.FirstOrDefault(x => x == item.HostName);
                if (delete == null)
                {
                    deletes.Add(item);
                }
            }

            var inserts = new List <TenantHost>();

            foreach (var item in news)
            {
                var insert = hosts.FirstOrDefault(x => x.HostName == item);
                if (insert == null)
                {
                    inserts.Add(new TenantHost
                    {
                        Code     = code,
                        HostName = item
                    });
                }
            }

            if (deletes.Count != 0)
            {
                repoTenant.DeleteHosts(deletes);

                //xóa cache
                foreach (var item in deletes)
                {
                    _cache.Remove($"TenantHost:{item.HostName}");
                }

                //xóa token của các tk trong chi nhánh này
                await DeleteTokenAsync(code);
            }

            if (inserts.Count != 0)
            {
                await repoTenant.InsertHostsAsync(inserts);
            }

            repoTenant.UpdateTenantFields(tenant,
                                          tenant.Set(x => x.Name, model.Info.TaxCode),
                                          tenant.Set(x => x.UpdatedAt, DateTime.Now),
                                          tenant.Set(x => x.UpdatedAtUtc, DateTime.UtcNow),
                                          tenant.Set(x => x.UpdatedBy, userCode));

            repoTenant.UpdateInfoFields(info,
                                        info.Set(x => x.TaxCode, model.Info.TaxCode),
                                        info.Set(x => x.FullNameVi, model.Info.FullNameVi),
                                        info.Set(x => x.Address, model.Info.Address));

            await _uow.CommitAsync();

            return(Ok());
        }