Exemplo n.º 1
0
 public ClientListViewModel()
 {
     using (var context = new ClientsContext())
     {
         context.Clients.ToList().ForEach(x => _clients.Add(new ClientViewModel(x)));
     }
 }
Exemplo n.º 2
0
 public static void SynchT()
 {
     using (ClientsContext db = new ClientsContext())
         using (SqlConnection con = new SqlConnection(Param.ConnectionString))
             try
             {
                 con.Open();
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = "SELECT * FROM rate_list";
                 SqlDataReader  dr       = cmd.ExecuteReader();
                 List <TarifED> tarifsED = new List <TarifED>();
                 while (dr.Read())
                 {
                     if (dr["Name"].ToString() != "")
                     {
                         var tarif = new TarifED
                         {
                             SQLGuid        = dr["id_org"].ToString(),
                             Name           = dr["Name"].ToString(),
                             DateApply      = Convert.ToDateTime(dr["Date"]),
                             LetterFileName = dr["letter_filename"] == DBNull.Value ? null : dr["Letter_filename"].ToString()
                         };
                         tarifsED.Add(tarif);
                         Console.WriteLine(db.Organizations.Where(o => EF.Functions.Like(o.SQLGuid, $"%{tarif.SQLGuid}%")).Count());
                     }
                 }
                 ;
                 dr.Close();
                 db.SaveChanges();
             }
             catch (SystemException ex)
             {
                 Console.WriteLine(ex.Message);
             }
 }
Exemplo n.º 3
0
 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
 {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     using (var context = new ClientsContext())
     {
         context.UpdateClient(_client);
     }
 }
Exemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            ClientsContext db = new ClientsContext();

            db.Clients.Add(new Client()
            {
                LongName = "Vano"
            });
            db.SaveChanges();
        }
Exemplo n.º 5
0
 static bool SynchTarifs()
 {
     using (ClientsContext db = new ClientsContext())
         using (SqlConnection con = new SqlConnection(Param.ConnectionString))
             try
             {
                 con.Open();
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = "SELECT * FROM rate_list";
                 SqlDataReader  dr       = cmd.ExecuteReader();
                 List <TarifED> tarifsED = new List <TarifED>();
                 while (dr.Read())
                 {
                     if (dr["Name"].ToString() != "")
                     {
                         var tarif = new TarifED
                         {
                             SQLGuid        = dr["id_org"].ToString(),
                             Name           = dr["Name"].ToString(),
                             DateApply      = Convert.ToDateTime(dr["Date"]),
                             LetterFileName = dr["letter_filename"] == DBNull.Value ? null : dr["Letter_filename"].ToString()
                         };
                         tarifsED.Add(tarif);
                         foreach (var o in db.Organizations)
                         {
                             if (tarif.SQLGuid == o.SQLGuid)
                             {
                                 o.TarifsED.Add(tarif);
                             }
                         }
                     }
                 }
                 ;
                 dr.Close();
                 foreach (var t in tarifsED)
                 {
                     foreach (var o in db.Organizations)
                     {
                         if (o.SQLGuid == t.SQLGuid)
                         {
                             Console.WriteLine(t.SQLGuid);
                             o.TarifsED.Add(t);
                         }
                     }
                 }
                 db.SaveChanges();
             }
             catch (SystemException ex)
             {
                 Console.WriteLine(ex.Message);
                 return(false);
             }
     return(true);
 }
Exemplo n.º 6
0
 private void DeleteSelected()
 {
     if (SelectedClient != null)
     {
         using (var context = new ClientsContext())
         {
             context.DeleteClient(SelectedClient.Id);
         }
         _clients.Remove(SelectedClient);
         SelectedClient = null;
     }
 }
Exemplo n.º 7
0
        public static ClientsContext GetDbContext(string dbName)
        {
            var options = new DbContextOptionsBuilder <ClientsContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;

            var dbContext = new ClientsContext(options);

            dbContext.Seed();

            return(dbContext);
        }
Exemplo n.º 8
0
        public IActionResult Result(Client client)
        {
            List <Client> result = null;

            using (var context = new ClientsContext())
            {
                context.Clients.Add(client);
                context.SaveChanges();
                result = context.Clients.ToList();
            }
            return(View(result));
        }
