Example #1
0
        internal static void DeleteUser(UserViewModel user)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var userToDelete =
                from utd in entity.Users
                where utd.Username.Contains(user.Username)
                select utd;

            if (userToDelete.Count() != 0)
            {
                foreach (var item in userToDelete)
                {
                    entity.Users.Remove(item);
                }

                entity.SaveChanges();

                MessageBox.Show("User " + user.Username + " deleted", "Confirmation", MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show("User " + user.Username + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }
        internal static void DeleteProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToDelete =
                from ptd in entity.Products
                where ptd.Name.Contains(product.Name) && ptd.Vendor1.Name.Contains(product.Vendor.Name)
                select ptd;

            if (productToDelete.Count() != 0)
            {
                foreach (var item in productToDelete)
                {
                    entity.Products.Remove(item);
                }

                MessageBox.Show("Product " + product.Name + " deleted", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #3
0
        internal static void AddUser(UserViewModel user)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var userToAdd =
                from uta in entity.Users
                where uta.Username==user.Username
                select uta;

            if (userToAdd.Count()!=0)
            {
                MessageBox.Show("User " + user.Username + " exists", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                entity.Users.Add(new User()
                                     {
                                         Username = user.Username,
                                         Password = Convert.ToBase64String(System.Security.Cryptography.MD5.Create().
                                                    ComputeHash(Encoding.UTF8.GetBytes(user.Password))),
                                         Rank = user.Rank
                                     });

                    entity.SaveChanges();
                    MessageBox.Show("User " + user.Username + " added", "Confirmation", MessageBoxButton.OK);
            }
        }
        internal static void DeleteVendor(VendorViewModel vendor)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var vendorToDelete =
                (from vtd in entity.Vendors
                where vtd.Name == vendor.Name
                select vtd).First();

            if (vendorToDelete!=null)
            {
                var del = vendorToDelete.Products;
                foreach (var item in del.ToList())
                {
                    entity.Products.Remove(item);
                }

                entity.Vendors.Remove(vendorToDelete);

                MessageBox.Show("Vendor " + vendor.Name + " deleted", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Vendor " + vendor.Name + " doesn't exist", "Confirmation", MessageBoxButton.OK);
            }
        }
        internal static void AddVendor(VendorViewModel vendor)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var vendorToAdd =
                from vta in entity.Vendors
                where vta.Name.Contains(vendor.Name)
                select vta;

            if (vendorToAdd.Count()!=0)
            {
                MessageBox.Show("Vendor " + vendor.Name + " exists", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                entity.Vendors.Add(new Vendor()
                                   {
                                       Name = vendor.Name
                                   });

                MessageBox.Show("Vendor " + vendor.Name + " added", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
        }
        internal static void AddProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToAdd =
                from pta in entity.Products
                where ((pta.Name == product.Name) && (pta.Vendor1.Name == product.Vendor.Name))
                select pta;

            if (productToAdd.Count() != 0)
            {

                UpdateProduct(product);

            }
            else
            {
                var productVendor =
                    (from pv in entity.Vendors
                    where pv.Name == product.Vendor.Name
                    select pv).First();

                entity.Products.Add(new Product()
                                    {
                                        Name = product.Name,
                                        BuyPrice = product.BuyPrice,
                                        SellPrice = product.SellPrice,
                                        Quantity = product.Quantity,
                                        DayOfPurchase = DateTime.Now,
                                        Vendor = productVendor.VendorID
                                    });

                MessageBox.Show("Product " + product.Name + " added!", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
        }
        internal static void UseProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToUse =
                    from ptu in entity.Products
                    where ptu.Name.Contains(product.Name) && ptu.Vendor1.Name.Contains(product.Vendor.Name)
                    select ptu;

            if (productToUse.Count() != 0)
            {
                foreach (var item in productToUse)
                {
                    item.Quantity -= product.Quantity;
                    item.DayOfSale = DateTime.Now;
                    if (item.SaleQuantity == null)
                    {
                        item.SaleQuantity = product.Quantity;
                    }
                    else
                    {
                        item.SaleQuantity += product.Quantity;
                    }
                }

                MessageBox.Show("Product " + product.Name + " used", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        internal static void UpdateProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToUpdate =
                    from ptu in entity.Products
                    where ptu.Name.Contains(product.Name) && ptu.Vendor1.Name.Contains(product.Vendor.Name)
                    select ptu;

            if (productToUpdate.Count() != 0)
            {
                foreach (var item in productToUpdate)
                {
                    item.Quantity += product.Quantity;
                    item.BuyPrice = product.BuyPrice;

                }

                MessageBox.Show("Product " + product.Name + " updated", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }