Beispiel #1
0
        public static async Task AtualizaAsync()
        {
            using (var db = new LocalDbContext())
            {
                db.Database.Migrate();

                var ws = new SyncWebService();
                await AtualizaInscricoes(db, ws);
                await AtualizaConfirmacoes(db, ws);

                db.SaveChanges();
            }
        }
Beispiel #2
0
        public async Task <Usuario> LogInAsync()
        {
            using (var db = new LocalDbContext())
            {
                Login login = new Login();
                App.Current.Settings.GetSection("SyncUser").Bind(login);
                var content  = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, JsonContentType);
                var response = await RequestAsync(async() => await client.PostAsync("Conta/Login", content), logIn : false);

                var usuario = JsonConvert.DeserializeObject <Usuario>(response);
                db.Usuario.RemoveRange(db.Usuario.ToList());
                db.Add(usuario);

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", usuario.Token);

                db.SaveChanges();
                return(usuario);
            }
        }
Beispiel #3
0
        public async Task ExecutaConfirmacoesAsync()
        {
            using (var db = new LocalDbContext())
            {
                var today = App.Current.Today;
                var ws    = new SyncWebService();

                var listaSync    = new List <Confirmacao>();
                var confirmacoes = db.Confirmacoes.Where(c => !c.Cancela && c.Dia == today);

                foreach (var confirmacao in confirmacoes)
                {
                    if (confirmacao.StatusConfirmacao != StatusConfirmacao.Confirmado)
                    {
                        try
                        {
                            await ConfirmacaoWebService.Instance.ConfirmaAsync(confirmacao);

                            confirmacao.StatusConfirmacao = StatusConfirmacao.Confirmado;
                        }
                        catch (ServerException ex)
                        {
                            Console.WriteLine(ex.Message);
                            confirmacao.Mensagem          = "Erro no servidor de confirmação";
                            confirmacao.StatusConfirmacao = StatusConfirmacao.Erro;
                        }
                        confirmacao.StatusSincronia = StatusSincronia.Modificado;
                    }

                    if (confirmacao.StatusSincronia != StatusSincronia.Sincronizado)
                    {
                        listaSync.Add(confirmacao);
                    }

                    confirmacao.StatusSincronia = StatusSincronia.Sincronizado;
                }

                await PostConfirmacoesAsync(listaSync);

                db.SaveChanges();
            }
        }
