コード例 #1
0
        public OrderLine CreateOrderLine(OrderLine newOrder)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                orderLine ordLine = new orderLine()
                {
                    // id = newOrder.OrderLineId,
                    orderId   = 1,
                    productId = newOrder.ProductID,
                    quantity  = newOrder.Quantity,
                    price     = newOrder.Price,
                };

                dbEntities.OrderLine.Add(ordLine);
                dbEntities.SaveChanges();

                OrderLine returnOrder = new OrderLine();
                //   returnOrder = null;

                returnOrder.OrderLineId = ordLine.id;
                returnOrder.ProductID   = (int)ordLine.productId;
                returnOrder.OrderID     = (int)ordLine.orderId;
                returnOrder.Quantity    = ordLine.quantity;
                returnOrder.Price       = ordLine.price;



                return(returnOrder);
            }
        }
コード例 #2
0
        public bool CreateDisaster(DisasterB newDisaster)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Disasters.Any(o => o.disasterName == newDisaster.Name))
                {
                    return(false);
                }



                disaster disaster = new disaster()
                {
                    disasterName = newDisaster.Name,
                    categoryId   = newDisaster.CategoryId,
                    description  = newDisaster.Description,
                    priority     = newDisaster.Priority,
                    region       = newDisaster.Region,
                    victims      = newDisaster.Victims,
                    accountId    = newDisaster.DisasterBankAccountId,
                };

                dbEntities.Disasters.Add(disaster);


                dbEntities.SaveChanges();
            }
            return(true);
        }
コード例 #3
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public UserB GetUserByName(string name)
        {
            UserB userData = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var user = (from p in NWEntities.Ausers
                            where p.name == name
                            select p).FirstOrDefault();
                if (user != null)
                {
                    userData = new UserB()
                    {
                        UserId        = user.id,
                        Name          = user.name,
                        Email         = user.email,
                        Address       = user.address,
                        Phone         = user.phoneno,
                        Salt          = user.salt,
                        Password      = user.password,
                        BankAccountId = (int)user.accountId,
                        TypeOfUser    = user.typeOfUser,
                    }
                }
                ;
            }
            return(userData);
        }
コード例 #4
0
        public DisasterB GetDisasterByName(string name)
        {
            DisasterB disData = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var dis = (from p in NWEntities.Disasters
                           where p.disasterName == name
                           select p).FirstOrDefault();
                if (dis != null)
                {
                    disData = new DisasterB()
                    {
                        DisasterId            = dis.id,
                        Name                  = dis.disasterName,
                        Description           = dis.description,
                        Priority              = dis.priority,
                        Region                = dis.region,
                        Victims               = dis.victims,
                        CategoryId            = (int)dis.categoryId,
                        DisasterBankAccountId = (int)dis.accountId,
                    }
                }
                ;
            }
            return(disData);
        }
コード例 #5
0
        public bool Update(BankAccountB bankAccountBefore)
        {
            bool update = true;

            using (var NWEntities = new SaveWorldEntities())
            {
                var bankId         = bankAccountBefore.AccountId;
                var accountForSave = (from p in NWEntities.BankAccounts
                                      where p.id == bankId
                                      select p).FirstOrDefault();

                accountForSave.accountNo  = bankAccountBefore.AccountNo;
                accountForSave.amount     = bankAccountBefore.Amount;
                accountForSave.ccv        = bankAccountBefore.CCV;
                accountForSave.expiryDate = bankAccountBefore.ExpiryDate;
                accountForSave.rowVersion = bankAccountBefore.RowVersion;

                NWEntities.BankAccounts.Attach(accountForSave);
                NWEntities.Entry(accountForSave).State = System.Data.Entity.EntityState.Modified;
                try
                {
                    NWEntities.SaveChanges();
                }
                catch
                {
                    update = false;
                }
            }
            return(update);
        }
コード例 #6
0
        public BankAccountB GetBankAccountById(int id)
        {
            BankAccountB accountData = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var account = (from p in NWEntities.BankAccounts
                               where p.id == id
                               select p).FirstOrDefault();
                if (account != null)
                {
                    accountData = new BankAccountB()
                    {
                        AccountId  = account.id,
                        AccountNo  = account.accountNo,
                        ExpiryDate = account.expiryDate,
                        CCV        = account.ccv,
                        Amount     = account.amount,
                        RowVersion = account.rowVersion,
                    }
                }
                ;
            }
            return(accountData);
        }
