Пример #1
0
 public int CreateInteraction(Interaction shared)
 {
     DALayer.Entities.Interaction data = InteractionHandler.SharedToData(shared);
     ctx.Interaction.Add(data);
     ctx.SaveChanges();
     return(data.Id);
 }
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,UnitNumber,AptName,Reason,PhonNum,Permission,DateReq")] Tenant tenant)
        {
            if (ModelState.IsValid)
            {
                db.Tenants.Add(tenant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tenant));
        }
Пример #3
0
        public ActionResult RequestForm([Bind(Include = "ID, FirstName, LastName, PhoneNumber, ApartmentName, UnitNumber, Description, Checkbox, Received")] Tenant tenant)
        {
            if (ModelState.IsValid) //Are required fields filled out?
            {
                //adds form infomation to database
                db.Tenants.Add(tenant);
                db.SaveChanges();
                return(RedirectToAction("ViewForms"));
            }

            return(View(tenant));
        }
 public ViewResult TenantView([Bind(Include = "ID,FirstName,LastName,PhoneNumber,ApartmentName,ApartmentNumber,FixDescription")] Tenant tenant)
 {
     if (ModelState.IsValid)              // Check to see if the model is valid
     {
         tc.Tenants.Add(tenant);          // If model is valid, add the tenant form information into the database
         tc.SaveChanges();                // Save the changes to the database
         return(View("Thanks", tenant));  // Return the tenant's name on a "thank you" page
     }
     else
     {
         return(View(tenant));             // If model is invalid, validation issue and just return tenant information
     }
 }
Пример #5
0
        public void createRelJugadorInvestigacion(RelJugadorInvestigacion r)
        {
            var col = ctx.RelJugadorMapa.Where(w => w.id == r.colonia.id).SingleOrDefault();
            var inv = ctx.Investigacion.Where(w => w.id == r.investigacion.id).SingleOrDefault();

            List <Entities.Costo> cos = new List <Entities.Costo>();

            foreach (var item in r.investigacion.costos)
            {
                var rec  = ctx.Recurso.Where(w => w.id == item.recurso.id).SingleOrDefault();
                var prod = ctx.Producto.Where(w => w.id == item.idProducto).SingleOrDefault();
                var c    = new Entities.Costo(rec, prod, item.valor, item.incrementoNivel);
                cos.Add(c);
            }

            Entities.RelJugadorInvestigacion rji = new Entities.RelJugadorInvestigacion(col, inv, r.nivel, r.finalizaConstruccion);

            try
            {
                ctx.RelJugadorInvestigacion.Add(rji);

                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #6
0
        public int createDestacamento(Destacamento d)
        {
            Entities.Destacamento desE = new Entities.Destacamento(d.nombre, d.descripcion, d.foto, d.ataque, d.escudo,
                                                                   d.efectividadAtaque, d.vida, d.velocidad, d.enMision, d.tiempoInicial, d.incrementoTiempo);
            try
            {
                ctx.Database.Connection.Open();
                ctx.Destacamento.Add(desE);
                ctx.SaveChanges();

                Entities.Destacamento des = ctx.Destacamento.ToList().LastOrDefault();

                ctx.Database.Connection.Close();

                return(des.id);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #7
0
        public void registerLogin(string id)
        {
            Entities.ActividadJugador j = ctx.ActividadJugador.Where(c => c.UserId.Equals(id)).OrderByDescending(c => c.CreatedDate).FirstOrDefault();

            if (j == null || j.CreatedDate.Date.CompareTo(DateTime.Now.Date) != 0)
            {
                ctx.ActividadJugador.Add(new Entities.ActividadJugador {
                    UserId = id, CreatedDate = DateTime.Now, tipo = "login"
                });
                ctx.SaveChanges();
            }
        }
 public void createConf(Configuracion conf)
 {
     Entities.Configuracion u = new Entities.Configuracion(conf.css, conf.nombre, conf.titulo, conf.idAppFace, conf.claveAppFace);
     try
     {
         ctx.Configuracion.Add(u);
         ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void createRecurso(Recurso r)
 {
     Entities.Recurso rec = new Entities.Recurso(r.nombre, r.descripcion, r.cantInicial, r.capacidadInicial, r.produccionXTiempo, r.foto);
     try
     {
         ctx.Recurso.Add(rec);
         ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #10
0
        //public IActionResult ProcessCode(string code, string error, string error_description, string resource, string state)
        public async Task <IActionResult> ProcessCode(OnboardingModel model)
        {
            //Find Tenant based on tenant guid
            var t = m_db.Tenants.FirstOrDefault(p => p.Secret == model.state);

            if (t != null)
            {
                var authContext = new AuthenticationContext($"{m_aadOptions.AzureAdInstance}"); //MT
                var creds       = new ClientCredential(m_aadOptions.ClientId, m_aadOptions.ClientSecret);
                var redirectUri = new Uri($"{m_aadOptions.Domain}/MT/ProcessCode");
                var authResult  = await authContext.AcquireTokenByAuthorizationCodeAsync(
                    model.code, redirectUri, creds,
                    "https://graph.microsoft.com/");

                //Do we already registered that tenant?
                if (m_db.Tenants.FirstOrDefault(p => p.TenantGuid == authResult.TenantId.ToLower()) == null)
                {
                    t.TenantGuid = authResult.TenantId.ToLower();
                }
                else
                {
                    m_db.Tenants.Remove(t);
                }
                m_db.SaveChanges();
            } //Else - wrong secret
            //Clean old
            var old = m_db.Tenants.Where(p => p.TenantGuid == "" && p.DtCreated < DateTime.UtcNow.AddMinutes(-5));

            if (old.Count() > 0)
            {
                foreach (var item in old)
                {
                    m_db.Tenants.Remove(item);
                }
                m_db.SaveChanges();
            }
            return(View(model));
        }
        public TenantController(TenantContext context)
        {
            _context = context;

            if (_context.Tenants.Count() == 0)
            {
                // Create a new Tenant if collection is empty,
                // which means you can't delete all Tenants.
                _context.Tenants.Add(new Tenant {
                    Name = "Tenant1"
                });
                _context.SaveChanges();
            }
        }
Пример #12
0
        public void CreateMapa(MapaNode m)
        {
            var mapaE = new Entities.MapaNode(m.nombre, m.nivel, m.cantidad, m.distance);

            try
            {
                ctx.MapaNode.Add(mapaE);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void createRelJugadorMapa(RelJugadorMapa r)
        {
            var j   = ctx.Jugador.Where(w => w.Id == r.jugador.id).SingleOrDefault();
            var rel = new Entities.RelJugadorMapa(r.nivel1, r.nivel2, r.nivel3, r.nivel4, r.nivel5, r.coord, j);

            try
            {
                ctx.RelJugadorMapa.Add(rel);
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #14
0
 public void createCosto(Costo c)
 {
     try
     {
         Entities.Recurso rec = ctx.Recurso.Where(w => w.id == c.recurso.id).SingleOrDefault();
         var prod             = ctx.Producto.Where(w => w.id == c.idProducto).SingleOrDefault();
         var cost             = new Entities.Costo(rec, prod, c.valor, c.incrementoNivel);
         ctx.Costo.Add(cost);
         ctx.SaveChanges();
         ctx.Database.Connection.Close();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #15
0
        public void createAlianza(Alianza a)
        {
            var admin = ctx.Jugador.Where(w => w.Id == a.administrador.id).SingleOrDefault();

            Entities.Alianza alli = new Entities.Alianza(a.nombre, a.descripcion, a.foto, admin);

            try
            {
                ctx.Alianza.Add(alli);
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #16
0
 public void createProduce(Produce p)
 {
     try
     {
         ctx.Database.Connection.Open();
         Entities.Recurso rec = ctx.Recurso.Where(w => w.id == p.recurso.id).SingleOrDefault();
         var prod             = ctx.Producto.Where(w => w.id == p.idProducto).SingleOrDefault();
         var produce          = new Entities.Produce(rec, prod, p.valor, p.incrementoNivel);
         ctx.Produce.Add(produce);
         ctx.SaveChanges();
         ctx.Database.Connection.Close();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void createRelJugadorRecurso(RelJugadorRecurso r)
        {
            var rec = ctx.Recurso.Where(w => w.id == r.recurso.id).SingleOrDefault();
            var col = ctx.RelJugadorMapa.Where(w => w.id == r.colonia.id).SingleOrDefault();

            var rjr = new Entities.RelJugadorRecurso(rec, col, r.capacidad, r.cantidadR, r.produccionXTiempo, r.ultimaConsulta);

            try
            {
                ctx.RelJugadorRecurso.Add(rjr);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #18
0
        public void createRelJugadorAlianza(RelJugadorAlianza r)
        {
            var ali = ctx.Alianza.Where(w => w.id == r.alianza.id).SingleOrDefault();
            var mie = ctx.Jugador.Where(w => w.Id == r.miembro.id).SingleOrDefault();

            Entities.RelJugadorAlianza rja = new Entities.RelJugadorAlianza(ali, mie, r.activo);

            try
            {
                ctx.RelJugadorAlianza.Add(rja);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void createCapacidad(Capacidad c)
 {
     try
     {
         ctx.Database.Connection.Open();
         Entities.Recurso recurso = ctx.Recurso.Where(w => w.id == c.recurso.id).SingleOrDefault();
         var producto             = ctx.Producto.Where(w => w.id == c.idProducto).SingleOrDefault();
         var capacity             = new Entities.Capacidad(recurso, producto, c.valor, c.incrementoNivel);
         ctx.Capacidad.Add(capacity);
         ctx.SaveChanges();
         ctx.Database.Connection.Close();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #20
0
        public void createRelJugadorEdificio(RelJugadorEdificio r)
        {
            var col = ctx.RelJugadorMapa.Where(w => w.id == r.colonia.id).SingleOrDefault();
            var ed  = ctx.Edificio.Where(w => w.id == r.edificio.id).SingleOrDefault();

            var rje = new Entities.RelJugadorEdificio(col, ed, r.nivelE, r.finalizaConstruccion);

            try
            {
                ctx.RelJugadorEdificio.Add(rje);

                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void createHistorialVentas(HistorialVentas hvTmp)
        {
            Entities.HistorialVentas hv = new Entities.HistorialVentas();

            hv.idusuario    = hvTmp.idusuario;
            hv.nombreOferta = hvTmp.nombreOferta;
            hv.fechaCompra  = hvTmp.fechaCompra;

            try
            {
                ctx.HistorialVentas.Add(hv);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #22
0
        public int createInvestigacion(Investigacion i)
        {
            var inv = new Entities.Investigacion(i.nombre, i.descripcion, i.foto, i.tiempoInicial, i.incrementoTiempo);

            try
            {
                ctx.Investigacion.Add(inv);
                ctx.SaveChanges();

                Entities.Investigacion invs = ctx.Investigacion.ToList().LastOrDefault();

                return(invs.id);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void createPaquetePaypal(PaquetePaypal ppTmp)
        {
            Entities.PaquetePaypal pp = new Entities.PaquetePaypal();
            pp.nombreOferta = ppTmp.nombreOferta;
            pp.producto     = ppTmp.producto;
            pp.cantidad     = ppTmp.cantidad;
            pp.precio       = ppTmp.precio;
            pp.ofertaActiva = ppTmp.ofertaActiva;


            try
            {
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #24
0
        public void createDependencia(Dependencia d)
        {
            var padre = (from c in ctx.Producto
                         where c.id == d.padreId
                         select c).SingleOrDefault();
            var hijo = (from c in ctx.Producto
                        where c.id == d.hijoId
                        select c).SingleOrDefault();

            Entities.Dependencia dep = new Entities.Dependencia(padre, hijo, d.nivel);

            try
            {
                ctx.Dependencia.Add(dep);
                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void createRelJugadorDestacamento(RelJugadorDestacamento r)
        {
            CostoHandlerEF cosoH = new CostoHandlerEF(ctx);
            var            col   = ctx.RelJugadorMapa.Where(w => w.id == r.colonia.id).SingleOrDefault();
            var            des   = ctx.Destacamento.Where(w => w.id == r.destacamento.id).SingleOrDefault();

            List <Entities.Costo> cos = new List <Entities.Costo>();

            foreach (var item in r.destacamento.costos)
            {
                var rec  = ctx.Recurso.Where(w => w.id == item.recurso.id).SingleOrDefault();
                var prod = ctx.Producto.Where(w => w.id == item.idProducto).SingleOrDefault();
                var c    = new Entities.Costo(rec, prod, item.valor, item.incrementoNivel);
                cos.Add(c);
            }
            List <Entities.Capacidad> cap = new List <Entities.Capacidad>();

            foreach (var item in r.destacamento.capacidad)
            {
                var rec  = ctx.Recurso.Where(w => w.id == item.recurso.id).SingleOrDefault();
                var prod = ctx.Producto.Where(w => w.id == item.idProducto).SingleOrDefault();
                var c    = new Entities.Capacidad(rec, prod, item.valor, item.incrementoNivel);
                cap.Add(c);
            }

            var rje = new Entities.RelJugadorDestacamento(col, des, r.cantidad, r.finalizaConstruccion);

            try
            {
                ctx.RelJugadorDestacamento.Add(rje);

                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #26
0
 public bool addEntity(Tenant newTenant)
 {
     if (_context.Tenants.Where(c => c.SubDomainName == newTenant.SubDomainName).Count() == 0)
     {
         _context.Add(newTenant);
         saveAll();
         string connectionString = null;
         try
         {
             connectionString = onTenantEntry(newTenant);
         }
         catch (Exception ex)
         {
             connectionString = null;
         }
         try
         {
             if (connectionString != null)
             {
                 var dbContextOptionsBuilder = new DbContextOptionsBuilder <TenantContext>();
                 dbContextOptionsBuilder.UseNpgsql(_configuration.GetConnectionString("DefaultConnectionString"));
                 TenantContext tenantContext_temp = new TenantContext(dbContextOptionsBuilder.Options);
                 Tenant        recent_tenant      = tenantContext_temp.Tenants.Last();
                 recent_tenant.ConnectionStringName = connectionString;
                 tenantContext_temp.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             return(false);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #27
0
        public static void Initialize(TenantContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Tenants.Any())
            {
                return;   // DB has been seeded
            }

            var tenants = new Tenant[]
            {
                new Tenant {
                    FullName = "Doctor Aged Care", CustomerCode = "DAC", DnsName = "dac.helix.medicaldirector.com", SubscriptionCode = "MD"
                },
            };

            foreach (Tenant s in tenants)
            {
                context.Tenants.Add(s);
            }
            context.SaveChanges();
        }
Пример #28
0
        internal void SeedDeaultTenant(long tenantId, TenantContext context)
        {
            var tenant = new Tenant()
            {
                Id = tenantId,
                Name="ApexVox"
            };

            if(!context.Tenants.Any(x=>x.Id == tenantId))
            {
                context.Database.OpenConnection();
                try
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Tenants ON");
                    context.Tenants.Add(tenant);
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Tenants OFF");
                }
                finally
                {
                    context.Database.CloseConnection();
                }
            }
        }
Пример #29
0
        public async Task <TwiMLResult> SmsWebhook(SmsRequest request, int numMedia)
        {
            // Is this number in our database?

            var accountsRef   = _db.Collection("accounts");
            var query         = accountsRef.WhereEqualTo("PhoneNumber", request.From);
            var querySnapshot = await query.GetSnapshotAsync();

            DocumentSnapshot?document;

            if (querySnapshot.Count == 0)
            {
                await accountsRef.Document(Guid.NewGuid().ToString())
                .SetAsync(new Dictionary <string, object>()
                {
                    { "PhoneNumber", request.From }
                });

                var snapshot = await query.GetSnapshotAsync();

                document = snapshot.Documents[0];
            }
            else
            {
                document = querySnapshot.Documents[0];
            }

            // Save the message body if there is one
            if (request.Body != null)
            {
                await document.Reference.UpdateAsync("Messages", FieldValue.ArrayUnion(new Dictionary <string, object>()
                {
                    { "Text", request.Body },
                    { "Timestamp", Timestamp.GetCurrentTimestamp() }
                }));
            }


            var filenames = await SaveMedia(numMedia);


            var phone = _context.Phones.FirstOrDefault(x => x.PhoneNumber == request.From);

            if (phone == null)
            {
                phone = new Phone
                {
                    PhoneNumber = request.From,
                    Images      = new List <Models.Image>()
                };
                _context.Phones.Add(phone);
            }

            foreach (var(image, thumbnail) in filenames)
            {
                if (phone.Images == null)
                {
                    phone.Images = new List <Models.Image>();
                }
                phone.Images.Add(new Models.Image
                {
                    Name          = image,
                    ThumbnailName = thumbnail
                });
            }

            _context.SaveChanges();

            var response    = new MessagingResponse();
            var messageBody = numMedia == 0 ? "Send us an image!" :
                              $"Thanks for sending us {numMedia} file(s)!";

            response.Message(messageBody);
            return(TwiML(response));
        }
Пример #30
0
 public void Add(Portfolio portfolio)
 {
     _context.Add(portfolio);
     _context.SaveChanges();
 }