Beispiel #4
0
 private void SaveLog(string msg, string type = null)
 {
     try
     {
         if (!String.IsNullOrEmpty(msg))
         {
             using (var context = new LocalDbContext())
             {
                 context.Logs.Add(new AppLog {
                     Details = msg, LogType = type
                 });
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
 }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, LocalDbContext context)
        {
            context.People.Add(new Person {
                Id = 1, FullName = "John Lennon"
            });
            context.People.Add(new Person {
                Id = 2, FullName = "Paul McCartney"
            });
            context.People.Add(new Person {
                Id = 3, FullName = "Ringo Starr"
            });
            context.People.Add(new Person {
                Id = 4, FullName = "George Harrison"
            });
            context.People.Add(new Person {
                Id = 5, FullName = "Pete Best"
            });
            context.People.Add(new Person {
                Id = 6, FullName = "Jimmie Nicol"
            });

            context.Users.Add(new User {
                Username = "******", Password = "******", IdUser = 1
            });
            context.SaveChanges();

            app.UseRouting();

            // global cors policy
            app.UseCors(x => x
                        .SetIsOriginAllowed(origin => true)
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(x => x.MapControllers());
        }
Beispiel #6
0
        public async Task CriaConfirmacoesAsync()
        {
            using (var db = new LocalDbContext())
            {
                var today = App.Current.Today;

                var listaSync = new List <Confirmacao>();
                var dias      = db.InscricaoDias.Include(d => d.Inscricao).ThenInclude(i => i.Confirmacoes).Where(d => d.Dia == today.DayOfWeek).ToList();

                foreach (var dia in dias)
                {
                    var confirmacao = dia.Inscricao.Confirmacoes.FirstOrDefault(d => d.Dia == today);

                    if (confirmacao == null)
                    {
                        confirmacao = new Confirmacao
                        {
                            Dia               = today,
                            InscricaoId       = dia.InscricaoId,
                            Inscricao         = dia.Inscricao,
                            StatusConfirmacao = StatusConfirmacao.NaoConfirmado
                        };
                    }

                    if (confirmacao.StatusSincronia != StatusSincronia.Sincronizado)
                    {
                        listaSync.Add(confirmacao);
                    }

                    confirmacao.StatusSincronia = StatusSincronia.Sincronizado;
                }

                await PostConfirmacoesAsync(listaSync);

                db.SaveChanges();
            }
        }
 public bool AdicionarPedido(Pedido pedido)
 {
     _local.Pedidos.Add(pedido); //adicionando Pedido
     _local.SaveChanges();       //comitrar
     return(true);
 }
Beispiel #8
0
 public bool AdicionarDisco(Disco disco)
 {
     _local.discos.Add(disco);
     _local.SaveChanges();
     return(true);
 }
 public bool AdicionarPessoa(Pessoa pessoa)
 {
     local.pessoas.Add(pessoa);
     local.SaveChanges();
     return(true);
 }
Beispiel #10
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            var services = serviceProvider;

            try
            {
                var dbOptions = serviceProvider.GetRequiredService <DbContextOptions <LocalDbContext> >();
                using (var context = new LocalDbContext(dbOptions))
                {
                    context.Database.EnsureCreated();

                    var dummyUser = context.Users.Where(x => x.UserName == "DummyUser").FirstOrDefault();
                    if (dummyUser == null)
                    {
                        var dummy = new User
                        {
                            UserName = "******",
                            FullName = "Dummy User",
                            Password = JsonWebToken.GenerateHash("test1234!", "128"),
                            Role     = "dummyuser tester"
                        };

                        context.Users.Add(dummy);
                    }

                    var dummyTester = context.Users.Where(x => x.UserName == "DummyTester").FirstOrDefault();

                    if (dummyTester == null)
                    {
                        var dummytester = new User
                        {
                            UserName = "******",
                            FullName = "Dummy tester",
                            Password = JsonWebToken.GenerateHash("test1234!", "128"),
                            Role     = "tester"
                        };

                        context.Users.Add(dummytester);
                    }

                    var dummyAdmin = context.Users.Where(x => x.UserName == "dummyAdmin").FirstOrDefault();

                    if (dummyAdmin == null)
                    {
                        var adminUser = new User
                        {
                            UserName = "******",
                            FullName = "Dummy Admin",
                            Password = JsonWebToken.GenerateHash("test1234", "128"),
                            Role     = "Admin"
                        };

                        context.Users.Add(adminUser);
                    }

                    if (!context.BidList.Any())
                    {
                        context.BidList.AddRange(
                            new BidList
                        {
                            BidListId   = 1,
                            Account     = dummyTester.UserName,
                            AskQuantity = 10
                        },
                            new BidList
                        {
                            BidListId   = 2,
                            Account     = dummyUser.UserName,
                            AskQuantity = 20
                        },
                            new BidList
                        {
                            BidListId   = 3,
                            Account     = dummyAdmin.UserName,
                            AskQuantity = 30
                        }
                            );
                    }


                    if (!context.CurvePoints.Any())
                    {
                        context.CurvePoints.AddRange(
                            new CurvePoint
                        {
                            CurveId = 1,
                            Term    = 1,
                            Value   = 10
                        },
                            new CurvePoint
                        {
                            CurveId = 2,
                            Term    = 2,
                            Value   = 20
                        },
                            new CurvePoint
                        {
                            CurveId = 3,
                            Term    = 3,
                            Value   = 30
                        }
                            );

                        if (!context.Ratings.Any())
                        {
                            context.Ratings.AddRange(
                                new Rating
                            {
                                MoodysRating = "azez",
                                FitchRating  = "chjhdd",
                                SandPRating  = "shdh"
                            },

                                new Rating
                            {
                                MoodysRating = "gkeeoe",
                                FitchRating  = "azzdd",
                                SandPRating  = "retr"
                            },
                                new Rating
                            {
                                MoodysRating = "jemlkop",
                                FitchRating  = "zaeer",
                                SandPRating  = "shfgfddh"
                            }
                                );
                        }

                        if (!context.Rules.Any())
                        {
                            context.Rules.AddRange(

                                new Rule
                            {
                                Name        = "this a test rule",
                                Description = "djjsdpo",
                                Template    = "hdshljsq",
                            },
                                new Rule
                            {
                                Name        = "this a test rule1",
                                Description = "djjsdpo",
                                Template    = "hdshljsq",
                            },
                                new Rule
                            {
                                Name        = "this a test rule2",
                                Description = "djjsdpo",
                                Template    = "hdshljsq",
                            }

                                );
                        }

                        if (!context.Trades.Any())
                        {
                            context.Trades.AddRange(

                                new Trade
                            {
                                Account     = dummyTester.UserName,
                                BuyPrice    = 5,
                                BuyQuantity = 5
                            },
                                new Trade
                            {
                                Account     = dummyUser.UserName,
                                BuyPrice    = 10,
                                BuyQuantity = 10
                            },
                                new Trade
                            {
                                Account     = dummyAdmin.UserName,
                                BuyPrice    = 15,
                                BuyQuantity = 15
                            }

                                );
                        }
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #11
0
 public bool AdicionarAtivo(Ativo ativo)
 {
     _local.ativo.Add(ativo);
     _local.SaveChanges();
     return(true);
 }
Beispiel #12
0
 public bool AdicionarProduto(Produto produto)
 {
     _local.produto.Add(produto);
     _local.SaveChanges();
     return(true);
 }
        public StudentTableModel(
            StudentTableToken token,
            PageControllerReducer reducer,
            PhotoService photoService,
            TabPageHost pageHost,
            LocalDbContext context)
        {
            _context                = context;
            this.PhotoService       = photoService;
            this.StudentTableConfig = new TableConfig {
                Sorts      = this.Sorts,
                Filter     = this.FilterFunction,
                DragConfig = new DragConfig {
                    DragValuePath = nameof(StudentViewModel.Student)
                }
            };
            this.StudentTableConfig.SelectedItem
            .AsObservable()
            .Where(LambdaHelper.NotNull)
            .Subscribe(model => UpdatePhoto(((StudentViewModel)model).Student));
            this.ShowStudent = new CommandHandler(() => {
                var selectedItem = this.StudentTableConfig.SelectedItem.Value;
                if (selectedItem == null)
                {
                    return;
                }

                var studentEntity = ((StudentViewModel)selectedItem).Student;
                pageHost.AddPageAsync(new StudentViewPageToken(studentEntity.LastName, studentEntity));
            }
                                                  );
            this.DeleteStudent = ReactiveCommand.Create
                                 (
                () => {
                var selectedItem = this.StudentTableConfig.SelectedItem.Value;
                if (selectedItem == null)
                {
                    return;
                }

                var student          = ((StudentViewModel)selectedItem).Student;
                var persistentEntity = context.Students.Find(student.Id);
                if (persistentEntity != null)
                {
                    context.Students.Remove(persistentEntity);
                    context.SaveChanges();
                }
                RunInUiThread(() => {
                    this.StudentTableConfig.TableItems.Remove(selectedItem);
                });
            }
                                 );
            this.RefreshSubject
            .AsObservable()
            .ObserveOnDispatcher(DispatcherPriority.Background)
            .Subscribe(_ => {
                this.StudentTableConfig.TableItems.Clear();
                var studentEntities = context.Students
                                      .Include("Groups")
                                      .ToList();
                var studentViewModels = studentEntities.Select(entity => new StudentViewModel(entity)).ToList();
                this.StudentTableConfig.TableItems.AddRange(studentViewModels);
            });
            reducer.Dispatch(new RegisterControlsAction(token, GetControls()));
        }
Beispiel #14
0
 public bool AdicionarSapato(Sapato sapato)
 {
     _local.sapato.Add(sapato);
     _local.SaveChanges();
     return(true);
 }
 public bool AdicionarProduto(Produto produto)
 {
     _local.Produtos.Add(produto); //adicionando produto
     _local.SaveChanges();         //comitrar
     return(true);
 }
Beispiel #16
0
 public bool AdicionarSerraCircular(SerraCircular serraCircular)
 {
     _local.serra_circular.Add(serraCircular);//nome do local, da tabela e do objeto
     _local.SaveChanges();
     return(true);
 }
 public bool AdicionaProduto(Produtos produto)
 {
     _Local.Add(produto);
     _Local.SaveChanges();
     return(true);
 }
Beispiel #18
0
 public void InsertMultimedias(ICollection <MultimediaContract> multimedias)
 {
     _localDbContext.Multimedia.AddRange(_mapper.Map <ICollection <Multimedia> >(multimedias));
     _localDbContext.SaveChanges();
 }
Beispiel #19
0
        public ProductResponse Handle(ProductParam command)
        {
            var          productResponse = new ProductResponse();
            ProductEntry product;

            if (command.action == "read")
            {
                product = _dbContext.Products.Where(p =>
                                                    p.ID == Int32.Parse(command.ID)).FirstOrDefault();
                if (product != null)
                {
                    productResponse.data = product;
                }

                productResponse.isSuccess  = true;
                productResponse.message    = "Success";
                productResponse.statusCode = StatusCodes.Status200OK;
            }
            else
            {
                using (var transaction = _dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        switch (command.action.Trim())
                        {
                        case "create":
                            product = command.convertToModel(false);
                            _dbContext.Products.Add(product);
                            break;

                        case "update":
                            product = command.convertToModel(true);
                            _dbContext.Products.Update(product);
                            break;

                        case "delete":
                            product = _dbContext.Products.Where(p =>
                                                                p.ID == Int64.Parse(command.ID)).FirstOrDefault();
                            _dbContext.Products.Remove(product);
                            break;

                        default:

                            break;
                        }

                        if (_dbContext.SaveChanges() > 0)
                        {
                            productResponse.isSuccess  = true;
                            productResponse.message    = "Success";
                            productResponse.statusCode = StatusCodes.Status200OK;
                        }
                        else
                        {
                            productResponse.isSuccess  = false;
                            productResponse.message    = "Failed";
                            productResponse.statusCode = StatusCodes.Status500InternalServerError;
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        productResponse.isSuccess  = false;
                        productResponse.message    = ex.StackTrace.ToString();
                        productResponse.statusCode = StatusCodes.Status500InternalServerError;
                    }
                }
            }


            return(productResponse);
        }
 public void SaveChanges()
 {
     context.SaveChanges();
 }
 public bool AdicionarCarro(Carro carro)
 {
     _local.carro.Add(carro);
     _local.SaveChanges();
     return(true);
 }
Beispiel #22
0
        public virtual bool AddTipsterIfNotExists(DbTipster tipster)
        {
            OnInformationSending("Dodawanie tipstera...");
            if (_db.Tipsters.AsEnumerable().Any(t => t.NameDomainEquals(tipster)))
            {
                OnInformationSending("Dodano Tipstera");
                return(false);
            }

            var tipsterDomain = tipster.Link.UrlToDomain();
            var websiteId     = _db.Websites.SingleOrDefault(w => w.Address == tipsterDomain)?.Id;

            if (websiteId == null)
            {
                var newWId  = _db.Websites.Next(w => w.Id);
                var website = new DbWebsite(newWId, tipsterDomain, null);
                _db.Websites.Add(website);
                _db.SaveChanges();
                websiteId = newWId;
            }

            var tipsterToAdd = new DbTipster
            {
                Id        = _db.Tipsters.Next(v => v.Id),
                Name      = tipster.Name,
                Link      = tipster.Link,
                WebsiteId = websiteId
            };

            _db.Tipsters.AddOrUpdate(tipsterToAdd);
            _db.SaveChanges();

            OnInformationSending("Dodano Tipstera");
            return(true);
        }
Beispiel #23
0
 public bool AdicionarJogo(Jogo jogo)
 {
     _local.jogo.Add(jogo);
     _local.SaveChanges();
     return(true);
 }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            var services = serviceProvider;

            try
            {
                var dbOptions = services.GetRequiredService <DbContextOptions <LocalDbContext> >();

                using (var context = new LocalDbContext(dbOptions))
                {
                    context.Database.EnsureCreated();

                    // Let's remove this record if we currently have it so we can test creating the user
                    // as unique
                    var tempUser = context.Users.Where(x => x.UserName == "tempUsername").SingleOrDefault();

                    if (tempUser != null)
                    {
                        context.Users.Remove(tempUser);
                    }


                    // Add additional dummy user for when testing user deletions
                    var dummyUser = context.Users.Where(x => x.UserName == "dummy").SingleOrDefault();

                    if (dummyUser == null)
                    {
                        var dummy = new User
                        {
                            FullName = "Dummy User",
                            UserName = "******",
                            Password = AppSecurity.HashPassword("test1234!").HashedPassword,
                            Role     = "Tester"
                        };

                        context.Users.Add(dummy);
                    }

                    var user = context.Users.Where(x => x.UserName == "unitTester").SingleOrDefault();

                    if (user == null)
                    {
                        user = new User
                        {
                            FullName = "Unit Tester",
                            UserName = "******",
                            Password = AppSecurity.HashPassword("test1234!").HashedPassword,
                            Role     = "Admin"
                        };

                        context.Users.Add(user);
                    }

                    var admin = context.Users.Where(x => x.UserName == "admin").SingleOrDefault();

                    if (admin == null)
                    {
                        user = new User
                        {
                            FullName = "App Admin",
                            UserName = "******",
                            Password = AppSecurity.HashPassword("test1234!").HashedPassword,
                            Role     = "Admin"
                        };

                        context.Users.Add(user);
                    }



                    if (!context.BidList.Any())
                    {
                        context.BidList.AddRange(
                            new BidList
                        {
                            Account     = user.UserName,
                            Type        = "A simple bid",
                            BidQuantity = 10
                        },
                            new BidList
                        {
                            Account     = user.UserName,
                            Type        = "Another bid",
                            BidQuantity = 5
                        },
                            new BidList
                        {
                            Account     = user.UserName,
                            Type        = "Bid away!!",
                            BidQuantity = 50
                        }
                            );
                    }

                    if (!context.CurvePoints.Any())
                    {
                        context.CurvePoints.AddRange(
                            new CurvePoint
                        {
                            CurveId = 1,
                            Term    = 3,
                            Value   = 1
                        },
                            new CurvePoint
                        {
                            CurveId = 1,
                            Term    = 3,
                            Value   = 5
                        },
                            new CurvePoint
                        {
                            CurveId = 1,
                            Term    = 3,
                            Value   = 5
                        },
                            new CurvePoint
                        {
                            CurveId = 1,
                            Term    = 3,
                            Value   = 5
                        }
                            );
                    }

                    if (!context.Ratings.Any())
                    {
                        context.Ratings.AddRange(
                            new Rating
                        {
                            MoodysRating = "asd",
                            SandPRating  = "Yuasdp",
                            FitchRating  = "Hm123123mm"
                        },
                            new Rating
                        {
                            MoodysRating = "Blsdah",
                            SandPRating  = "Ydup",
                            FitchRating  = "Hmsdamm"
                        },
                            new Rating
                        {
                            MoodysRating = "Blaaah",
                            SandPRating  = "Yuaap",
                            FitchRating  = "Hmdddmm"
                        },
                            new Rating
                        {
                            MoodysRating = "Blah",
                            SandPRating  = "Yup",
                            FitchRating  = "Hmmm"
                        }
                            );
                    }

                    if (!context.RuleNames.Any())
                    {
                        context.RuleNames.AddRange(
                            new RuleName
                        {
                            Name        = "This is a rule",
                            Description = "Test123",
                            Template    = "ABC123"
                        },
                            new RuleName
                        {
                            Name        = "This is a rule",
                            Description = "asdad",
                            Template    = "ABC123"
                        },
                            new RuleName
                        {
                            Name        = "Tasd",
                            Description = "czc",
                            Template    = "ABC123"
                        }
                            );
                    }

                    if (!context.Trades.Any())
                    {
                        context.Trades.AddRange(
                            new Trade
                        {
                            Account     = user.UserName,
                            Type        = "Buy",
                            BuyQuantity = 5
                        },
                            new Trade
                        {
                            Account     = user.UserName,
                            Type        = "Buy",
                            BuyQuantity = 2
                        }
                            );
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <SeedData> >();
                logger.LogError(ex, "An error occurred seeding the DB.");
            }
        }
Beispiel #25
0
 public void Save()
 {
     _db.SaveChanges();
 }
 /// <summary>
 /// 添加单个
 /// </summary>
 /// <param name="entity"></param>
 public virtual void Add(T entity)
 {
     _localDbContext.Set <T>().Add(entity);
     _localDbContext.SaveChanges();
 }
Beispiel #27
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
Beispiel #28
0
 public bool AdicionaEmpresa(Empresa empresa)
 {
     _Local.Add(empresa);
     _Local.SaveChanges();
     return(true);
 }
Beispiel #29
0
 public void Post(UserSession session)
 {
     _context.Sessions.Add(session);
     _context.SaveChanges();
 }
Beispiel #30
0
 public void Add(Sapato request)
 {
     _local.sapato.Add(request);
     _local.SaveChanges();
 }