Exemplo n.º 1
0
        public async Task <AddTenantResultModel> AddTenant(TenantRequestModel requestModel)
        {
            var result = new AddTenantResultModel();

            var tenant = new Tenant()
            {
                Name     = requestModel.Name,
                HostName = requestModel.Domain,
                Theme    = requestModel.Theme
            };

            try
            {
                await _context.Tenants.AddAsync(tenant);

                await _context.SaveChangesAsync();

                var logo = await AddLogo(tenant.Id, requestModel.Logo);

                tenant.Logo = logo;

                _context.Tenants.Update(tenant);
                await _context.SaveChangesAsync();

                result.Success = true;
                result.Tenant  = tenant;
            }
            catch (Exception ex) {
                result.Success = false;
                result.Error   = $"Unhandled expection: {ex.Message}";
            }

            return(result);
        }
        public async Task <ActionResult <Tenant> > PostTenant(Tenant tenant)
        {
            _context.Tenants.Add(tenant);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTenant), new { id = tenant.Id }, tenant));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GenerateKeyPair([FromServices] IRsaKeyPairService rsaKeyPairService,
                                                          [FromServices] KeyPairAppService keyPairAppService, int?keyStrength = 2048)
        {
            if (!keyStrength.HasValue)
            {
                return(RedirectToAction(nameof(GenerateKeyPair), new { keyStrength = 2048 }));
            }

            var keyPair = rsaKeyPairService.GenerateRsaPrivateAndPublicKeyPair(keyStrength.Value);

            Regex regex         = new Regex(@"s/\x00//g;");
            var   keyPairEntity = new KeyPair()
            {
                AccountSysid = this.UserSession.UserSysId,
                TenantId     = this.UserSession.TenantId.Value,
                PrivateKey   = regex.Replace(CertificateUtil.ExportToByte(keyPair.Private).ConvertToBase64String(), string.Empty),
                PublicKey    = regex.Replace(CertificateUtil.ExportToByte(keyPair.Public).ConvertToBase64String(), string.Empty)
            };

            await keyPairAppService.InsertAsync(keyPairEntity);

            await _agileLabsDbContext.SaveChangesAsync();

            ViewBag.PrivateKey = CertificateUtil.ExportToByte(keyPair.Private).ConvertToUTF8String().Replace(Environment.NewLine, "<br/>");
            ViewBag.PublicKey  = CertificateUtil.ExportToByte(keyPair.Public).ConvertToUTF8String().Replace(Environment.NewLine, "<br/>");

            return(View());
        }
        public async Task <IActionResult> Create([FromServices] IDeviceCertificateService deviceCertificateService,
                                                 [FromServices] IRsaKeyPairService rsaKeyPairService,
                                                 [FromServices] KeyPairAppService keyPairAppService,
                                                 [Bind] CertificateSignRequestCreateViewModel model,
                                                 [Bind] Guid?keyPairSysid = null)
        {
            if (ModelState.IsValid)
            {
                var x509NameList = BUildNameList(model);

                if (!x509NameList.Any())
                {
                    throw new Exception("X509 Name can't be empty");
                }

                AsymmetricCipherKeyPair keyPair = null;
                if (keyPairSysid.HasValue)
                {
                    var keyPairEntity = tenantContext.KeyPairs.SingleOrDefault(x => x.Sysid == keyPairSysid.Value);
                    keyPair = CertificateUtil.ReadPrivateKey(keyPairEntity.PrivateKey.ConvertBase64ToUTF8());
                }
                else
                {
                    var keyPairEntity = keyPairAppService.GenerateKeyPair(out keyPair, model.CommonName);
                    keyPairSysid = keyPairEntity.Sysid;
                    await keyPairAppService.InsertAsync(keyPairEntity);
                }

                var x509Name = string.Join(", ", x509NameList);
                var sans     = new List <string> {
                    model.CommonName
                };
                var csr = deviceCertificateService.CreateCertificateSignRequest(keyPair.Public, x509Name, sans, keyPair.Private);

                var verifyResult = csr.Verify(keyPair.Public);

                var publicKey = csr.GetPublicKey();

                tenantContext.DeviceCertificates.Add(new DeviceCertificate
                {
                    Name         = model.CommonName,
                    SignRequest  = CertificateUtil.ExportToByte(csr).ConvertToBase64String(),
                    AccountSysid = this.UserSession.UserSysId,
                    KeyPairSysid = keyPairSysid.Value
                });
                await tenantContext.SaveChangesAsync();

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

            return(View(model));
        }
Exemplo n.º 5
0
        public void deleteRelJugadorAlianza(int id)
        {
            var rja = ctx.RelJugadorAlianza.
                      Where(w => w.id == id).SingleOrDefault();

            try
            {
                ctx.RelJugadorAlianza.Remove(rja);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void deleteAlianza(int id)
        {
            var alli = (from c in ctx.Alianza
                        where c.id == id
                        select c).SingleOrDefault();

            try
            {
                ctx.Alianza.Remove(alli);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        public void DeleteMapa(int id)
        {
            var mapaE = (from c in ctx.MapaNode
                         where c.id == id
                         select c).SingleOrDefault();

            try
            {
                ctx.MapaNode.Remove(mapaE);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void deleteConf(int id)
        {
            var u = (from c in ctx.Configuracion
                     where c.id == id
                     select c).SingleOrDefault();

            try
            {
                ctx.Configuracion.Remove(u);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 9
0
        public void deleteCosto(int id)
        {
            var cost = (from c in ctx.Costo
                        where c.Id == id
                        select c).SingleOrDefault();

            try
            {
                ctx.Costo.Remove(cost);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void deleteHistorialVentas(int idTmp)
        {
            var hv = (from c in ctx.HistorialVentas
                      where c.id == idTmp
                      select c).SingleOrDefault();

            try
            {
                ctx.HistorialVentas.Remove(hv);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void deleteRelJugadorRecurso(int id)
        {
            var rjr = (from c in ctx.RelJugadorRecurso
                       where c.id == id
                       select c).SingleOrDefault();

            try
            {
                ctx.RelJugadorRecurso.Remove(rjr);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 12
0
        public void deleteRelJugadorInvestigacion(int id)
        {
            var rji = (from c in ctx.RelJugadorInvestigacion
                       where c.id == id
                       select c).SingleOrDefault();

            try
            {
                ctx.RelJugadorInvestigacion.Remove(rji);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        public void deleteAdmin(string id)
        {
            var admE = (from c in ctx.Admin
                        where c.Id.Equals(id)
                        select c).SingleOrDefault();

            try
            {
                ctx.Admin.Remove(admE);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 14
0
        public void deleteProduce(int id)
        {
            var produce = (from c in ctx.Produce
                           where c.Id == id
                           select c).SingleOrDefault();

            try
            {
                ctx.Produce.Remove(produce);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 15
0
        public void deleteDependencia(int id)
        {
            var dep = (from c in ctx.Dependencia
                       where c.id == id
                       select c).SingleOrDefault();

            try
            {
                ctx.Dependencia.Remove(dep);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 16
0
        public void deleteDestacamento(int id)
        {
            var dest = (from c in ctx.Destacamento
                        where c.id == id
                        select c).SingleOrDefault();

            try
            {
                ctx.Destacamento.Remove(dest);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void deleteCapacidad(int id)
        {
            var capacity = (from c in ctx.Capacidad
                            where c.Id == id
                            select c).SingleOrDefault();

            try
            {
                ctx.Capacidad.Remove(capacity);
                ctx.SaveChangesAsync().Wait();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void deletePaquetePaypal(int id)
 {
     {
         var pp = (from c in ctx.PaquetePaypal
                   where c.id == id
                   select c).SingleOrDefault();
         try
         {
             ctx.PaquetePaypal.Remove(pp);
             ctx.SaveChangesAsync().Wait();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Exemplo n.º 19
0
        public void bajarNivel(int id)
        {
            try
            {
                var r = ctx.RelJugadorEdificio
                        .Where(w => w.id == id)
                        .SingleOrDefault();

                if (r != null)
                {
                    r.nivelE -= 1;
                    ctx.SaveChangesAsync().Wait();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> SignUp(Tenant model)
        {
            string stateMarker = Guid.NewGuid().ToString();

            model.Secret    = stateMarker;
            model.DtCreated = DateTime.UtcNow;
            m_db.Tenants.Add(model);
            await m_db.SaveChangesAsync();

            return(new RedirectResult(GenerateSignUpUri(stateMarker, model.IsAdmin)));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Create(UserVoice userVoice)
        {
            if (string.IsNullOrWhiteSpace(userVoice.Content))
            {
                _agileLabsDbContext.Add(userVoice);
                await _agileLabsDbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Thanks)));
            }
            return(View());
        }
        public Boolean updateRelJugadorDestacamento(RelJugadorDestacamento rje)
        {
            RelJugadorRecursoHandlerEF jrHandler = new RelJugadorRecursoHandlerEF(ctx);
            var relJMHandler = new RelJugadorMapaHandlerEF(ctx);

            try
            {
                var r = ctx.RelJugadorDestacamento
                        .Where(w => w.id == rje.id)
                        .SingleOrDefault();

                if (r != null)
                {
                    var dest = r.getShared();
                    var cant = rje.cantidad - r.cantidad;
                    if (!rje.getForceUpdate())
                    {
                        List <Entities.Costo> costos = r.destacamento.calCostoXNivel(0, cant);
                        Boolean compro = jrHandler.restarCompra(r.colonia.id, costos);
                        if (compro == false)
                        {
                            return(false);
                        }
                        DateTime ahora         = DateTime.Now;
                        TimeSpan tConstruccion = TimeSpan.FromSeconds(dest.destacamento.tiempoInicial * cant);
                        r.finalizaConstruccion = ahora.Add(tConstruccion);
                    }
                    else
                    {
                        r.cantidad = rje.cantidad;
                    }

                    ctx.SaveChangesAsync().Wait();
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 23
0
        public async Task <ActionResult <Tenant> > PostTenant(Tenant Tenant, int UserId)
        {
            _context.Tenant.Add(Tenant);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TenantExists(UserId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetTenant", new { UserId = Tenant.UserId }, Tenant));
        }
        public async Task <IActionResult> CreateRootCa(
            [Bind] RootCaCreateViewModel model,
            [FromServices] RootAuthorityAppService rootAuthorityAppService,
            [FromServices] TenantContext agileLabsDbContext)
        {
            if (ModelState.IsValid)
            {
                await rootAuthorityAppService.CreateRootCertificationAuthority(model.KeyPairSysid, model.Name);

                await _adminDbContext.SaveChangesAsync();

                await agileLabsDbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemplo n.º 25
0
        public async Task <IActionResult> CreateAuthority(Guid keyPairSysid)
        {
            var keyPair        = _tenantContext.KeyPairs.SingleOrDefault(x => x.Sysid == keyPairSysid);
            var publicKey      = CertificateUtil.ReadPublicKey(keyPair.PublicKey);
            var privateKeyPair = CertificateUtil.ReadPrivateKey(keyPair.PrivateKey);
            var rootCa         = _certificateAuthorityService.CreateRootCertificateAuthority(new X509Name("CN=AgileLabs Root Ca"), privateKeyPair, 12 * 1000);

            var certString = CertificateUtil.ExportToByte(rootCa, X509ContentType.Cert);
            CertificateAuthority certificateAuthority = new CertificateAuthority()
            {
                Certificate  = certString.ConvertToUTF8String(),
                KeyPairSysid = keyPairSysid
            };

            _tenantContext.CertificateAuthorities.Add(certificateAuthority);
            await _tenantContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 26
0
 /// <summary>
 /// This persists changes to data base.
 /// </summary>
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }