Exemplo n.º 1
0
        public static bool UpdateCustomer(AdminRegisterationDTO data)
        {
            int tempId = Int32.Parse(data.id);

            try
            {
                UjewelriesDBContext db = new UjewelriesDBContext();
                if (data.name != null & data.name != "")
                {
                    db.Costumers.Where(a => a.id == tempId).ToList()[0].name = data.name;
                }
                if (data.password != null & data.password != "")
                {
                    db.Costumers.Where(a => a.id == tempId).ToList()[0].password = data.password;
                }
                if (data.Admin != null & data.Admin != "")
                {
                    db.Costumers.Where(a => a.id == tempId).ToList()[0].is_manager = bool.Parse(data.Admin);
                }
                db.SaveChanges();
            }
            catch
            {
                Console.WriteLine("ERROR update failed");
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static bool CreateProduct(string id, string name, double price, double cost, int inv, int supplier_id, string category, bool is_active)
        {
            UjewelriesDBContext db = new UjewelriesDBContext();

            Product NewProduct = new Product();

            NewProduct.name        = name;
            NewProduct.price       = price;
            NewProduct.id          = id;
            NewProduct.cost        = cost;
            NewProduct.inv         = inv;
            NewProduct.category    = category;
            NewProduct.is_active   = is_active;
            NewProduct.supplier_id = supplier_id;
            try
            {
                db.Products.Add(NewProduct);
                db.SaveChanges();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
 public static bool UpdateCustomerToManager(int id)
 {
     try
     {
         UjewelriesDBContext db = new UjewelriesDBContext();
         db.Costumers.Where(a => a.id == id).ToList()[0].is_manager = true;
         db.SaveChanges();
     }
     catch
     {
         Console.WriteLine("ERROR update failed");
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public static bool UCTM(LoginDto data)// set admin account
        {
            try {
                UjewelriesDBContext db = new UjewelriesDBContext();
                int id = Int32.Parse(data.id);
                db.Costumers.Where(a => a.id == id).ToList()[0].is_manager = true;
                db.SaveChanges();
            }
            catch
            {
                Console.WriteLine("ERROR update failed");
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool DeleteCustomer(int id)
        {
            UjewelriesDBContext db = new UjewelriesDBContext();
            Costumer            SelectedCustomer = (Costumer)db.Costumers.Where(a => a.id == id).First();

            try
            {
                db.Costumers.Remove(SelectedCustomer);
                db.SaveChanges();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public static bool DeleteProduct(string id)
        {
            UjewelriesDBContext db = new UjewelriesDBContext();
            Product             SelectedProduct = (Product)db.Products.Where(a => a.id == id).First();

            try
            {
                db.Products.Remove(SelectedProduct);
                db.SaveChanges();
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Deleting false");
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        public static bool UpdateProduct(ProductDTO data)
        {
            try
            {
                UjewelriesDBContext db = new UjewelriesDBContext();
                if (data.name != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].name = data.name;
                }
                if (data.price != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].price = double.Parse(data.price);
                }
                if (data.cost != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].cost = double.Parse(data.cost);
                }
                if (data.inv != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].inv = Int32.Parse(data.inv);
                }
                if (data.supplier_id != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].supplier_id = Int32.Parse(data.supplier_id);
                }
                if (data.category != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].category = data.category;
                }
                if (data.is_active != "")
                {
                    db.Products.Where(a => a.id == data.id).ToList()[0].is_active = bool.Parse(data.is_active);
                }
                db.SaveChanges();
            }
            catch
            {
                Console.WriteLine("ERROR update failed");
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public static bool CreateCustomer(int id, string name, string password, bool is_maneger = false)
        {
            UjewelriesDBContext db          = new UjewelriesDBContext();
            Costumer            NewCustomer = new Costumer();

            NewCustomer.name       = name;
            NewCustomer.password   = password;
            NewCustomer.id         = id;
            NewCustomer.is_manager = is_maneger;
            try
            {
                db.Costumers.Add(NewCustomer);
                db.SaveChanges();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
            return(true);
        }