コード例 #7
0
        public bool UpdateProduct(ProductB product)
        {
            var updated = true;

            using (var NWEntities = new SaveWorldEntities())
            {
                var productId       = product.ProductId;
                var productDatabase =
                    (from p
                     in NWEntities.Products
                     where p.id == productId
                     select p).FirstOrDefault();

                if (productDatabase == null)
                {
                    throw new Exception("No product with ID " + product.ProductId);
                }
                productDatabase.productName = product.ProductName;
                productDatabase.price       = product.Price;
                productDatabase.description = product.ProductDescription;
                productDatabase.minStock    = product.Stock;


                NWEntities.Products.Attach(productDatabase);

                NWEntities.Entry(productDatabase).State = System.Data.Entity.EntityState.Modified;

                var num = NWEntities.SaveChanges();
            }
            return(updated);
        }
コード例 #8
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public UserB CheckLogin(string userEmail, string password)
        {
            UserB userCorrect = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var user = NWEntities.Ausers.FirstOrDefault(u => u.email == userEmail);
                if (user.password == Hasher(password + user.salt))
                {
                    if (user != null)
                    {
                        userCorrect = new UserB()
                        {
                            UserId        = user.id,
                            Name          = user.name,
                            Password      = user.password,
                            Salt          = user.salt,
                            Email         = user.email,
                            Address       = user.address,
                            Phone         = user.phoneno,
                            TypeOfUser    = user.typeOfUser,
                            BankAccountId = (int)user.accountId,
                        };
                    }
                }
            }
            return(userCorrect);
        }
コード例 #9
0
        public void UpdateOrderLine(OrderLine orderLine)
        {
            using (var NWEntities = new SaveWorldEntities())
            {
                var orderLineId       = orderLine.OrderLineId;
                var orderLineDatabase =
                    (from p
                     in NWEntities.OrderLine
                     where p.id == orderLineId
                     select p).FirstOrDefault();

                if (orderLineDatabase == null)
                {
                    throw new Exception("No orderLine with ID " +
                                        orderLine.OrderLineId);
                }

                orderLineDatabase.id        = orderLine.OrderLineId;
                orderLineDatabase.orderId   = orderLine.OrderID;
                orderLineDatabase.price     = orderLine.Price;
                orderLineDatabase.productId = orderLine.ProductID;
                orderLineDatabase.quantity  = orderLine.Quantity;


                NWEntities.OrderLine.Attach(orderLineDatabase);


                NWEntities.Entry(orderLineDatabase).State = System.Data.Entity.EntityState.Modified;


                var num = NWEntities.SaveChanges();
            }
        }
コード例 #10
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public bool CheckEmailIfExists(string email)
        {
            bool exist = false;

            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Ausers.Any(o => o.email == email))
                {
                    exist = true;
                }
            }
            return(exist);
        }
コード例 #11
0
        public bool CheckNameIfExists(string name)
        {
            bool exist = false;

            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Disasters.Any(o => o.disasterName == name))
                {
                    exist = true;
                }
            }
            return(exist);
        }
コード例 #12
0
        public bool CheckIfNameExists(string name)
        {
            bool exists = false;

            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Products.Any(pr => pr.productName == name))
                {
                    exists = true;
                }
            }
            return(exists);
        }
コード例 #13
0
        public void DeleteProduct(int id)
        {
            using (var NWEntities = new SaveWorldEntities())
            {
                var product = (from p in NWEntities.Products
                               where p.id == id
                               select p).FirstOrDefault();
                if (product != null)

                {
                    NWEntities.Products.Remove(product);
                    NWEntities.SaveChanges();
                }
                ;
            }
        }
コード例 #14
0
        public bool CheckBankAccountw(int accNo, int CCV)
        {
            using (var NWEntities = new SaveWorldEntities())
            {
                bankAccount accountValid = NWEntities.BankAccounts
                                           .FirstOrDefault(u => u.accountNo == accNo &&
                                                           u.ccv == CCV);

                if (accountValid != null)
                {
                    correct = true;
                }
            }

            return(correct);
        }
コード例 #15
0
        public void DeleteDisaster(int id)
        {
            using (var NWEntities = new SaveWorldEntities())
            {
                var disaster = (from p in NWEntities.Disasters
                                where p.id == id
                                select p).FirstOrDefault();
                if (disaster != null)

                {
                    NWEntities.Disasters.Remove(disaster);
                    NWEntities.SaveChanges();
                }
                ;
            }
        }
コード例 #16
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public int GetUserIDByName(string name)
        {
            int id = 0;

            using (var NWEntities = new SaveWorldEntities())
            {
                var user = (from p in NWEntities.Ausers
                            where p.name == name
                            select p).FirstOrDefault();
                if (user != null)
                {
                    id = user.id;
                }
            }
            return(id);
        }
コード例 #17
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public void CreateUser(UserB newUser)
        {
            string salted   = SaltGenerator(10);
            string passHash = Hasher(newUser.Password + salted);

            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Ausers.Any(o => o.email == newUser.Email))
                {
                    return;
                }



                auser user = new auser()
                {
                    name       = newUser.Name,
                    email      = newUser.Email,
                    password   = passHash,
                    salt       = salted,
                    address    = newUser.Address,
                    phoneno    = newUser.Phone,
                    typeOfUser = 1,
                    accountId  = newUser.BankAccountId,
                };

                dbEntities.Ausers.Add(user);

                try
                {
                    dbEntities.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                }
            }
        }
コード例 #18
0
        public int CreateOrderAndReturnId(Order newOrder)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                tbOrder order = new tbOrder()
                {
                    userId = newOrder.UserId,
                    date   = newOrder.OrderDate,
                };

                dbEntities.TbOrder.Add(order);

                dbEntities.SaveChanges();

                return(order.id);
            }
        }
コード例 #19
0
        public void ReturnStock(int idOfProduct, int returnQuantity)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                var product = (from p in dbEntities.Products
                               where p.id == idOfProduct
                               select p).FirstOrDefault();
                if (product != null)
                {
                    product.minStock += returnQuantity;
                }



                dbEntities.SaveChanges();
            }
        }
コード例 #20
0
        public void RemoveStockFromProduct(int id, int removeQuantity)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                var product = (from p in dbEntities.Products
                               where p.id == id
                               select p).FirstOrDefault();
                if (product != null)
                {
                    product.minStock -= removeQuantity;
                }



                dbEntities.SaveChanges();
            }
        }
コード例 #21
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public int DeleteUser(int id)
        {
            using (var NWEntities = new SaveWorldEntities())
            {
                var usr = (from p in NWEntities.Ausers
                           where p.id == id
                           select p).FirstOrDefault();
                if (usr != null)

                {
                    NWEntities.Ausers.Remove(usr);
                    NWEntities.SaveChanges();
                }
                ;
            }

            return(id);
        }
コード例 #22
0
        public List <Category> GetAllCategories()
        {
            List <Category> list = new List <Category>();

            using (SaveWorldEntities NWEntities = new SaveWorldEntities())
            {
                var ptx     = (from r in NWEntities.Category select r);
                var allRows = NWEntities.Category.ToList();

                for (int i = 0; i < allRows.Count; i++)
                {
                    Category cat = new Category();
                    cat.CatogoryId     = allRows[i].id;
                    cat.NameOfCategory = allRows[i].nameOfCategory;

                    list.Add(cat);
                }
            }
            return(list);
        }
コード例 #23
0
        public int RemoveOrderLineAndReturnStock(int idToRemoveOrderLine)
        {
            int stock = 0;

            using (var NWEntities = new SaveWorldEntities())
            {
                var orderLine = (from p in NWEntities.OrderLine
                                 where p.id == idToRemoveOrderLine
                                 select p).FirstOrDefault();
                if (orderLine != null)

                {
                    stock = orderLine.quantity;
                    NWEntities.OrderLine.Remove(orderLine);
                    NWEntities.SaveChanges();
                }
                ;
            }
            return(stock);
        }
コード例 #24
0
        public Category GetCategoryByName(string name)
        {
            Category category = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var cat = (from p in NWEntities.Category
                           where p.nameOfCategory == name
                           select p).FirstOrDefault();
                if (cat != null)
                {
                    category = new Category()
                    {
                        CatogoryId     = cat.id,
                        NameOfCategory = cat.nameOfCategory,
                    }
                }
                ;
            }
            return(category);
        }
コード例 #25
0
        public string GetCategoryNameById(int id)
        {
            Category category = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var cat = (from p in NWEntities.Category
                           where p.id == id
                           select p).FirstOrDefault();
                if (cat != null)
                {
                    category = new Category()
                    {
                        CatogoryId     = cat.id,
                        NameOfCategory = cat.nameOfCategory,
                    }
                }
                ;
            }
            return(category.NameOfCategory);
        }
