public async Task <IActionResult> Create(EnvironmentModel model)
        {
            Environment environment = new Environment();

            new EnvironmentModelAssembler().Apply(environment, model);
            environment.Index = await _domainContext.Environments.GetNextIndex();

            await Validate(environment);

            if (model == null || ModelState.IsValid == false)
            {
                return(View("Edit", model));
            }

            _domainContext.Environments.Save(environment);
            await _domainContext.SaveAsync();

            return(RedirectToAction("Edit", "Environments", new { id = environment.Id }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(VariableModel model)
        {
            Variable variable = new Variable();

            new VariableModelAssembler().ApplyModel(
                model,
                variable,
                await _domainContext.Environments.GetAll());

            await Validate(variable);

            if (model == null || ModelState.IsValid == false)
            {
                return(View("Edit", model));
            }

            _domainContext.Variables.Save(variable);
            await _domainContext.SaveAsync();

            return(RedirectToAction("Edit", "Variables", new { id = variable.Id }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(int?id, ItemEditModel model)
        {
            if (model == null || ModelState.IsValid == false)
            {
                return(View("Edit", model));
            }

            var duplicateItem = await _domainContext.Items.GetByName(model.Name);

            if (duplicateItem != null)
            {
                ModelState.AddModelError("Name", string.Format("Item with the name '{0}' already exists.", model.Name));
                return(View("Edit", model));
            }

            Item item = new Item();

            new ItemEditModelAssembler().ApplayModel(item, model);
            _domainContext.Items.Save(item);
            await _domainContext.SaveAsync();

            return(RedirectToAction("Edit", new { id = item.Id }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            var tenant = await _domainContext.Tenants.Get(model.Name);

            if (tenant != null)
            {
                ModelState.AddModelError("Name", "Name is already taken.");
                return(View(model));
            }

            using (var scope = await _domainContext.BeginTransaction())
            {
                tenant    = new Tenant();
                tenant.Id = model.Name;
                _domainContext.Tenants.Save(tenant);

                ApplicationUser user = new ApplicationUser();
                user.UserName           = model.Email;
                user.NormalizedUserName = model.Email.ToUpper();
                user.Email           = model.Email;
                user.NormalizedEmail = model.Email.ToUpper();
                user.PasswordHash    = _passwordHasher.HashPassword(user, model.Password);
                user.SecurityStamp   = Guid.NewGuid().ToString();
                _domainContext.Users.Save(user, model.Name);
                await _domainContext.SaveAsync();

                scope.Commit();
            }

            StringBuilder body = new StringBuilder();

            body.Append("Thank you for registering.<br/><br/>");
            body.AppendFormat("The url of your console is <a href=\"{0}\">{0}</a>.<br/>", _urlService.GetUrlWithTenant(model.Name));
            await _emailService.SendEmailAsync(
                model.Email,
                "Thank you for registering",
                body.ToString());

            return(this.RedirectToAction("RegistrationConfirmation", new { tenant = model.Name }));
        }