Exemplo n.º 9
0
 public static bool UpdateContacts()
 {
     using (ClientsContext db = new ClientsContext())
         using (SqlConnection con = new SqlConnection(Param.ConnectionString))
             try
             {
                 con.Open();
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = "SELECT id, id_org, ISNULL(Post,'') AS Post, ISNULL(Fio,'') AS Fio, ISNULL(phone1,'') AS Phone, ISNULL(phone2,'') AS Phone1, ISNULL(Mail,'') AS Email, predstavitel FROM contacts";
                 SqlDataReader  dr       = cmd.ExecuteReader();
                 List <Contact> contacts = new List <Contact>();
                 while (dr.Read())
                 {
                     string id           = dr["id"].ToString();
                     string idOrg        = dr["id_org"].ToString();
                     string post         = dr["Post"].ToString() == "" ? null : dr["Post"].ToString();
                     string fio          = dr["Fio"].ToString();
                     string phone        = dr["Phone"].ToString() == "" ? null : dr["Phone"].ToString();
                     string phone1       = dr["Phone1"].ToString() == "" ? null : dr["Phone1"].ToString();
                     string email        = dr["Email"].ToString() == "" ? null : dr["Email"].ToString();
                     int    predstavitel = Convert.ToInt32(dr["predstavitel"]);
                     contacts.Add(new Contact
                     {
                         SQLGuid          = id,
                         SQLGuidOrg       = idOrg,
                         Fio              = fio,
                         Post             = post,
                         Phone            = phone,
                         Phone1           = phone1,
                         Email            = email,
                         isRepresentative = predstavitel
                     });
                 }
                 foreach (var o in db.Organizations)
                 {
                     foreach (var c in contacts)
                     {
                         if (o.SQLGuid == c.SQLGuidOrg)
                         {
                             o.Contacts.Add(c);
                         }
                     }
                 }
                 db.SaveChanges();
                 return(true);
             }
             catch (SystemException ex)
             {
                 return(false);
             };
 }
