예제 #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();
        }
예제 #2
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #3
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #4
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #5
0
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <postgresContext>()
                          .UseInMemoryDatabase(databaseName: "archerPostgresDatabase")
                          .Options;

            dbContext = new postgresContext(options);

            InitCompanyTable(dbContext);
            dbContext.SaveChanges();
        }
예제 #6
0
        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);
            }
        }
예제 #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,
                });
            }
        }
예제 #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();
     }
 }
예제 #9
0
        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));
        }
예제 #11
0
파일: DBHelper.cs 프로젝트: i-kurt/Syslog
 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();
         //...
     }
 }
예제 #12
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #13
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #14
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #15
0
파일: Model.cs 프로젝트: tiwatit/Database
 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);
     }
 }
예제 #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();
            }
        }
예제 #17
0
        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);
            }
        }
예제 #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));
        }
예제 #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",
                });
            }
        }
예제 #20
0
        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();
            }
        }
예제 #21
0
 /// <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());
 }
예제 #22
0
 public virtual int SaveChanges()
 {
     return(_db.SaveChanges());
 }
예제 #23
0
 /// <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());
 }
예제 #24
0
 /// <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());
 }
예제 #25
0
 // POST /Test/
 //[HttpPost]
 public IActionResult Insert([FromBody] Test value)
 {
     testContext.Test.Add(value);
     testContext.SaveChanges();
     return(View());
 }
예제 #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 });
                        }
                    }
                }
            }
        }