//done
            public bool Delete(string email)
            {
                try
                {
                    using (var context = new OrderManagmentDbContext())
                    {
                        var query = context.Set<Customer>().SingleOrDefault(c => c.Email == email);
                        if (query != null)
                        {
                            query.IsActive = false;
                            context.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("No customer with this email not found");
                        }
                        return true;
                    }
                }
                catch (Exception e)
                {

                    return false;
                }

            }
Exemple #2
0
        public SearcBasket BasketSearch(int basketId)
        {
            var tempBasket = new SearcBasket();

            try
            {
                using (var context = new OrderManagmentDbContext())
                {
                    var basketquery = context.Set <Basket>().SingleOrDefault(b => b.BasketId == basketId);
                    if (basketquery != null)
                    {
                        tempBasket.BasketThatWeSearch = basketquery;
                        tempBasket.QueryResault       = true;
                        return(tempBasket);
                    }
                    else
                    {
                        tempBasket.BasketThatWeSearch = null;
                        tempBasket.QueryResault       = false;
                        return(tempBasket);
                    }
                }
            }
            catch (Exception e)
            {
                tempBasket.BasketThatWeSearch = null;
                tempBasket.QueryResault       = false;
                return(tempBasket);
            }
        }
            //done
            public bool Update(string email, string name, string address, DateTime birthDate, bool status)
            {
                try
                {
                    using (var context = new OrderManagmentDbContext())
                    {
                        var query = context.Set<Customer>().SingleOrDefault(c => c.Email == email);
                        if (query != null)
                        {
                            query.Email = email;
                            query.Name = name;
                            query.Address = address;
                            query.Dob = birthDate;
                            query.IsActive = status;
                            context.SaveChanges();
                        }
                        return true;
                    }
                }
                catch (Exception e)
                {

                    return false;
                }
            }
 //done
 public bool Register(string email, string name, string address, DateTime birthDate)
 {
     using (var context = new OrderManagmentDbContext())
     {
         var newCustomer = new Customer(email, name, address, true, birthDate);
         context.Add(newCustomer);
         context.SaveChanges();
         return true;
     }
 }
Exemple #5
0
 public bool CreateNewProduct(string name, decimal price, ProductCategoryId categoryid)
 {
     using (var context = new OrderManagmentDbContext())
     {
         var newProduct = new Product();
         newProduct.Name     = name;
         newProduct.Price    = price;
         newProduct.Category = categoryid;
         context.Add(newProduct);
         context.SaveChanges();
         return(true);
     }
 }
            //done
            public List<Customer> GetRecentCustomers()
            {

                using (var context = new OrderManagmentDbContext())
                {
                    var customerList = new List<Customer>();
                    customerList = context.Set<Customer>()
                        .Where(t => t.RegisterDay.AddDays(30) >= DateTime.Today)
                        .Where(t => t.IsActive == true)
                        .ToList();
                    //this return all the customer that have been registered the last month
                    return customerList;
                }

            }
 //done
 public bool DeleteBasket(string email, int basketId)
 {
     try
     {
         using (var context = new OrderManagmentDbContext())
         {
             var query = context.Set<Customer>().SingleOrDefault(c => c.Email == email);
             if (query != null)
             {
                 //var basketquery = context.Set<Basket>().SingleOrDefault(b => b.BasketId == basket.BasketId);
                 var basketRemover = context.Set<Basket>().SingleOrDefault(b => b.BasketId == basketId);
                 basketRemover.CustomerBelong = null;
                 context.Remove(basketRemover);
                 context.SaveChanges();
             }
             return true;
         }
     }
     catch (Exception e)
     {
         return false;
     }
 }
            //done
            public bool AddBasket(string email, Basket basket)
            {
                try
                {
                    using (var context = new OrderManagmentDbContext())
                    {
                        var query = context.Set<Customer>().SingleOrDefault(c => c.Email == email);
                        var basketquery = context.Set<Basket>().SingleOrDefault(b => b.BasketId == basket.BasketId);
                        if (query != null && basketquery != null)
                        {
                            basketquery.CustomerBelong = email;
                            context.SaveChanges();
                        }

                        return true;
                    }
                }
                catch (Exception e)
                {

                    return false;
                }
            }