Example #1
0
 public ActionResult RegisterTenant(string name, string surname)
 {
     _tenant.Name    = name;
     _tenant.Surname = surname;
     tenantRepository.Create(_tenant);
     return(RedirectToAction("Apartments"));
 }
        public TenantEditor CreateOrModify(string name)
        {
            var existing = repository.FindByName(name);

            if (existing == null)
            {
                Instance = repository.Create(new TenantResource
                {
                    Name = name,
                });
            }
            else
            {
                existing.Name = name;
                Instance      = repository.Modify(existing);
            }

            return(this);
        }
        public async Task <TenantEditor> CreateOrModify(string name)
        {
            var existing = await repository.FindByName(name).ConfigureAwait(false);

            if (existing == null)
            {
                Instance = await repository.Create(new TenantResource
                {
                    Name = name,
                }).ConfigureAwait(false);
            }
            else
            {
                existing.Name = name;
                Instance      = await repository.Modify(existing).ConfigureAwait(false);
            }

            return(this);
        }
Example #4
0
        public void Handle(RegisterTenant command)
        {
            var newId = 1111;

            var(tenant, userAccount, events) = Tenant.CreateAccount(newId,
                                                                    command.UserName, command.Password, command.Email);

            tenantRepository.Create(tenant);
            eventBus.Publish(events);
        }
        public async Task <ApiResponse> CreateTenant([FromBody] TenantViewModel createTenant)
        {
            try
            {
                await _tenantAppService.Create(new CreateTenantInput
                {
                    FirstName  = createTenant.FirstName,
                    LastName   = createTenant.LastName,
                    MiddleName = createTenant.MiddleName,
                    DOB        = Convert.ToDateTime(createTenant.DOB),
                    NickName   = createTenant.NickName,
                    GenderId   = createTenant.GenderId
                });

                return(new ApiResponse(HttpStatusCode.OK, null, "Tenant created successfully."));
            }
            catch (Exception ex)
            {
                return(new ApiResponse(HttpStatusCode.BadRequest, null, ex.InnerException.ToString()));
            }
        }
Example #6
0
        public List <IEvent> Register(Guid id, NewTenantCommand command)
        {
            var tenant = Tenant.Factory.Build(id, command);

            if (!tenant.IsValid())
            {
                this.Notify(tenant.Notifications);
                return(null);
            }

            var user = tenant.RegisterUser(command.Username, command.Password);

            //TODO : Criar mecanismo de transação
            _tenantRepository.Create(tenant);
            _userRepository.Create(user);

            return(new List <IEvent>
            {
                new TenantRegistered(tenant)
            });
        }
Example #7
0
        /// <summary>
        /// Create a new website from a template.
        /// </summary>
        /// <param name="templateTenantId">Identifies the template that will be used to create website.</param>
        /// <param name="web">New website details.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Newly allocated website identifier.</returns>
        public long Create(long templateTenantId, Web web, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one so that website creation tasks can all be rolled back in the case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                // Check that website (and domain) do not already exist and can be created
                _webValidator.ValidateCreate(web);

                // Get template that determines initial website structure
                Template template = _templateRepository.Read(templateTenantId, true, unitOfWork ?? localUnitOfWork);

                // Get tenant identifier for new website
                DateTime now    = DateTime.UtcNow;
                Tenant   tenant = new Tenant {
                    Created = now, Updated = now
                };
                web.TenantId = _tenantRepository.Create(tenant, unitOfWork ?? localUnitOfWork);

                // Populate web from template
                web.CreateUserEnabled            = template.CreateUserEnabled;
                web.UserHasImage                 = template.UserHasImage;
                web.UserThumbnailImageWidth      = template.UserThumbnailImageWidth;
                web.UserThumbnailImageHeight     = template.UserThumbnailImageHeight;
                web.UserThumbnailImageResizeMode = template.UserThumbnailImageResizeMode;
                web.UserPreviewImageWidth        = template.UserPreviewImageWidth;
                web.UserPreviewImageHeight       = template.UserPreviewImageHeight;
                web.UserPreviewImageResizeMode   = template.UserPreviewImageResizeMode;
                web.UserImageMinWidth            = template.UserImageMinWidth;
                web.UserImageMinHeight           = template.UserImageMinHeight;

                // Create web
                _webRepository.Create(web, unitOfWork ?? localUnitOfWork);

                // Create domain
                web.Domains[0].TenantId = web.TenantId;
                long domainId = _domainRepository.Create(web.Domains[0], unitOfWork ?? localUnitOfWork);

                // Build website based on template
                Dictionary <ElementKeyValue, ElementKeyValue> templateElements = new Dictionary <ElementKeyValue, ElementKeyValue>();
                List <Page> navigationPages = new List <Page>();
                Page        page            = new Page {
                    TenantId = web.TenantId
                };
                BuildWebsite(web.TenantId, page, template.Page, templateElements, navigationPages, unitOfWork ?? localUnitOfWork);

                // Update navigation elements with navigation pages
                _elementService.AddNavigationPages(web.TenantId, templateElements.Select(kvp => kvp.Value).ToList(), navigationPages, unitOfWork ?? localUnitOfWork);

                // Commit work if local unit of work in place, then return newly allocated website identifier
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
                return(web.TenantId);
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
 public async Task <Guid> Create(Tenant newTenantBo)
 {
     return(await _tenantRepository.Create(newTenantBo));
 }