Beispiel #1
0
 /// <summary>
 /// translate OrderDetails type to OrderDetailsBE type
 /// </summary>
 /// <param name="orderdetails"></param>
 /// <returns></returns>
 public OrderDetailsBE Translate(OrderDetails orderdetails)
 {
     if (orderdetails != null)
     {
         OrderDetailsBE orderdetailsBE = new OrderDetailsBE()
         {
             OrderDetailId = orderdetails.OrderDetailId,
             OrderId       = orderdetails.OrderId,
             ProductId     = orderdetails.ProductId,
             Quantity      = orderdetails.Quantity,
             TotalPrice    = orderdetails.TotalPrice,
             IsDeleted     = orderdetails.IsDeleted,
             Order         = new OrderTranslator().Translate(orderdetails.Order),
             Product       = new ProductTranslator().Translate(orderdetails.Product)
         };
         if (orderdetails.Order != null)
         {
             OrderTranslator orderTranslator = new OrderTranslator();
             orderdetailsBE.Order = orderTranslator.Translate(orderdetails.Order);
         }
         if (orderdetails.Product != null)
         {
             ProductTranslator productTranslator = new ProductTranslator();
             orderdetailsBE.Product = productTranslator.Translate(orderdetails.Product);
         }
         return(orderdetailsBE);
     }
     else
     {
         return(null);
     }
 }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// get product by productid
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public ProductBE GetById(int id)
        {
            this.DBEntity = new TTAEntityContainer();
            ProductTranslator productTranslator = new ProductTranslator();

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

            return(productTranslator.Translate(product));
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// GetAllProducts
        /// </summary>
        /// <returns></returns>
        public List <ProductBE> GetAllProducts()
        {
            this.DBEntity = new TTAEntityContainer();
            ProductTranslator productTranslator = new ProductTranslator();

            List <Product>   list          = (from Product Product in DBEntity.Products select Product).ToList <Product>();
            List <ProductBE> listProductBE = new List <ProductBE>();

            foreach (Product productDE in list)
            {
                ProductBE productBE = productTranslator.Translate(productDE);
                listProductBE.Add(productBE);
            }
            return(listProductBE);
        }