Beispiel #1
0
        public bool UpdateCustomer(Customer cus)
        {
            bool result = false;

            try
            {
                using (AccessoriesEntities _entityUpdate = new AccessoriesEntities())
                {
                    Customer _customer = _entityUpdate.Customers.Where(x => x.Id == cus.Id).Select(x => x).FirstOrDefault();
                    /*_customer.Id = cus.Id;*/
                    _customer.Name    = cus.Name;
                    _customer.Address = cus.Address;
                    _customer.Gender  = cus.Gender;
                    _customer.Phone   = cus.Phone;
                    _entityUpdate.SaveChanges();
                    result = true;
                }
            }

            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);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public bool UpdateStaff(Staff sf)
        {
            bool result = false;

            try
            {
                using (AccessoriesEntities _entityStaff = new AccessoriesEntities())
                {
                    Staff _staff = _entityStaff.Staffs.Where(x => x.Id == sf.Id).Select(x => x).FirstOrDefault();
                    /*_customer.Id = cus.Id;*/
                    _staff.Name      = sf.Name;
                    _staff.Phone     = sf.Phone;
                    _staff.Date_join = sf.Date_join;
                    _staff.Position  = sf.Position;
                    _staff.Salary    = sf.Salary;
                    _entityStaff.SaveChanges();
                    result = true;
                }
            }

            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);
                    }
                }
            }
            return(result);
        }
Beispiel #3
0
        public bool UpdateProduct(Product pro) // UpdateStudentDetails method for update a existing Record
        {
            bool result = false;

            try
            {
                using (AccessoriesEntities _entity = new AccessoriesEntities())
                {
                    Product _product = _entity.Products.Where(x => x.Id == pro.Id).Select(x => x).FirstOrDefault();
                    _product.ProductName = pro.ProductName;
                    _product.Provider    = pro.Provider;
                    _product.Price       = pro.Price;
                    _product.Quantity    = pro.Quantity;
                    _entity.SaveChanges();
                    result = true;
                }
            }
            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);
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
        public bool SaveProduct(Product pro)
        {
            bool result = false;

            using (AccessoriesEntities _entity = new AccessoriesEntities())
            {
                _entity.Products.Add(pro);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #5
0
        public bool SaveStaff(Staff sf)
        {
            bool result = false;

            using (AccessoriesEntities _entityStaff = new AccessoriesEntities())
            {
                _entityStaff.Staffs.Add(sf);
                _entityStaff.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #6
0
        public bool SaveCustomer(Customer cus)
        {
            bool result = false;

            using (AccessoriesEntities _entityCus = new AccessoriesEntities())
            {
                _entityCus.Customers.Add(cus);
                _entityCus.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #7
0
        public bool DeleteStaff(Staff sf)
        {
            bool result = false;

            using (AccessoriesEntities _entityStaff = new AccessoriesEntities())
            {
                Staff _staff = new Staff();
                _staff = _entityStaff.Staffs.Where(x => x.Id == sf.Id).Select(x => x).FirstOrDefault();
                _entityStaff.Staffs.Remove(_staff);
                _entityStaff.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #8
0
        public bool DeleteCustomer(Customer cus)
        {
            bool result = false;

            using (AccessoriesEntities _entity = new AccessoriesEntities())
            {
                Customer _customer = new Customer();
                _customer = _entity.Customers.Where(x => x.Id == cus.Id).Select(x => x).FirstOrDefault();
                _entity.Customers.Remove(_customer);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #9
0
        public bool DeleteProduct(Product pro) // UpdateStudentDetails method for update a existing Record
        {
            bool result = false;

            using (AccessoriesEntities _entity = new AccessoriesEntities())
            {
                Product _product = new Product();
                _product = _entity.Products.Where(x => x.Id == pro.Id).Select(x => x).FirstOrDefault();
                _entity.Products.Remove(_product);
                _entity.SaveChanges();
                result = true;
            }
            return(result);
        }