public async Task <IHttpActionResult> Update([FromBody] UsuarioViewModel usuario)
        {
            using (var context = new RedContext())
            {
                var ExistUsuario = await context.Usuarios.FirstOrDefaultAsync(b => b.Id == usuario.Id);

                if (ExistUsuario == null)
                {
                    return(NotFound());
                }

                ExistUsuario.Address      = usuario.Address;
                ExistUsuario.CityId       = usuario.CityId;
                ExistUsuario.DepartmentId = usuario.DepartmentId;
                ExistUsuario.CountryId    = usuario.CountryId;
                ExistUsuario.FirstName    = usuario.FirstName;
                ExistUsuario.Genero       = usuario.Genero;
                ExistUsuario.LastName     = usuario.LastName;
                ExistUsuario.Phone        = usuario.Phone;
                ExistUsuario.Photo        = usuario.Photo;
                ExistUsuario.UserName     = usuario.UserName;
                ExistUsuario.Password     = usuario.Password;

                await context.SaveChangesAsync();

                return(Ok(new UsuarioViewModel(ExistUsuario)));
            }
        }
Exemple #2
0
 private void InitGrid(RedComboBox[] comboboxes, RedContext context)
 {
     foreach (RedComboBox cb in comboboxes)
     {
         var row = new DataGridViewRow();
         var c1  = new DataGridViewTextBoxCell();
         c1.Value = cb.Name;
         DataGridViewCell c2;
         if (cb.query.ToLowerInvariant() == "textedit")
         {
             c2       = new DataGridViewTextBoxCell();
             c2.Value = "";
         }
         else
         {
             c2 = new DataGridViewComboBoxCell();
             var t = cb.GetValues(context);
             foreach (DataRow r in t.Rows)
             {
                 (c2 as DataGridViewComboBoxCell).Items.Add(r[0].ToString());
             }
             (c2 as DataGridViewComboBoxCell).Value = (c2 as DataGridViewComboBoxCell).Items[0];
         }
         c2.ReadOnly = false;
         row.Cells.Add(c1);
         row.Cells.Add(c2);
         dataGridView1.Rows.Add(row);
     }
 }
Exemple #3
0
        public Form1(DBConfig config)
        {
            log4net.Config.XmlConfigurator.Configure();

            log.Debug("Application started...");
            this.config = config;
            InitializeComponent();
            context = new RedContext()
            {
                Provider = new RedDBProvider(config.ConnectionString)
            };

            LoginForm lf = new LoginForm(context);

            while (lf.CurrentUser == null)
            {
                lf.ShowDialog();
            }

            currentUser = lf.CurrentUser;
            log.DebugFormat("User {0} loged in.", currentUser.Login);

            InitForm();
            dataGridView1.AutoGenerateColumns = false;
        }
Exemple #4
0
 public ViewForm(RedComboBox[] comboboxes, RedContext context)
 {
     InitializeComponent();
     dataGridView1.AutoGenerateColumns = false;
     parametrs = new List <string>();
     InitGrid(comboboxes, context);
 }
 public async Task <IHttpActionResult> Get()
 {
     using (var context = new RedContext())
     {
         return(Ok(await context.VotingPlaces.ToListAsync()));
     }
 }
 public async Task <IHttpActionResult> Get(int id)
 {
     using (var context = new RedContext())
     {
         return(Ok(await context.VotingPlaces.Where(v => v.CityId == id).ToListAsync()));
     }
 }
Exemple #7
0
 public async Task <IHttpActionResult> Get(int id)
 {
     using (var context = new RedContext())
     {
         return(Ok(await context.Departments.FirstOrDefaultAsync(b => b.Id == id)));
     }
 }
Exemple #8
0
 private void відкритиПоточнийСтанToolStripMenuItem_Click(object sender, EventArgs e)
 {
     context = new RedContext()
     {
         Provider = new RedDBProvider(config.ConnectionString)
     };
     InitForm();
     MessageBox.Show("Поточний стан бази завантажено.");
 }
        public StudentCompetitionReportGeneration(RedContext context)
        {
            InitializeComponent();
            this.context = context;
            var students = context.Provider.ExecuteSelectCommand(studQuery);

            comboBox1.ValueMember   = "Id";
            comboBox1.DisplayMember = "Name";
            comboBox1.DataSource    = students;
        }
Exemple #10
0
        public async Task <IHttpActionResult> Save([FromBody] DepartmentViewModel department)
        {
            using (var context = new RedContext())
            {
                var newDepartment = context.Departments.Add(new Department
                {
                    CountryId = department.CountryId,
                    Name      = department.DepartmentName
                });

                await context.SaveChangesAsync();

                return(Ok(new DepartmentViewModel(newDepartment)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] CountryViewModel country)
        {
            using (var context = new RedContext())
            {
                var newCountry = context.Countries.Add(new Country
                {
                    Id   = country.CountryId,
                    Name = country.CountryName
                });

                await context.SaveChangesAsync();

                return(Ok(new CountryViewModel(newCountry)));
            }
        }
Exemple #12
0
 public ChartForm(RedContext context)
 {
     InitializeComponent();
     this.context = context;
     var sectTable = context.Provider.ExecuteSelectCommand(sectionsQuery);
     comboBox1.DisplayMember = sectTable.Columns[0].ColumnName;
     comboBox1.DataSource = sectTable;
     minYear = DateTime.Parse(context.Provider.ExecuteSelectCommand(minYearQuery).Rows[0][0].ToString()).Year;
     maxYear = DateTime.Parse(context.Provider.ExecuteSelectCommand(maxYearQuery).Rows[0][0].ToString()).Year;
     zedGraphControl1.GraphPane.XAxis.Type = AxisType.Text;
     zedGraphControl1.GraphPane.Title.Text = graphLable;
     zedGraphControl1.GraphPane.XAxis.Title.Text = "Навчальні роки";
     zedGraphControl1.GraphPane.YAxis.Title.Text = "Кількість студентів";
     zedGraphControl1.Refresh();
 }
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new RedContext())
            {
                var votingplace = await context.VotingPlaces.FirstOrDefaultAsync(r => r.Id == id);

                if (votingplace == null)
                {
                    return(NotFound());
                }

                context.VotingPlaces.Remove(votingplace);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
Exemple #14
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new RedContext())
            {
                var department = await context.Departments.FirstOrDefaultAsync(r => r.Id == id);

                if (department == null)
                {
                    return(NotFound());
                }

                context.Departments.Remove(department);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
        public async Task <IHttpActionResult> Save([FromBody] CityViewModel city)
        {
            using (var context = new RedContext())
            {
                var newCity = context.Cities.Add(new City
                {
                    CountryId    = city.CountryId,
                    DepartmentId = city.DepartmentId,
                    Name         = city.CityName
                });

                await context.SaveChangesAsync();

                return(Ok(new CityViewModel(newCity)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] CommuneViewModel commune)
        {
            using (var context = new RedContext())
            {
                var newCommune = context.Communes.Add(new Commune
                {
                    CommuneId    = commune.CommuneId,
                    Name         = commune.Name,
                    CountryId    = commune.CountryId,
                    DepartmentId = commune.DepartmentId,
                    CityId       = commune.CityId
                });

                await context.SaveChangesAsync();

                return(Ok(new CommuneViewModel(newCommune)));
            }
        }
Exemple #17
0
        private void відкритиАрхівToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var oad = new OpenArchive();

            oad.ShowDialog();
            if (!string.IsNullOrEmpty(oad.SelectedFile))
            {
                var dbname = Path.GetFileNameWithoutExtension(oad.SelectedFile);
                context = new RedContext()
                {
                    Provider =
                        new RedDBProvider(string.Format(config.ArchiveConnectionStringPattern, dbname))
                };
                log.DebugFormat("User {0} opened archive database {1}", currentUser.Login, "");
                InitForm();
                MessageBox.Show("Архів бази завантажено.");
            }
        }
        public async Task <IHttpActionResult> Update([FromBody] CountryViewModel country)
        {
            using (var context = new RedContext())
            {
                var Existcountry = await context.Countries.FirstOrDefaultAsync(b => b.Id == country.CountryId);

                if (Existcountry == null)
                {
                    return(NotFound());
                }

                Existcountry.Name = country.CountryName;

                await context.SaveChangesAsync();

                return(Ok(new CountryViewModel(Existcountry)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] VotingPlaceViewModel votingplace)
        {
            using (var context = new RedContext())
            {
                var newVotingPlace = context.VotingPlaces.Add(new VotingPlace
                {
                    Id           = votingplace.VotingPlaceId,
                    Name         = votingplace.Name,
                    CountryId    = votingplace.CountryId,
                    DepartmentId = votingplace.DepartmentId,
                    CityId       = votingplace.CityId,
                    Code         = votingplace.Code
                });

                await context.SaveChangesAsync();

                return(Ok(new VotingPlaceViewModel(newVotingPlace)));
            }
        }
Exemple #20
0
        public async Task <IHttpActionResult> Update([FromBody] DepartmentViewModel department)
        {
            using (var context = new RedContext())
            {
                var ExistDepartment = await context.Departments.FirstOrDefaultAsync(b => b.Id == department.DepartmentId);

                if (ExistDepartment == null)
                {
                    return(NotFound());
                }

                ExistDepartment.CountryId = department.CountryId;
                ExistDepartment.Name      = department.DepartmentName;

                await context.SaveChangesAsync();

                return(Ok(new DepartmentViewModel(ExistDepartment)));
            }
        }
        public async Task <IHttpActionResult> Update([FromBody] CommuneViewModel commune)
        {
            using (var context = new RedContext())
            {
                var ExistCommune = await context.Communes.FirstOrDefaultAsync(b => b.CommuneId == commune.CommuneId);

                if (ExistCommune == null)
                {
                    return(NotFound());
                }

                ExistCommune.Name         = commune.Name;
                ExistCommune.CountryId    = commune.CountryId;
                ExistCommune.DepartmentId = commune.DepartmentId;
                ExistCommune.CityId       = commune.CityId;

                await context.SaveChangesAsync();

                return(Ok(new CommuneViewModel(ExistCommune)));
            }
        }
Exemple #22
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            XmlSerializer serializer = new XmlSerializer(typeof(DBConfig));
            var           conf       = new DBConfig();

            using (var stream = File.OpenRead(@"d:\TK\Lesia\LabaBoiko\FizDb\ProjectsManager\FizDb.WebClient\bin\DBConfig.xml"))
            {
                conf = (DBConfig)serializer.Deserialize(stream);
            }
            var context = new RedContext()
            {
                Provider = new RedDBProvider(conf.ConnectionString)
            };

            Container.Context = context;
            Container.Dataset = GetDataSet(conf, context);
        }
        public async Task <IHttpActionResult> Update([FromBody] VotingPlaceViewModel votingplace)
        {
            using (var context = new RedContext())
            {
                var ExistVotingPlace = await context.VotingPlaces.FirstOrDefaultAsync(b => b.Id == votingplace.VotingPlaceId);

                if (ExistVotingPlace == null)
                {
                    return(NotFound());
                }

                ExistVotingPlace.Name         = votingplace.Name;
                ExistVotingPlace.CountryId    = votingplace.CountryId;
                ExistVotingPlace.DepartmentId = votingplace.DepartmentId;
                ExistVotingPlace.CityId       = votingplace.CityId;
                ExistVotingPlace.Code         = votingplace.Code;

                await context.SaveChangesAsync();

                return(Ok(new VotingPlaceViewModel(ExistVotingPlace)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] UsuarioViewModel usuario)
        {
            using (var context = new RedContext())
            {
                var newUsuario = context.Usuarios.Add(new User
                {
                    Id           = usuario.Id,
                    Address      = usuario.Address,
                    CityId       = usuario.CityId,
                    DepartmentId = usuario.DepartmentId,
                    CountryId    = usuario.CountryId,
                    FirstName    = usuario.FirstName,
                    Genero       = usuario.Genero,
                    LastName     = usuario.LastName,
                    Phone        = usuario.Phone,
                    Photo        = usuario.Photo,
                    UserName     = usuario.UserName,
                    Password     = usuario.Password
                });

                var role = context.Roles.First(c => c.Name == "User").Id;

                var User = context.Users.Add(new IdentityUser("usuario")
                {
                    Email = newUsuario.UserName, EmailConfirmed = true
                });
                User.Roles.Add(new IdentityUserRole {
                    RoleId = role
                });

                await context.SaveChangesAsync();

                var store = new RedUserStore();
                await store.SetPasswordHashAsync(User, new RedUserManager().PasswordHasher.HashPassword(usuario.Password));

                return(Ok(new UsuarioViewModel(newUsuario)));
            }
        }
Exemple #25
0
        private Red.RedDataSet GetDataSet(DBConfig config, RedContext context)
        {
            var dataSet = new RedDataSet();

            foreach (var t in config.Tables)
            {
                dataSet.AddTable(t.query, t.name, t.SearchQuery == null? null: t.SearchQuery.Query, context);
                if (t.Comboboxes != null)
                {
                    foreach (var c in t.Comboboxes)
                    {
                        dataSet.tables[t.name].AddComboBox(c.name, new RedComboBox(c.query, c.name));
                    }
                }
                if (t.Columns != null)
                {
                    foreach (var c in t.Columns)
                    {
                        dataSet.tables[t.name].AddColumnAliasHere(c.Name, c.Alias);
                    }
                }
            }
            foreach (var r in config.Requests)
            {
                dataSet.AddView(r.query, r.name, r.desc, context);
                if (r.Comboboxes != null)
                {
                    foreach (var c in r.Comboboxes)
                    {
                        dataSet.views[r.name].AddComboBox(c.name, new RedComboBox(c.query, c.name));
                    }
                }
            }

            return(dataSet);
        }
Exemple #26
0
 public LoginForm(RedContext context)
 {
     InitializeComponent();
     this.context = context;
 }