Exemple #1
0
        public void LikeDislike([FromBody] KarmaDTO karma)
        {
            var feedback = db.Feedback.FirstOrDefault(el => el.FeedbackId == karma.Id);
            var reaction = db.UserFeedbackReaction.FirstOrDefault(el => karma.Id == el.FeedbackId && karma.UserId == el.UserId);

            if (reaction == null)
            {
                feedback.Karma = feedback.Karma + 1;
                db.UserFeedbackReaction.Add(new UserFeedbackReaction(karma.Id, karma.UserId));
            }
            else
            {
                feedback.Karma = feedback.Karma - 1;
                db.UserFeedbackReaction.Remove(reaction);
            }
            db.Feedback.Update(feedback);
            db.SaveChanges();
        }
Exemple #2
0
 public int item_add(Item item)
 {
     using (postgresContext db = new postgresContext())
     {
         db.Items.Add(item);
         db.SaveChanges();
         var a = db.Accounts.Max(a => a.Id);
         return(a);
     }
 }
Exemple #3
0
 public int account_add(Account acc)
 {
     using (postgresContext db = new postgresContext())
     {
         db.Accounts.Add(acc);
         db.SaveChanges();
         var d = db.Accounts.Max(d => d.Id);
         return(d);
     }
 }
Exemple #4
0
 public int character_add(Character char_)
 {
     using (postgresContext db = new postgresContext())
     {
         db.Characters.Add(char_);
         db.SaveChanges();
         var m = db.Characters.Max(m => m.Id);
         return(m);
     }
 }
Exemple #5
0
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <postgresContext>()
                          .UseInMemoryDatabase(databaseName: "archerPostgresDatabase")
                          .Options;

            dbContext = new postgresContext(options);

            InitCompanyTable(dbContext);
            dbContext.SaveChanges();
        }
        public Category CreateCategory(string name, string description)
        {
            var query = from c in context.Categories
                        select c;
            Category last = query.ToList().Last();

            var cat = new Category(last.Id + 1, name, description);

            context.Categories.Add(cat);
            var affectedR = context.SaveChanges();

            if (affectedR == 1)
            {
                return(cat);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public IActionResult ProdutoCarrinho([FromBody] CarrinhoCompras carrinho)
        {
            try
            {
                var context        = new postgresContext();
                var carrinhoExiste = context.CarrinhoCompras.FirstOrDefault(x => x.IdProduto == carrinho.IdProduto && x.Finalizado == false && x.IdUsuario == carrinho.IdUsuario);
                var produto        = context.Produtos.FirstOrDefault(x => x.IdProduto == carrinho.IdProduto);
                if (carrinhoExiste != null)
                {
                    carrinhoExiste.Quantidade = carrinho.Quantidade;
                    if (carrinhoExiste.Quantidade > produto.Quantidade)
                    {
                        throw new Exception($"Quantidade Máxima excedida! - Total Disponível: {produto.Quantidade}");
                    }

                    //produto.Quantidade -= carrinhoExiste.Quantidade;
                    //context.Produtos.Update(produto);
                    context.CarrinhoCompras.Update(carrinhoExiste);
                }
                else
                {
                    if (carrinho.Quantidade > produto.Quantidade)
                    {
                        throw new Exception($"Quantidade Máxima excedida! - Total Disponível: {produto.Quantidade}");
                    }

                    // produto.Quantidade -= carrinho.Quantidade;
                    //context.Produtos.Update(produto);

                    carrinho.Finalizado = false;
                    context.CarrinhoCompras.Add(carrinho);
                }
                context.SaveChanges();
                context.Dispose();

                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.OK,
                    Body = "",
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("[error] ConfigController - GetFurnaces - {0} - {1}",
                                  ex.Message,
                                  ex.StackTrace.Replace(Environment.NewLine, " "));
                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.InternalServerError,
                    Body = ex.Message,
                });
            }
        }
Exemple #8
0
 public void setRecord(user_stats records)
 {
     using (postgresContext db = new postgresContext())
     {
         var user = db.user_stats.ToList().Where(x => x.user_id == records.user_id).ToList()[0];
         user.maxmatterlvl = records.maxmatterlvl;
         user.maxenergylvl = records.maxenergylvl;
         user.maxnaturelvl = records.maxnaturelvl;
         db.user_stats.Update(user);
         db.SaveChanges();
     }
 }
        public int RemoveGoal(string selectedTitle)
        {
            using var db = new postgresContext();
            var itemToRemove = db.Goal.SingleOrDefault(x => x.Title == selectedTitle);

            if (itemToRemove != null)
            {
                db.Goal.Remove(itemToRemove);
            }

            return(db.SaveChanges());
        }
        public IActionResult Contact()
        {
            var user = new User();

            using (var db = new postgresContext())
            {
                user.Name    = "Malik";
                user.SurName = "Chanbaz";
                db.User.Add(user);
                var count = db.SaveChanges();
            }
            return(View(user));
        }
Exemple #11
0
 public void SysLogKaydet(string strAciklama)
 {
     //TODO: Exception handle
     using (postgresContext db = new postgresContext())
     {
         SysLog s = new SysLog();
         s.Aciklama = strAciklama;
         s.Tarih    = new DateTime[] { DateTime.Now };
         db.SysLogs.Add(s);
         db.SaveChanges();
         //...
     }
 }
Exemple #12
0
 public bool item_delete(int i_id)
 {
     using (postgresContext db = new postgresContext())
     {
         var item = item_get_by_id(i_id);
         if (item == null)
         {
             return(false);
         }
         db.Items.Remove(item);
         db.SaveChanges();
         return(true);
     }
 }
Exemple #13
0
 public bool character_delete(int char_id)
 {
     using (postgresContext db = new postgresContext())
     {
         var chara = character_get_by_id(char_id);
         if (chara == null)
         {
             return(false);
         }
         db.Characters.Remove(chara);
         db.SaveChanges();
         return(true);
     }
 }
Exemple #14
0
 public bool character_item_delete(int l_id)
 {
     using (postgresContext db = new postgresContext())
     {
         var nom = db.CharactersItems.FirstOrDefault(n => n.LinkId == l_id);
         if (nom == null)
         {
             return(false);
         }
         db.CharactersItems.Remove(nom);
         db.SaveChanges();
         return(true);
     }
 }
Exemple #15
0
 public bool account_delete(int acc_id)
 {
     using (postgresContext db = new postgresContext())
     {
         var director = account_get_by_id(acc_id);
         if (director == null)
         {
             return(false);
         }
         db.Accounts.Remove(director);
         db.SaveChanges();
         return(true);
     }
 }
Exemple #16
0
        private static void Init()
        {
            using (var db = new woodmanContext())
            {
                var entities = db.EfCoreTest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                }

                for (var i = 0; i < InitialCount; i++)
                {
                    db.Add(new EfCoreTest
                    {
                        Name         = nameof(BulkTransactionTests),
                        CreatedDate  = DateTime.Now,
                        ModifiedDate = DateTime.Now
                    });
                }

                db.SaveChanges();
            }

            using (var db = new postgresContext())
            {
                var entities = db.Efcoretest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                }

                for (var i = 0; i < InitialCount; i++)
                {
                    db.Add(new Efcoretest
                    {
                        Name         = nameof(BulkTransactionTests),
                        Createddate  = DateTime.Now,
                        Modifieddate = DateTime.Now
                    });
                }

                db.SaveChanges();
            }
        }
        public void Contact()
        {
            var user = new User();

            var mock = new Mock <postgresContext>();

            mock.Setup(p => p.SaveChanges()).Returns(1);

            using (var db = new postgresContext())
            {
                user.Name    = "Malik";
                user.SurName = "Chanbaz";
                db.User.Add(user);
                var count = db.SaveChanges();
                Assert.AreEqual(count, 1);
            }
        }
Exemple #18
0
        public virtual Result <User> Update(User model)
        {
            if (model == null)
            {
                return(Error <User>());
            }
            var user = _dbContext.Users.Where(x => x.Id == model.Id).FirstOrDefault();

            if (user == null)
            {
                return(Error <User>($"User with id = {model.Id} not found."));
            }
            if (model.BannedAt == null)
            {
                user.BannedAt = DateTime.Now;
            }
            else
            {
                user.BannedAt = null;
            }
            _dbContext.SaveChanges();
            return(Ok(user));
        }