コード例 #26
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        /* public bool IsCookieValid(string cookieId)
         * {
         *   CoreValidator.ThrowIfNullOrEmpty(cookieId, nameof(cookieId));
         *   using (var db = new AuctionContext())
         *   {
         *       return db.Users.Any(u => u.RememberToken == cookieId);
         *   }
         * }
         */

        public bool UpdateUser(UserB user)
        {
            string salted   = SaltGenerator(10);
            string passHash = Hasher(user.Password + salted);

            var updated = true;

            using (var NWEntities = new SaveWorldEntities())
            {
                var userId       = user.UserId;
                var userDatabase =
                    (from p
                     in NWEntities.Ausers
                     where p.id == userId
                     select p).FirstOrDefault();

                if (userDatabase == null)
                {
                    throw new Exception("No user with ID " +
                                        user.UserId);
                }

                userDatabase.name      = user.Name;
                userDatabase.email     = user.Email;
                userDatabase.password  = passHash;
                userDatabase.salt      = salted;
                userDatabase.phoneno   = user.Phone;
                userDatabase.address   = user.Address;
                userDatabase.accountId = user.BankAccountId;

                NWEntities.Ausers.Attach(userDatabase);


                NWEntities.Entry(userDatabase).State = System.Data.Entity.EntityState.Modified;


                var num = NWEntities.SaveChanges();
            }
            return(updated);
        }
コード例 #27
0
        public List <ProductB> GetAllProduct()
        {
            // var db = new SaveWorldEntities();
            //return db.Products.ToList();
            List <ProductB> list = new List <ProductB>();

            using (SaveWorldEntities NWEntities = new SaveWorldEntities())
            {
                var ptx     = (from r in NWEntities.Products select r);
                var allRows = NWEntities.Products.ToList();

                for (int i = 0; i < allRows.Count; i++)
                {
                    ProductB pro = new ProductB();
                    pro.ProductName        = allRows[i].productName;
                    pro.ProductId          = allRows[i].id;
                    pro.ProductDescription = allRows[i].description;
                    pro.Price = allRows[i].price;
                    list.Add(pro);
                }
            }
            return(list);
        }
コード例 #28
0
ファイル: UserDAL.cs プロジェクト: jankalasnikov/SaveTheWorld
        public List <UserB> GetAllUsers()
        {
            List <UserB> list = new List <UserB>();

            using (SaveWorldEntities NWEntities = new SaveWorldEntities())
            {
                var ptx     = (from r in NWEntities.Ausers select r);
                var allRows = NWEntities.Ausers.ToList();

                for (int i = 0; i < allRows.Count; i++)
                {
                    UserB usr = new UserB();
                    usr.Name          = allRows[i].name;
                    usr.UserId        = allRows[i].id;
                    usr.Email         = allRows[i].email;
                    usr.Password      = allRows[i].password;
                    usr.Phone         = allRows[i].phoneno;
                    usr.BankAccountId = (int)allRows[i].accountId;
                    usr.Address       = allRows[i].address;
                    list.Add(usr);
                }
            }
            return(list);
        }
コード例 #29
0
        public ProductB GetProductByName(string name)
        {
            ProductB prodData = null;

            using (var NWEntities = new SaveWorldEntities())
            {
                var product = (from p in NWEntities.Products
                               where p.productName == name
                               select p).FirstOrDefault();
                if (product != null)
                {
                    prodData = new ProductB()
                    {
                        ProductId          = product.id,
                        ProductName        = product.productName,
                        ProductDescription = product.description,
                        Price = product.price,
                        Stock = product.minStock,
                    }
                }
                ;
            }
            return(prodData);
        }
コード例 #30
0
        public bool CreateProduct(ProductB newProduct)
        {
            using (SaveWorldEntities dbEntities = new SaveWorldEntities())
            {
                if (dbEntities.Products.Any(o => o.productName == newProduct.ProductName))
                {
                    return(false);
                }


                product Product = new product()
                {
                    productName = newProduct.ProductName,
                    description = newProduct.ProductDescription,
                    price       = newProduct.Price,
                    minStock    = newProduct.Stock,
                };

                dbEntities.Products.Add(Product);

                dbEntities.SaveChanges();
            }
            return(true);
        }