/// <summary> /// Excute the procedure to obtain search results and return them in form of a List<OrderSearchResult> object. /// </summary> /// <param name="dbEntity"></param> /// <param name="customerName"></param> /// <param name="oper"></param> /// <param name="orderDate"></param> /// <param name="productName"></param> /// <param name="sortExpression"></param> /// <param name="sortDirection"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> private List <OrderSearchResult> GetOrderSearchResults(TTAEntityContainer dbEntity, string customerName, string startDate, string endDate, string productName, string sortExpression, string sortDirection, int pageStart, int pageEnd, out int rowCount) { DateTime sDate = new DateTime(1990, 1, 1); DateTime eDate = DateTime.Now; List <OrderSearchResult> orderSRDEList = new List <OrderSearchResult>(); System.Data.Objects.ObjectParameter rowNum = new System.Data.Objects.ObjectParameter("RowNum", typeof(int)); if (!string.IsNullOrEmpty(startDate)) { sDate = Convert.ToDateTime(startDate); } if (!string.IsNullOrEmpty(endDate)) { eDate = Convert.ToDateTime(endDate); } if (sDate > eDate) { DateTime dateTemp = new DateTime(); dateTemp = sDate; sDate = eDate; eDate = dateTemp; } orderSRDEList = (from u in dbEntity.SearchResults(customerName, sDate, eDate, productName, sortExpression, sortDirection, pageStart, pageEnd, rowNum) select u).ToList <OrderSearchResult>(); rowCount = (int)rowNum.Value; return(orderSRDEList); }
/// <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); }
public Category GetById(TTAEntityContainer dbEntity, int id) { Category categoryDE = (from Category category in dbEntity.Categories where category.CategoryId == id select category).SingleOrDefault <Category>(); return(categoryDE); }
/// <summary> /// Gets the order details by id. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public int CountOrderDetailsByProductId(int id) { this.DBEntity = new TTAEntityContainer(); int orderDetailsNum = (from OrderDetails p in DBEntity.OrderDetails where p.ProductId == id select p).Count(); return(orderDetailsNum); }
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(); }
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(); }
/// <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); }
/// <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)); }
/// <summary> /// Gets order data entity by id. /// </summary> /// <param name="dBEntity">The d B entity.</param> /// <param name="id">The id.</param> /// <returns></returns> public Order GetDEById(TTAEntityContainer dBEntity, int id) { Order order = null; if (id > 0) { order = (from Order o in dBEntity.Orders where o.OrderId == id select o).SingleOrDefault <Order>(); } return(order); }
/// <summary> /// Gets order by id. /// </summary> /// <param name="dBEntity">The entity frame work data entity.</param> /// <param name="id">The id.</param> /// <returns></returns> public OrderBE GetById(TTAEntityContainer dBEntity, int id) { Order order = null; OrderTranslator translator = new OrderTranslator(); if (id >= 0) { order = (from Order o in dBEntity.Orders where o.OrderId == id select o).SingleOrDefault <Order>(); } return(translator.Translate(order)); }
public void DeleteTest() { OrderManager target = new OrderManager(); // TODO: Initialize to an appropriate value TTAEntityContainer dBEntity = new TTAEntityContainer(); // TODO: Initialize to an appropriate value int id = 1; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.Delete(dBEntity, id); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// Get all the addresses /// </summary> /// <returns>Get all the customers in a list</returns> public List <AddressBE> GetAllAddresses() { TTAEntityContainer _entity = new TTAEntityContainer(); List <AddressBE> listAddressBE = new List <AddressBE>(); List <Address> listAddressDE = (from Address in _entity.Addresses select Address).ToList <Address>(); foreach (Address address in listAddressDE) { AddressBE addressBE = new AddressTranslator().Translate(address); listAddressBE.Add(addressBE); } return(listAddressBE); }
/// <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)); }
/// <summary> /// Get all customers /// </summary> /// <returns>all the customers in a list</returns> public List <CustomerBE> GetAllCustomers() { TTAEntityContainer DBEntity = new TTAEntityContainer(); List <Customer> listCustomerDE = (from Customer customer in DBEntity.Customers select customer).ToList <Customer>(); List <CustomerBE> listCustomerBE = new List <CustomerBE>(); foreach (Customer customerDE in listCustomerDE) { CustomerBE customerBE = new CustomerTranslator().Translate(customerDE); listCustomerBE.Add(customerBE); } return(listCustomerBE); }
/// <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); } }
/// <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); }
/// <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); }
/// <summary> /// Gets all categories. /// </summary> /// <param name="dbEntity">The db entity.</param> /// <returns></returns> public List <CategoryBE> GetAllCategories(TTAEntityContainer dbEntity) { List <CategoryBE> listCategoryBE = new List <CategoryBE>(); CategoryTranslator categoryTranslator = new CategoryTranslator(); List <Category> categoryDEList = (from Category category in dbEntity.Categories select category).ToList <Category>(); foreach (Category categoryDE in categoryDEList) { CategoryBE categoryBE = categoryTranslator.Translate(categoryDE); listCategoryBE.Add(categoryBE); } return(listCategoryBE); }
/// <summary> /// select list of orderdetails by orderid for gridview datasource /// </summary> /// <param name="orderId"></param> /// <returns></returns> public List <OrderDetailsBE> GetOrderDetailsByOrderId(int orderId) { TTAEntityContainer dbEntity = new TTAEntityContainer(); List <OrderDetails> list = (from OrderDetails orderdetails in dbEntity.OrderDetails where orderdetails.OrderId == orderId && orderdetails.IsDeleted == false select orderdetails).ToList <OrderDetails>(); List <OrderDetailsBE> listBE = new List <OrderDetailsBE>(); foreach (OrderDetails orderdetails in list) { OrderDetailsBE orderdetailsBE = new OrderDetailsTranslator().Translate(orderdetails); listBE.Add(orderdetailsBE); } return(listBE); }
/// <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); } }
/// <summary> /// Gets the by customer ID. /// </summary> /// <param name="dBEntity">The d B entity.</param> /// <param name="customerId">The customer id.</param> /// <returns></returns> public List <OrderBE> GetByCustomerID(TTAEntityContainer dBEntity, int customerId) { List <Order> orderList = null; List <OrderBE> resultList = null; OrderTranslator translator = new OrderTranslator(); if (customerId >= 0) { orderList = (from Order o in dBEntity.Orders where o.CustomerId == customerId select o).ToList <Order>(); } foreach (Order order in orderList) { OrderBE orderBE = translator.Translate(order); resultList.Add(orderBE); } return(resultList); }
/// <summary> /// Call GetOrderSearchResults(...) method to obtain search results in form of a List<OrderSearchResult> object, /// and transform it to List<OrderSearchResultBE> type. /// </summary> /// <param name="customerName"></param> /// <param name="oper"></param> /// <param name="orderDate"></param> /// <param name="productName"></param> /// <param name="sortExpression"></param> /// <param name="sortDirection"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public List <OrderSearchResultBE> GetOrderSearchResults(string customerName, string startDate, string endDate, string productName, string sortExpression, string sortDirection, int pageStart, int pageEnd, out int rowCount) { TTAEntityContainer dbEntity = new TTAEntityContainer(); List <OrderSearchResult> searchResultList = new List <OrderSearchResult>(); searchResultList = this.GetOrderSearchResults(dbEntity, customerName, startDate, endDate, productName, sortExpression, sortDirection, pageStart, pageEnd, out rowCount); List <OrderSearchResultBE> searchResultBEList = new List <OrderSearchResultBE>(); OrderSearchResultTranslator orderSearchResultTranslator = new OrderSearchResultTranslator(); searchResultBEList = orderSearchResultTranslator.TranslateToBEList(searchResultList); return(searchResultBEList); }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }