Пример #1
0
        public void addCharacter(Character character)
        {
            character.id = Guid.NewGuid();
            _dbContext.Characters.Add(character);

            _dbContext.SaveChanges();
        }
Пример #2
0
        public T Add(T entity)
        {
            _dbContext.Set <T>().Add(entity);
            _dbContext.SaveChanges();

            return(entity);
        }
Пример #3
0
 public void Add(Item item)
 {
     if (!_context.Items.Contains(item))
     {
         _context.Items.Add(item);
         _context.SaveChanges();
     }
 }
        public NetworkAdapter Add(NetworkAdapter model)
        {
            var netAdaptor = _myDbContext.NetworkAdapters.FirstOrDefault(f => f.AdapterId == model.AdapterId);

            if (netAdaptor is null)
            {
                var result = _myDbContext.NetworkAdapters.Add(model);
                _myDbContext.SaveChanges();
                return(result);
            }
            return(model);
        }
Пример #5
0
        public JsonResult Insert()
        {
            Category entity = new Category
            {
                Name = "Harry Cheng",
                Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                Guid = Guid.NewGuid().ToString("N"),
            };

            dbContext.Set <Category>().Add(entity);
            dbContext.SaveChanges();
            return(Json(entity));
        }
        private static void PruebaDeConexionABaseDeDatosSqlite()
        {
            Console.WriteLine("Conectando a la base de datos...");
            using (var db = new SqliteDbContext())
            {
                // db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
                var usuario = new User()
                {
                    Name      = "bidkar",
                    Password  = "******",
                    FirstName = "Bidkar",
                    LastName  = "Aragon",
                    Email     = "*****@*****.**",
                    Status    = UserStatus.Active
                };
                // Create (insert)
                db.Add(usuario);
                db.SaveChanges();

                // Read (select)
                var usuarios = db.Users;
                foreach (var u in usuarios)
                {
                    Console.WriteLine("Usuario: " + u.Name);
                }
            }
        }
        private static void InsertarUsuarioPorConsola()
        {
            var usuario = new User();

            Console.WriteLine("Escribe los siguientes datos");
            Console.Write("Nombre de usuario: ");
            usuario.Name = Console.ReadLine();
            Console.Write("Contraseña: ");
            usuario.Password = Console.ReadLine();
            Console.Write("Nombre de pila: ");
            usuario.FirstName = Console.ReadLine();
            Console.Write("Apellidos: ");
            usuario.LastName = Console.ReadLine();
            Console.Write("Correo electrónico: ");
            usuario.Email = Console.ReadLine();
            Console.WriteLine($"Rol del usuario: {Role.ToStringList()}");
            usuario.RoleId = int.Parse(Console.ReadLine());
            using (var db = new SqliteDbContext())
            {
                db.Add(usuario);
                db.SaveChanges();
                ImprimirUsuarios();
                Console.WriteLine($"El id asignado al usuario {usuario.Name} es {usuario.Id}");
            }
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="isSave">isSave 无效</param>
        /// <returns></returns>
        public static OpResult AddRange(List <TEntity> entities, bool isSave = true)
        {
            var op = new OpResult();

            SqliteTrap.PushAction <TEntity>(new Action <IEnumerable <TEntity> >((o1) =>
            {
                try
                {
                    using (var context = new SqliteDbContext())
                    {
                        try
                        {
                            context.Set <TEntity>().AddRange(o1.ToList());
                            context.SaveChanges();
                        }
                        catch { }
                        finally
                        {
                            //One of the following two is enough
                            context.Database.Connection.Close();
                            context.Database.Connection.Dispose(); //THIS OR
                            ContextFactory.GetCurrentContext <SqliteDbContext>(true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    File.AppendAllText("Log.txt", ex.Message + "|" + ex.StackTrace, Encoding.UTF8);

                    //  Log.WriteError(ex);
                }
            }), entities);
            op.Successed = true;
            return(op);
        }
 public void Add(ProductModel entity)
 {
     using (var db = new SqliteDbContext())
     {
         db.Products.Add(entity);
         db.SaveChanges();
     }
 }
Пример #10
0
        public IActionResult PostMachine([FromBody] Machine machineData)
        {
            _dbContext.tMachine.Add(machineData);
            int res = _dbContext.SaveChanges();

            if (res > 0)
            {
                return(Ok(machineData));
            }
            return(BadRequest());
        }
Пример #11
0
        static void Main(string[] args)
        {
            using (var item = new SqliteDbContext("asdf"))
            {
                item.Group.Add(new Model.Group {
                    Course = 1, Name = "p2as", Size = 12, Lessons = null, Students = null
                });

                item.SaveChanges();
            }
            Console.WriteLine("Hello World!");
        }
Пример #12
0
 public IActionResult Nuevo(Alumno alumno)
 {
     if (alumno != null && ModelState.IsValid)
     {
         using (var db = new SqliteDbContext())
         {
             db.Add(alumno);
             db.SaveChanges();
         }
     }
     return(View("Index"));
 }
Пример #13
0
 public IActionResult Eliminar(int id)
 {
     using (var db = new SqliteDbContext())
     {
         var alumno = db.Alumnos.Find(id);
         if (alumno != null)
         {
             db.Remove(alumno);
             db.SaveChanges();
         }
     }
     return(View("Index"));
 }
Пример #14
0
        public IActionResult Save(PacienteViewModel paciente)
        {
            if (paciente != null && ModelState.IsValid)
            {
                using (var db = new SqliteDbContext())
                {
                    db.Add(paciente);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult Nueva(Carrera carrera)
        {
            using (var db = new SqliteDbContext())
            {
                if (ModelState.IsValid)
                {
                    db.Add(carrera);
                    db.SaveChanges();
                }

                return(View("Index"));
            }
        }
Пример #16
0
        internal static void Initialize(IServiceProvider services)
        {
            using (var context = new SqliteDbContext(services.GetRequiredService <DbContextOptions <SqliteDbContext> >()))
            {
                if (!context.Manufacturers.Any())
                {
                    context.Manufacturers.AddRange(
                        new VehicleManufacturer
                    {
                        Name        = "Honda",
                        Description = "A Japanese car manufacturer.....",
                        Models      = GenerateFakeModels()
                    },
                        new VehicleManufacturer
                    {
                        Name        = "Nissan",
                        Description = "Nissan makes a variety of sport compact cars",
                        Models      = new List <VehicleModel>
                        {
                            new VehicleModel
                            {
                                Name = "240SX"
                            },
                            new VehicleModel
                            {
                                Name = "300ZX"
                            }
                        }
                    },
                        new VehicleManufacturer
                    {
                        Name        = "Toyota",
                        Description = "Toyota was formed a long, long time ago...",
                        Models      = new List <VehicleModel>
                        {
                            new VehicleModel
                            {
                                Name = "Supra"
                            },
                            new VehicleModel
                            {
                                Name = "Celica"
                            }
                        }
                    }
                        );

                    context.SaveChanges();
                }
            }
        }
 public void Add(Enemy item)
 {
     if (!_context.Enemies.Contains(item))
     {
         _context.Enemies.Add(item);
         _context.SaveChanges();
     }
 }
Пример #18
0
        public IActionResult Delete(int id)
        {
            if (id > 0)
            {
                using (var db = new SqliteDbContext())
                {
                    var paciente = db.Pacientes.Find(id);
                    db.Remove(paciente);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult Eliminar(int id)
        {
            using (var db = new SqliteDbContext())
            {
                var carrera = db.Carreras.Find(id);
                if (carrera != null)
                {
                    db.Remove(carrera);
                    db.SaveChanges();
                }

                return(View("Index"));
            }
        }
        public IActionResult Editar(int id, Carrera carreraInput)
        {
            using (var db = new SqliteDbContext())
            {
                var carrera = db.Carreras.Find(id);
                if (carrera != null && ModelState.IsValid)
                {
                    carrera.Nombre = carreraInput.Nombre;
                    carrera.Plan   = carreraInput.Plan;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
        }
Пример #21
0
        public void AddDeputy(Deputy deputy)
        {
            using (SqliteDbContext context = new SqliteDbContext())
            {
                context.Deputies.Add(deputy);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
Пример #22
0
 public IActionResult Editar(int id, Alumno alumnoCambios)
 {
     using (var db = new SqliteDbContext())
     {
         var alumno = db.Alumnos.Find(id);
         if (alumno != null && ModelState.IsValid)
         {
             alumno.Matricula         = alumnoCambios.Matricula;
             alumno.Nombre            = alumnoCambios.Nombre;
             alumno.Apellidos         = alumnoCambios.Apellidos;
             alumno.CorreoElectronico = alumnoCambios.CorreoElectronico;
             alumno.Genero            = alumnoCambios.Genero;
             alumno.CarreraId         = alumnoCambios.CarreraId;
             db.SaveChanges();
         }
     }
     return(View("Index"));
 }
Пример #23
0
 public IActionResult Edit(int id, PacienteViewModel paciente)
 {
     if (ModelState.IsValid && id > 0)
     {
         using (var db = new SqliteDbContext())
         {
             var pacienteExistente = db.Pacientes.Find(id);
             if (pacienteExistente != null)
             {
                 pacienteExistente.Nombre    = paciente.Nombre;
                 pacienteExistente.Apellidos = paciente.Apellidos;
                 pacienteExistente.Edad      = paciente.Edad;
                 pacienteExistente.Genero    = paciente.Genero;
                 db.SaveChanges();
             }
         }
     }
     return(RedirectToAction("Index"));
 }
Пример #24
0
        private const int _thresholdValue = 500; // = (_MaxAmount - _MinAmount) * 0.75 + _MinAmount;

        #endregion


        #region Fields

        #endregion


        #region Properties

        #endregion


        #region ClassLifeCycles

        public SqliteReputationServices(SqliteDbContext context)
        {
            _context = context;

            if (!_context.Reputations.Any())
            {
                _context.Reputations.Add(new Reputation
                {
                    Peasants = 0,
                    Church   = 0,
                    Bandits  = 0,
                    Nobles   = 0
                });

                _context.SaveChanges();
            }

            CorrectReputation();
        }
        private static void InsertarMultiplesRegistros()
        {
            var usuarios = new List <User>()
            {
                new User {
                    Name      = "lilian",
                    Password  = "******",
                    FirstName = "Lilian Estefania",
                    LastName  = "Aragon Urias",
                    Email     = "lilian@aragon",
                    Status    = UserStatus.Active
                },
                new User {
                    Name      = "laura",
                    Password  = "******",
                    FirstName = "Laura",
                    LastName  = "No esta",
                    Email     = "laura@sefue",
                    Status    = UserStatus.Active
                }
            };

            usuarios.Add(
                new User
            {
                Name      = "luis",
                Password  = "******",
                FirstName = "Jose Luis",
                LastName  = "Si esta",
                Email     = "jluis@nosefue",
                Status    = UserStatus.Active
            }
                );

            // Guardar los usuarios creados anteriormente
            using (var db = new SqliteDbContext())
            {
                db.AddRange(usuarios);
                db.SaveChanges();
                ImprimirUsuarios();
            }
        }
Пример #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            Scraper.Scraper scrapper = new Scraper.Scraper();
            scrapper.ScrapeDataOfVote("https://www.sejm.gov.pl/sejm9.nsf/agent.xsp?symbol=klubglos&IdGlosowania=54381&KodKlubu=PiS");

            using (var dbContext = new SqliteDbContext())
            {
                dbContext.Database.ExecuteSqlCommand("DELETE FROM DEPUTIES");

                foreach (var dep in scrapper.Deputies)
                {
                    Deputy en = new Deputy();
                    {
                        en.Name           = dep.Name;
                        en.PoliticalParty = dep.PoliticalParty;
                    }
                    dbContext.Deputies.Add(en);
                }

                dbContext.SaveChanges();
            }
        }
Пример #27
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxName.Text) && string.IsNullOrEmpty(textBoxLastName.Text))
            {
                MessageBox.Show("Podaj Imie i Nazwisko Posła");
            }
            else
            {
                using (var dbContext = new SqliteDbContext())
                {
                    Deputy en = new Deputy();
                    {
                        en.Name           = textBoxName.Text;
                        en.PoliticalParty = textBoxPoliticalPartial.Text;
                        //   EnvoysManager.AddEnvoys(en);
                    }
                    dbContext.Deputies.Add(en);
                    dbContext.SaveChanges();

                    if (en.EnvoyID > 0)
                    {
                        MessageBox.Show("Id posła to " + en.EnvoyID);
                    }
                    else
                    {
                        MessageBox.Show("Błąd!");
                    }

                    LoadEnvoyList();

                    textBoxName.Text             = "";
                    textBoxLastName.Text         = "";
                    textBoxPoliticalPartial.Text = "";
                }
            }
        }
        private static void CrearDataGeneral()
        {
            using (var db = new SqliteDbContext())
            {
                var roles = new List <Role>
                {
                    new Role {
                        Name = "Administrador"
                    },
                    new Role {
                        Name = "Usuario"
                    }
                };

                var permisos = new List <Permission>
                {
                    new Permission {
                        Description = "Puede iniciar sesión", Level = PermissionLevel.TotalAccess
                    },
                    new Permission {
                        Description = "Puede cobrar", Level = PermissionLevel.RestrictedAccess
                    }
                };

                db.AddRange(
                    new RolePermission {
                    Role = roles[0], Permission = permisos[0]
                },
                    new RolePermission {
                    Role = roles[0], Permission = permisos[1]
                },
                    new RolePermission {
                    Role = roles[1], Permission = permisos[1]
                }
                    );

                db.SaveChanges();

                var usuarios = new List <User>
                {
                    new User
                    {
                        Name      = "bidkar",
                        Password  = "******",
                        FirstName = "Bidkar",
                        LastName  = "Aragon",
                        Email     = "bidkar@aragon",
                        Role      = roles[0]
                    },
                    new User
                    {
                        Name      = "citlalli",
                        Password  = "******",
                        FirstName = "Citalli",
                        LastName  = "Rivera",
                        Email     = "citlalli@rivera",
                        Role      = roles[1]
                    }
                };

                db.AddRange(usuarios);
                db.SaveChanges();
            }
        }
Пример #29
0
        private void scraperMeetingsBtn_Click(object sender, EventArgs e)
        {
            Scraper.Scraper scrapper = new Scraper.Scraper();
            scrapper.ScrapeDataSitting("https://www.sejm.gov.pl/sejm9.nsf/agent.xsp?symbol=posglos&NrKadencji=9");


            foreach (var meet in scrapper.Meetings)
            {
                Scraper.Scraper s2 = new Scraper.Scraper();
                s2.ScrapeDataOfDay(meet.DetailsLink);
                foreach (var meet2 in s2.Meetings)
                {
                    Meeting meeting2 = new Meeting();
                    meeting2.TimeOfVote  = meet2.TimeOfVote;
                    meeting2.VotingTopic = meet2.VotingTopic;
                    meeting2.VotingLink  = meet2.DetailsLink;

                    meeting2.NrMeetings = meet.NrMeetings;
                    meeting2.DateOfVote = meet.DateOfVote;


                    SrapedMeetings.Add(meeting2);

                    //listEnvoysBox.DataSource = s2.Meetings;
                    //listEnvoysBox.DisplayMember = "FullName";
                }
            }


            foreach (var meeting in SrapedMeetings.Take(5))
            {
                Scraper.Scraper scraperParties = new Scraper.Scraper();
                scraperParties.ScrapeDataClubLink(meeting.VotingLink);

                foreach (var link in scraperParties.Links)
                {
                    Scraper.Scraper scrapevoting = new Scraper.Scraper();
                    scrapevoting.ScrapeDataOfVote(link.Link);

                    foreach (var votingItem in scrapevoting.VotingList)
                    {
                        Deputy deputy = Deputies.Where(x => x.Name == votingItem.Name && x.PoliticalParty == link.Party)
                                        .FirstOrDefault();

                        if (null == deputy)
                        {
                            deputy = new Deputy()
                            {
                                Name = votingItem.Name, PoliticalParty = link.Party
                            };
                            Deputies.Add(deputy);
                        }

                        Vote vote = new Vote()
                        {
                            Meeting  = meeting,
                            Deputy   = deputy,
                            VoteType = votingItem.Vote
                        };

                        Votes.Add(vote);
                    }
                }
            }

            using (SqliteDbContext context = new SqliteDbContext())
            {
                context.Meetings.AddRange(SrapedMeetings);
                context.Deputies.AddRange(Deputies);
                context.Votes.AddRange(Votes);


                context.SaveChanges();
            }
        }
Пример #30
0
 public void SaveChanges()
 {
     _dbContext.SaveChanges();
 }