Exemple #19
0
        public IActionResult DeleteCarrinho(int idcarrinho, int idUsuario)
        {
            try
            {
                var context        = new postgresContext();
                var carrinhoExiste = context.CarrinhoCompras.FirstOrDefault(x => x.IdCarrinhoCompras == idcarrinho && x.Finalizado == false && x.IdUsuario == idUsuario);

                if (carrinhoExiste != null)
                {
                    var produto = context.Produtos.FirstOrDefault(x => x.IdProduto == carrinhoExiste.IdProduto);
                    produto.Quantidade += carrinhoExiste.Quantidade;
                    context.Produtos.Update(produto);
                    context.CarrinhoCompras.Remove(carrinhoExiste);
                    context.SaveChanges();
                }


                context.Dispose();

                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.OK,
                    Body = "Produto Apagado",
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("[error] ConfigController - GetFurnaces - {0} - {1}",
                                  ex.Message,
                                  ex.StackTrace.Replace(Environment.NewLine, " "));
                return(new ResultWithBody
                {
                    Code = System.Net.HttpStatusCode.InternalServerError,
                    Body = "GetFurnaces - Fatal error retrieving furnaces configuration",
                });
            }
        }
        public void AddProject(ProjectIndexViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.AddProject == null)
            {
                throw new ArgumentNullException(nameof(model.AddProject));
            }
            if (model.AddProject.Name == null)
            {
                throw new ArgumentNullException(nameof(model.AddProject.Name));
            }
            if (model.AddProject.Name == "")
            {
                throw new ArgumentException($"{nameof(model.AddProject.Name)} must not be empty.");
            }

            using (var db = new postgresContext())
            {
                var userId = _userData.GetID();
                if (db.Project.Any(x => (x.Name == model.AddProject.Name) && (x.UserId == userId)))
                {
                    throw new ProjectAlreadyExistsException();
                }

                db.Project.Add(new Project()
                {
                    Name   = model.AddProject.Name,
                    UserId = userId
                });

                db.SaveChanges();
            }
        }
 /// <returns>
 ///     The number of state entries written to the database.
 /// </returns>
 public int AddGoal(Goal goal)
 {
     using var db = new postgresContext();
     db.Goal.Add(goal);
     return(db.SaveChanges());
 }
Exemple #22
0
 public virtual int SaveChanges()
 {
     return(_db.SaveChanges());
 }
 /// <returns>
 ///     The number of state entries written to the database.
 /// </returns>
 public int AddTransaction(Transaction transaction)
 {
     using var db = new postgresContext();
     db.Transaction.Add(transaction);
     return(db.SaveChanges());
 }
 /// <returns>
 ///     The number of state entries written to the database.
 /// </returns>
 public int AddCategory(Category category)
 {
     using var db = new postgresContext();
     db.Category.Add(category);
     return(db.SaveChanges());
 }
Exemple #25
0
 // POST /Test/
 //[HttpPost]
 public IActionResult Insert([FromBody] Test value)
 {
     testContext.Test.Add(value);
     testContext.SaveChanges();
     return(View());
 }
Exemple #26
0
        protected virtual void InitNpgSqlDb()
        {
            using (var db = new postgresContext())
            {
                for (var i = 1; i <= 10; i++)
                {
                    var name = $"{Name}_{i}";

                    var existing = db.Efcoretest
                                   .Where(e => e.Name == name)
                                   .FirstOrDefault();

                    var efCoreTestId = 0;

                    if (existing == null)
                    {
                        var inserted = db.Efcoretest.Add(new Efcoretest
                        {
                            Name         = name,
                            Createddate  = DateTime.Now,
                            Modifieddate = DateTime.Now
                        });

                        db.SaveChanges();

                        efCoreTestId = inserted.Entity.Id;
                        NpgSqlIds.Add(inserted.Entity.Id);
                    }
                    else
                    {
                        efCoreTestId = existing.Id;
                        NpgSqlIds.Add(existing.Id);
                    }

                    if (i > 5)
                    {
                        continue;
                    }

                    for (var j = 1; j <= 4; j++)
                    {
                        var childName = $"{Name}_{i}_{j}";

                        var existingChild = db.Efcoretestchild
                                            .Where(e => e.Name == childName)
                                            .FirstOrDefault();

                        if (existingChild == null)
                        {
                            var inserted = db.Add(new Efcoretestchild
                            {
                                Efcoretestid = efCoreTestId,
                                Name         = name,
                                Createddate  = DateTime.Now,
                                Modifieddate = DateTime.Now
                            });

                            db.SaveChanges();

                            NpgSqlCompositeIds.Add(new object[] { inserted.Entity.Id, efCoreTestId });
                        }
                        else
                        {
                            NpgSqlCompositeIds.Add(new object[] { existing.Id, efCoreTestId });
                        }
                    }
                }
            }
        }