Ejemplo n.º 1
0
        /// <summary>
        /// delete a product by productid
        /// </summary>
        /// <param name="dbEntity">The db entity.</param>
        /// <param name="id">The id.</param>
        public bool Delete(TTAEntityContainer dbEntity, int id)
        {
            Product product = (from Product p in dbEntity.Products where p.ProductId == id select p).SingleOrDefault <Product>();

            dbEntity.Products.DeleteObject(product);
            dbEntity.SaveChanges();
            return(true);
        }
Ejemplo n.º 2
0
        public void Update(TTAEntityContainer dbEntity, Category category)
        {
            Category categoryDE = (from Category cate in dbEntity.Categories
                                   where cate.CategoryId == category.CategoryId
                                   select cate).SingleOrDefault <Category>();

            categoryDE.CategoryName = category.CategoryName;
            dbEntity.SaveChanges();
        }
Ejemplo n.º 3
0
        public void Delete(TTAEntityContainer dbEntity, int id)
        {
            Category categoryDE = (from Category category in dbEntity.Categories
                                   where category.CategoryId == id
                                   select category).SingleOrDefault <Category>();

            dbEntity.DeleteObject(categoryDE);
            dbEntity.SaveChanges();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Insert a product
        /// </summary>
        /// <param name="dbEntity">The db entity.</param>
        /// <param name="Product">The product.</param>
        public bool Insert(TTAEntityContainer dbEntity, ProductBE Product)
        {
            ProductTranslator productTranslator = new ProductTranslator();
            Product           productDE         = productTranslator.Translate(Product);

            dbEntity.AddToProducts(productDE);
            dbEntity.SaveChanges();
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inserts order.
        /// </summary>
        /// <param name="DBEntity">The TTAEntityContainer.</param>
        /// <param name="order">The order.</param>
        public OrderBE Insert(TTAEntityContainer DBEntity, OrderBE orderBE)
        {
            OrderTranslator translator = new OrderTranslator();
            Order           order      = null;

            if (orderBE != null)
            {
                order = translator.Translate(orderBE);
                DBEntity.AddToOrders(order);
                DBEntity.SaveChanges();
            }
            return(translator.Translate(order));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Insert a customer
        /// </summary>
        /// <param name="dbEntity"> Database Entity Container</param>
        /// <param name="customerBE">Customer DataEntity</param>
        public bool Insert(TTAEntityContainer dbEntity, CustomerBE customerBE)
        {
            dbEntity.AddToCustomers((new CustomerTranslator()).Translate(customerBE));
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// update product
        /// </summary>
        /// <param name="dbEntity">The db entity.</param>
        /// <param name="pro">The pro.</param>
        public bool Update(TTAEntityContainer dbEntity, ProductBE pro)
        {
            ProductTranslator productTranslator = new ProductTranslator();
            Product           productDE         = productTranslator.Translate(pro);

            Product product = (from Product p in dbEntity.Products where p.ProductId == productDE.ProductId select p).SingleOrDefault <Product>();

            product.ProductName  = productDE.ProductName;
            product.ProductPrice = productDE.ProductPrice;
            product.CategoryId   = productDE.CategoryId;

            dbEntity.SaveChanges();
            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// insert a piece of orderdetails record by new inserted orderid linked by its corresponding createdtime
        /// </summary>
        /// <param name="orderdetails"></param>
        public bool Insert(OrderDetailsBE orderdetailsBE)
        {
            TTAEntityContainer dbEntity     = new TTAEntityContainer();
            OrderDetails       orderdetails = new OrderDetailsTranslator().Translate(orderdetailsBE);

            dbEntity.AddToOrderDetails(orderdetails);
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Update a customer
        /// </summary>
        /// <param name="dbEntity">Database Entity Container</param>
        /// <param name="cus">Custome Bussiness Entity</param>
        public bool Update(TTAEntityContainer dbEntity, CustomerBE cus)
        {
            Customer customer = (from Customer c in dbEntity.Customers where c.CustomerId == cus.CustomerId select c).SingleOrDefault <Customer>();

            customer.CustomerName   = cus.CustomerName;
            customer.CustomerGender = cus.CustomerGender;
            customer.AddressId      = cus.Address.AddressId;
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// delete a piece of orderdetail by its corresponding orderdetailid
        /// </summary>
        /// <param name="id"></param>
        public bool Delete(int id)
        {
            TTAEntityContainer dbEntity     = new TTAEntityContainer();
            OrderDetails       orderdetails = (from OrderDetails o in dbEntity.OrderDetails
                                               where o.OrderDetailId == id
                                               select o).SingleOrDefault <OrderDetails>();

            dbEntity.OrderDetails.DeleteObject(orderdetails);
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Convert order status into delete status.
        /// </summary>
        /// <param name="dBEntity">The entity frame work data entity.</param>
        /// <param name="id">The id.</param>
        public bool Delete(TTAEntityContainer dBEntity, int id)
        {
            int result = initialData;

            if (id >= 0)
            {
                Order  temp   = this.GetDEById(dBEntity, id);
                Status status = Status.Deleted;
                temp.StatusId = (int)status;
                result        = dBEntity.SaveChanges();
            }
            if (result != initialData)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// update a piece of orderdetail by its corresponding orderdetailid
        /// </summary>
        /// <param name="id"></param>
        public bool Close(OrderDetailsBE odBE)
        {
            TTAEntityContainer dbEntity     = new TTAEntityContainer();
            OrderDetails       orderdetails = (from OrderDetails o in dbEntity.OrderDetails
                                               where o.OrderDetailId == odBE.OrderDetailId
                                               select o).SingleOrDefault <OrderDetails>();

            orderdetails.IsDeleted = true;
            //dbEntity.OrderDetails.DeleteObject(orderdetails);
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Delete a customer
        /// </summary>
        /// <param name="dbEntity">Database Entity Container</param>
        /// <param name="id">The id of a customer</param>
        public bool Delete(TTAEntityContainer dbEntity, int id)
        {
            Customer customer = (from Customer c in dbEntity.Customers where c.CustomerId == id select c).SingleOrDefault <Customer>();// FirstOrDefault

            if (customer.Order.Count > 0)
            {
                throw new Exception("This Customer is referred by Order and you can not delete it");
            }
            dbEntity.Customers.DeleteObject(customer);
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Closes order.
        /// </summary>
        /// <param name="dBEntity">The entity frame work data entity.</param>
        /// <param name="id">The id.</param>
        public bool Close(TTAEntityContainer dBEntity, int id)
        {
            Status status = Status.Closed;
            Order  temp   = new Order();
            int    result = initialData;

            if (id > 0)
            {
                temp          = this.GetDEById(dBEntity, id);
                temp.StatusId = (int)status;
                result        = dBEntity.SaveChanges();
            }
            if (result != initialData)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// update a piece of orderdetail by its corresponding orderdetailid
        /// </summary>
        /// <param name="od"></param>
        public bool Update(OrderDetailsBE odBE)
        {
            TTAEntityContainer dbEntity     = new TTAEntityContainer();
            OrderDetails       orderdetails = (from OrderDetails o in dbEntity.OrderDetails
                                               where o.OrderDetailId == odBE.OrderDetailId
                                               select o).SingleOrDefault <OrderDetails>();

            orderdetails.ProductId  = odBE.ProductId;
            orderdetails.Quantity   = odBE.Quantity;
            orderdetails.TotalPrice = odBE.TotalPrice;
            int result = dbEntity.SaveChanges();

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates order.
        /// </summary>
        /// <param name="dBEntity">The entity frame work data entity.</param>
        /// <param name="orderBE">The order.</param>
        public bool Update(TTAEntityContainer dBEntity, OrderBE orderBE)
        {
            int result = initialData;

            if (orderBE != null)
            {
                Order temp = this.GetDEById(dBEntity, orderBE.OrderId);
                temp.StatusId               = orderBE.OrderStatusId;
                temp.OrderStatus.StatusId   = orderBE.OrderStatus.OrderStatusId;
                temp.OrderStatus.StatusName = orderBE.OrderStatus.StatusName;
                result = dBEntity.SaveChanges();
            }
            if (result != initialData)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Deletes order from database according to customerID.
        /// </summary>
        /// <param name="dBEntity">The data container.</param>
        /// <param name="customerId">The customer id.</param>
        /// <returns></returns>
        public bool DeleteFromDB(TTAEntityContainer dBEntity, int customerId)
        {
            int result = initialData;

            if (customerId > 0)
            {
                List <Order> list = (from Order order in dBEntity.Orders where order.CustomerId == customerId select order).ToList();
                foreach (Order order in list)
                {
                    Order temp = order;
                    dBEntity.Orders.DeleteObject(temp);
                }
                dBEntity.SaveChanges();
            }
            if (result != initialData)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 18
0
 public void Insert(TTAEntityContainer dbEntity, Category category)
 {
     dbEntity.Categories.AddObject(category);
     dbEntity.SaveChanges();
 }