Exemplo n.º 10
0
        public bool AddClient(string FirstNationName)
        {
            var myClient = new Client();

            myClient.FirstNationName = FirstNationName;

            using (ClientsContext _db = new ClientsContext())
            {
                // Add client to DB
                _db.Clients.Add(myClient);
                _db.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 11
0
 private void SaveClient()
 {
     if (!string.IsNullOrEmpty(SaveClientViewModel.LastName) ||
         !string.IsNullOrEmpty(SaveClientViewModel.FirstName) ||
         SaveClientViewModel.Birthday != _dateTimeNullValue)
     {
         var client = new Client
         {
             LastName  = SaveClientViewModel.LastName,
             FirstName = SaveClientViewModel.FirstName,
             Birthday  = SaveClientViewModel.Birthday
         };
         var viewModel = new ClientViewModel(client);
         using (var context = new ClientsContext())
         {
             var id = context.CreateClient(client);
             viewModel.Client.Id = id;
         }
         ClientListViewModel.Clients.Add(viewModel);
     }
 }
Exemplo n.º 12
0
 public ClientsController(ClientsContext context)
 {
     this.db = context;
     if (!db.Clients.Any())
     {
         db.Clients.Add(new Client
         {
             Name        = "Ivan",
             Surname     = "Rudov",
             MiddleName  = "Andreevich",
             DateOfBirth = DateTime.Parse("1994-4-20"),
             Deposit     = 1000M
         });
         db.Clients.Add(new Client
         {
             Name        = "Dmitriy",
             Surname     = "Izotov",
             MiddleName  = "Andreevich",
             DateOfBirth = DateTime.Parse("1994-5-02"),
             Deposit     = 2000M
         });
         db.Clients.Add(new Client
         {
             Name        = "Vladimir",
             Surname     = "Katkov",
             MiddleName  = "Vladimirovich",
             DateOfBirth = new DateTime(1994, 01, 15),
             Deposit     = 3000M
         });
         db.Clients.Add(new Client
         {
             Name        = "Pavel",
             Surname     = "Kireev",
             MiddleName  = "Aleksandrovich",
             DateOfBirth = new DateTime(1994, 06, 21),
             Deposit     = 4000M
         });
         db.SaveChanges();
     }
 }
Exemplo n.º 13
0
 static void Main(string[] args)
 {
     //Host=localhost;Port=5432;Database=usersdb;Username=postgres;Password=password
     Console.WriteLine("Hello World!");
     Console.WriteLine(LegalForms.IP.Description());
     Console.WriteLine(EnumHelper.GetEnumValue <LegalForms>("ИП").Description());
     Console.ReadLine();
     Synch.SynchOrganizations.OrgReestr();
     Synch.SynchOrganizations.SynchT();
     using (ClientsContext db = new ClientsContext())
     {
         var orgs = db.Organizations.Where(o => EF.Functions.Like(o.Alias, "%Орлова%"));
         foreach (Organization org in orgs)
         {
             org.Contacts.Add(new Contact
             {
                 Fio   = "Орлова А. Е.",
                 Phone = "8 919"
             });
         }
         ;
         db.SaveChanges();
     }
 }
Exemplo n.º 14
0
        public OrgnizationEditViewModel()
        {
            db = new ClientsContext();

            CreateContractED = new DelegateCommand(() =>
            {
                if (ContractsEd_ == null)
                {
                    var contractsEd = new ContractsEd
                    {
                        IdOrg    = Organization_.Id,
                        Agent    = ContractEdAgents[0],
                        Operator = Operators[0],
                        Num      = db.GetNextContracts(ClientsContext.NextContractType.EDInfodec),
                        Date     = DateTime.Now
                    };
                    db.ContractsEds.Add(contractsEd);
                    db.SaveChanges();
                    ContractsEd_ = contractsEd;
                    OnPropertyChanged("ContractsEd_");
                }
                ;
            });
            CreateContractLD = new DelegateCommand(() =>
            {
                if (ContractsLd_ == null)
                {
                    var contract = new ContractsLd
                    {
                        IdOrg = Organization_.Id,
                        Agent = ContractEdAgents[0],
                        Num   = db.GetNextContracts(ClientsContext.NextContractType.LDCtm),
                        Date  = DateTime.Now
                    };
                    db.ContractsLds.Add(contract);
                    db.SaveChanges();
                    ContractsLd_ = contract;
                    OnPropertyChanged("ContractsLd_");
                }
                ;
            });
            LicenseeLDChangeCommand = new DelegateCommand(() =>
            {
                OrganizationLicenseeLDView fr = new OrganizationLicenseeLDView();
                fr.Left = System.Windows.Forms.Cursor.Position.X;
                fr.Top  = System.Windows.Forms.Cursor.Position.Y;
                if (fr.ShowDialog() == true)
                {
                    var vm = fr.DataContext as OrganizationLicenseeLDViewModel;
                    Organization_.LicenseeLdidOrg           = vm.OrganizationSelected.Id;
                    Organization_.LicenseeLdidOrgNavigation = vm.OrganizationSelected;
                    OnPropertyChanged(nameof(Organization_));
                }
            });
            LicenseeLDEqualCommand = new DelegateCommand(() =>
            {
                Organization_.LicenseeLdidOrg           = Organization_.Id;
                Organization_.LicenseeLdidOrgNavigation = Organization_;
                OnPropertyChanged(nameof(Organization_));
            });
            SaveCommand = new DelegateCommand(() =>
            {
                db.SaveChanges();
            });
        }
        public List <User> GetUserList()
        {
            ClientsContext context = new ClientsContext();

            return(context.Users.ToList());
        }
Exemplo n.º 16
0
 public UnitOfWork(ClientsContext clientsContext)
 {
     _clientsContext = clientsContext;
 }
Exemplo n.º 17
0
 public RepositoryDAL()
 {
     ctx = new ClientsContext(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VetClinic2;Integrated Security=True");
 }
Exemplo n.º 18
0
 public ClientController(ClientsContext webAPIDataContext)
 {
     _clientsContext = webAPIDataContext;
     _clientsContext.Database.EnsureCreated();
 }
        public static void Seed(this ClientsContext context)
        {
            context.Clients.Add(new Client
            {
                Id    = 1,
                Nit   = "8004390-9",
                Name  = "Importaciones Tekus S.A.S.",
                Email = "*****@*****.**"
            });

            context.Clients.Add(new Client
            {
                Id    = 2,
                Nit   = "8003290-4",
                Name  = "SpaceZ",
                Email = "*****@*****.**"
            });

            context.Services.Add(new Service
            {
                Id         = 1,
                Name       = "Descarga espacial de contenidos",
                Price      = 22.09,
                ProviderId = 1
            });

            context.Services.Add(new Service
            {
                Id         = 2,
                Name       = "Desaparicion Forzada de bytes",
                Price      = 300.0,
                ProviderId = 1
            });

            context.Services.Add(new Service
            {
                Id         = 3,
                Name       = "Tour por Marte",
                Price      = 250000000.0,
                ProviderId = 2
            });

            context.Countries.Add(new Country
            {
                Id   = 1,
                Name = "Colombia",
            });

            context.Countries.Add(new Country
            {
                Id   = 2,
                Name = "Mexico",
            });

            context.Countries.Add(new Country
            {
                Id   = 3,
                Name = "Peru",
            });

            context.ServiceCountries.Add(new ServiceCountry
            {
                CountryId = 1,
                ServiceId = 1
            });

            context.ServiceCountries.Add(new ServiceCountry
            {
                CountryId = 2,
                ServiceId = 1
            });
            context.ServiceCountries.Add(new ServiceCountry
            {
                CountryId = 2,
                ServiceId = 2
            });
            context.ServiceCountries.Add(new ServiceCountry
            {
                CountryId = 3,
                ServiceId = 3
            });

            context.SaveChanges();
        }
Exemplo n.º 20
0
 public ClienteRepository(ClientsContext clientsContext)
 {
     _clientsContext = clientsContext;
 }
Exemplo n.º 21
0
 public UnitOfWork(ClientsContext context, IWebHostEnvironment env)
 {
     _context = context;
     _env     = env;
 }
 public ServiceCountryController(ClientsContext context)
 {
     _context = context;
 }
Exemplo n.º 23
0
 public ClientsController(ClientsContext context, IWebHostEnvironment env, IUnitOfWork unitOfWork)
 {
     _context    = context;
     _env        = env;
     _unitOfWork = unitOfWork;
 }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            clients_siContext dbMSql  = new clients_siContext();
            ClientsContext    dbPgSql = new ClientsContext();

            var organisations = dbPgSql.Organizations.ToList();
            var org2          = dbPgSql.Organizations.Find(25734);

            Console.WriteLine($"{org2.Alias} - {org2.Organization_?.Alias}");

            /*
             * foreach (var o in organisations)
             *  if(o.Alias!=o.Organization_?.Alias)
             *  Console.WriteLine($"{o.Alias} \t-\t {o.Organization_?.Alias}");
             */
            ICollection <ConvertCommands> commands = new List <ConvertCommands>()
            {
                /*
                 * ConvertCommands.SynchOrg,
                 * ConvertCommands.SynchContact,
                 * ConvertCommands.SynchRates
                 * ConvertCommands.SynchLicenseeLD
                 */
            };

            foreach (var cmd in commands)
            {
                switch (cmd)
                {
                case ConvertCommands.RemoveOrg:
                    dbPgSql.Organizations.RemoveRange(dbPgSql.Organizations);
                    dbPgSql.SaveChanges();
                    break;

                case ConvertCommands.SynchOrg:
                    var orglist  = dbMSql.Organizations.ToList();
                    var rateList = dbMSql.RateLists.ToList();

                    foreach (var o in orglist)
                    {
                        foreach (var o1 in dbMSql.OrgNotes)
                        {
                            Guid g = Guid.Parse(o1.GuidOrg);
                            if (o.Id == g)
                            {
                                var org = new PgSQL.Organization
                                {
                                    Alias       = o.OrgName,
                                    LegalForm   = (int)EnumHelper.GetEnumValue <LegalFromEnum>(o1.LegalForm),
                                    Name        = o1.OrgNameOriginal,
                                    NameFull    = $"{o1.LegalForm} {o1.OrgNameOriginal}",
                                    Inn         = o1.Inn,
                                    Kpp         = o1.Kpp,
                                    Ogrn        = o1.Ogrn,
                                    BankName    = o1.Bank,
                                    BankBik     = o1.Bik,
                                    BankAccount = o1.RShet,
                                    BankCorrsepondentAccount = o1.KorShet,
                                    DirectorName             = o1.Director,
                                    DirectorDolgnost         = o1.Dolgnost,
                                    Sqlguid = o.Id.ToString()
                                };
                                if (o.Date != "" && o.Date != null)
                                {
                                    org.ContractsEds.Add(new PgSQL.ContractsEd
                                    {
                                        Num  = o.Contract,
                                        Date = Convert.ToDateTime(o.Date)
                                    });
                                }
                                if (o.DateLd != "" && o.DateLd != null)
                                {
                                    org.ContractsLds.Add(new ContractsLd
                                    {
                                        Num  = o.ContractLd,
                                        Date = Convert.ToDateTime(o.DateLd)
                                    });
                                }
                                dbPgSql.Organizations.Add(org);
                                break;
                            }
                            ;
                        }
                        ;
                    }
                    ;
                    dbPgSql.SaveChanges();
                    break;

                case ConvertCommands.SynchRates:
                    var org1  = dbPgSql.Organizations.ToList();
                    var rates = dbMSql.RateLists;
                    foreach (var r in rates)
                    {
                        Guid rg = Guid.Parse(r.IdOrg);
                        foreach (var o in org1)
                        {
                            Guid g = Guid.Parse(o.Sqlguid);
                            if (rg == g)
                            {
                                o.TarifsEds.Add(new TarifsEd
                                {
                                    DateApply      = Convert.ToDateTime(r.Date),
                                    Name           = r.Name,
                                    LetterFileName = r.LetterFilename
                                });
                            }
                        }
                    }
                    dbPgSql.SaveChanges();
                    break;

                case ConvertCommands.SynchContact:
                    foreach (var o in dbPgSql.Organizations)
                    {
                        foreach (var c in dbMSql.Contacts)
                        {
                            if (Guid.Parse(c.IdOrg) == Guid.Parse(o.Sqlguid))
                            {
                                o.Contacts.Add(new PgSQL.Contact
                                {
                                    Fio              = c.Fio,
                                    Phone            = c.Phone1,
                                    Phone1           = c.Phone2,
                                    Email            = c.Mail,
                                    Post             = c.Post,
                                    IsRepresentative = c.Predstavitel
                                });
                            }
                        }
                    }
                    dbPgSql.SaveChanges();
                    break;

                case ConvertCommands.SynchLicenseeLD:
                    Console.WriteLine(" ------ ");
                    Console.WriteLine(dbMSql.ViewLicenseeLDRelation.Where(o => o.ParentOrgName != "").Count());
                    Console.WriteLine(" ------ ");

                    Dictionary <Guid, Guid> licRelations = new Dictionary <Guid, Guid>();
                    foreach (var org in dbMSql.ViewLicenseeLDRelation.Where(org => org.ParentOrgName != ""))
                    {
                        licRelations.Add(org.ChildrenID, org.ParentID);
                    }

                    Dictionary <Guid, int> parentOrgList = new Dictionary <Guid, int>();
                    var organizations = dbPgSql.Organizations.ToList();
                    foreach (var parentID in dbMSql.ViewLicenseeLDRelation.Where(org => org.ParentOrgName != "").Select(org => org.ParentID).Distinct())
                    {
                        var org = organizations.FirstOrDefault(o =>
                        {
                            Guid guid = Guid.Parse(o.Sqlguid);
                            if (guid == parentID)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        });
                        parentOrgList.Add(parentID, org.Id);
                    }
                    ;

                    foreach (var org in dbPgSql.Organizations)
                    {
                        foreach (var relation in licRelations)
                        {
                            if (Guid.Parse(org.Sqlguid) == relation.Key)
                            {
                                org.LicenseeLDIdOrg = parentOrgList[relation.Value];
                            }
                        }
                    }
                    dbPgSql.SaveChanges();
                    //Console.WriteLine(String.Join(',', dbMSql.ViewLicenseeLDRelation.Where(o => o.ParentOrgName != "").Select(o => o.ParentOrgName).ToArray()));
                    break;
                }
            }

            //dbPgSql.Contacts.RemoveRange(dbPgSql.Contacts);

            /*
             * dbPgSql.ContractsEds.RemoveRange(dbPgSql.ContractsEds);
             * dbPgSql.ContractsLds.RemoveRange(dbPgSql.ContractsLds);
             * dbPgSql.TarifsEds.RemoveRange(dbPgSql.TarifsEds);
             */
            /*
             * ClientsContext dbPgSql = new ClientsContext();
             *
             * dbPgSql.Organizations.RemoveRange(dbPgSql.Organizations);
             * dbPgSql.Contacts.RemoveRange(dbPgSql.Contacts);
             * dbPgSql.ContractsEds.RemoveRange(dbPgSql.ContractsEds);
             * dbPgSql.ContractsLds.RemoveRange(dbPgSql.ContractsLds);
             * dbPgSql.TarifsEds.RemoveRange(dbPgSql.TarifsEds);
             */
        }
Exemplo n.º 25
0
 protected override void Seed(ClientsContext context)
 {
     context.Products.AddOrUpdate(Products());
 }
Exemplo n.º 26
0
 public ClientRepository(ClientsContext context, IWebHostEnvironment env)
 {
     _context = context;
     _env     = env;
 }
Exemplo n.º 27
0
 public ClientRepository(ClientsContext context)
 {
     _context = context;
 }
 public ValidationActionFilter(ClientsContext context)
 {
     _context = context;
 }
Exemplo n.º 29
0
 public ClientController(ClientsContext context)
 {
     _context = context;
 }
Exemplo n.º 30
0
 public ClientRepository(ClientsContext dbContext)
 {
     _context = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }