示例#1
0
        public List <OrderHistoryWrapper> GetOrdersFromDepartment(int departmentID)
        {
            using (var _context = new AalborgZooContainer())
            {
                List <Order> allOrders = _context.OrderSet
                                         .Include("Orderlines.Unit")
                                         .Where(x => x.DepartmentID == departmentID)
                                         .OrderByDescending(x => x.DateOrdered)
                                         .Take(10)
                                         .ToList();
                List <OrderHistoryWrapper> wrappers = new List <OrderHistoryWrapper>();

                foreach (Order order in allOrders)
                {
                    bool hasFruit = order
                                    .OrderLines
                                    .Any(x => x.ProductVersion.Supplier == "FrugtKarl");
                    bool hasOther = order
                                    .OrderLines
                                    .Any(x => x.ProductVersion.Supplier != "FrugtKarl");
                    wrappers.Add(new OrderHistoryWrapper(order, hasFruit, hasOther));
                }

                return(wrappers);
            }
        }
示例#2
0
        public void DeleteOrder(Order order)
        {
            var db = new AalborgZooContainer();

            order = db.OrderSet.Where(x => x.Id == order.Id).First();
            db.OrderSet.Remove(order);
        }
 public ICollection <Unit> GetProductUnits(Product product)
 {
     using (var _context = new AalborgZooContainer())
     {
         return(_context.ProductSet.FirstOrDefault(x => x.Id == product.Id).ProductVersions.Last().Units);
     }
 }
示例#4
0
        /// <summary>
        /// Adds a not yet excisting order to the database
        /// </summary>
        /// <param name="order"></param>
        public Order AddOrder(Order order)
        {
            using (var _context = new AalborgZooContainer())
            {
                var   temp1     = order.OrderLines.First().ProductVersion.Id;
                Order tempOrder = new Order()
                {
                    OrderedByID    = order.OrderedByID,
                    DateCreated    = order.DateCreated,
                    DepartmentID   = order.DepartmentID,
                    Status         = order.Status,
                    Note           = order.Note,
                    DateOrdered    = order.DateOrdered,
                    Id             = order.Id,
                    DateCancelled  = order.DateCancelled,
                    DeletedByID    = order.DeletedByID,
                    OrderLines     = new Collection <OrderLine>(),
                    ShoppingList   = null,
                    ShoppingListId = null
                };

                List <OrderLine> tempOrderLines = new List <OrderLine>();
                foreach (OrderLine item in order.OrderLines)
                {
                    _context.ProductVersionSet.Attach(item.ProductVersion);
                    _context.OrderLineSet.Add(item);
                    tempOrder.OrderLines.Add(item);
                }

                _context.OrderSet.Add(tempOrder);

                _context.SaveChanges();
                return(tempOrder);
            }
        }
示例#5
0
        public void DeleteProduct(Product product)
        {
            var db = new AalborgZooContainer();

            product = db.ProductSet.Where(x => x.Id == product.Id).First();
            db.ProductSet.Remove(product);
        }
示例#6
0
        /// <summary>
        /// Updates an excisting order in the database
        /// </summary>
        /// <param name="order"></param>
        public void UpdateOrder(Order order)
        {
            using (var _context = new AalborgZooContainer())
            {
                var result = _context.OrderSet.SingleOrDefault(b => b.Id == order.Id);
                if (result != null)
                {
                    result.OrderLines     = order.OrderLines;
                    result.DateOrdered    = order.DateOrdered;
                    result.Note           = order.Note;
                    result.OrderedByID    = order.OrderedByID;
                    result.Status         = order.Status;
                    result.ShoppingListId = order.ShoppingListId;



                    //Calls the database to save the changes
                    _context.SaveChanges();
                }
                else if (result == null)
                {
                    throw new OrderDoesNotExistInDatabaseException();
                }
            }
        }
 public void Add(ShoppingList shoppingList)
 {
     using (var context = new AalborgZooContainer())
     {
         context.ShoppingListSet.Add(shoppingList);
         context.SaveChanges();
     }
 }
        public Product AddProduct(Product product)
        {
            using (var _context = new AalborgZooContainer())
            {
                Product productWithKey = _context.ProductSet.Add(product);
                _context.SaveChanges();

                return(productWithKey);
            }
        }
        public Department AddDepartment(Department department)
        {
            using (var db = new AalborgZooContainer())
            {
                Department departmentWithID = db.DepartmentSet.Add(department);
                db.SaveChanges();

                return(departmentWithID);
            }
        }
示例#10
0
 public List <Order> GetOrdersWithNoShoppinglist()
 {
     _contextForShopper = new AalborgZooContainer();
     return(_contextForShopper.OrderSet
            .Include("OrderLines")
            .Include("Orderlines.ProductVersion")
            .Include("OrderLines.ProductVersion.Units")
            .Include("Orderlines.ProductVersion.Product")
            .Where(x => x.ShoppingList == null)
            .ToList());
 }
        /// <summary>
        /// Gets all products from the database.
        /// </summary>
        /// <returns></returns>
        public List <Product> GetAllProducts()
        {
            List <Product> product = new List <Product>();

            using (var _context = new AalborgZooContainer())
            {
                product = _context.ProductSet.ToList();
            }

            return(product);
        }
示例#12
0
        /// <summary>
        /// Gets an order from orderID in the database
        /// </summary>
        /// <param name="orderID"></param>
        /// <returns></returns>
        public Order GetOrder(int orderID)
        {
            using (var _context = new AalborgZooContainer())
            {
                Order order = _context.OrderSet.Find(orderID);

                if (order == null)
                {
                    throw new OrderDoesNotExistInDatabaseException();
                }
                return(order);
            }
        }
示例#13
0
        public bool CheckIfProductExist(Product product)
        {
            var db = new AalborgZooContainer();

            if (db.ProductSet.Where(x => x.Id == product.Id).First().Id == product.Id)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public List <Department> GetDepartments()
        {
            List <Department> _depList = new List <Department>();

            using (var db = new AalborgZooContainer())
            {
                foreach (Department dep in db.DepartmentSet.Include("ZooKeepers"))
                {
                    _depList.Add(dep);
                }
            }
            return(_depList);
        }
示例#15
0
        public void MakeProduct(int employeeID, string name)
        {
            var db = new AalborgZooContainer();

            Product newProduct = new Product()
            {
                DateCreated = DateTime.Now,
                CreatedByID = employeeID,
                Name        = name
            };

            db.ProductSet.Add(newProduct);
            db.SaveChanges();
        }
示例#16
0
 /// <summary>
 /// Finds an department order that is under construction and thereby not yet sent. If no such order exist it
 /// will return null.
 /// The function is linear and will look through all orders in database until a satisfying order is found.
 /// </summary>
 /// <param name="department"></param>
 /// <returns></returns>
 public Order GetUnfinishedOrder(Department department)
 {
     using (var _context = new AalborgZooContainer())
     {
         foreach (Order order in _context.OrderSet)
         {
             if (order.Status == order.UnderConstruction && order.DepartmentID == department.Id)
             {
                 return(order);
             }
         }
         return(null);
     }
 }
 public ShoppingList GetActiveShoppingList()
 {
     using (var context = new AalborgZooContainer())
     {
         ShoppingList shopList = context.ShoppingListSet.Include("Orders.OrderLines").Last();
         if (shopList != null && shopList.Status == 0)
         {
             return(shopList);
         }
         else
         {
             return(null);
         }
     }
 }
        public List <Product> GetDepartmentProductsWithUnits(Department department)
        {
            List <Product> departmentProductList = new List <Product>();

            using (var _context = new AalborgZooContainer())
            {
                foreach (DepartmentSpecificProduct depProduct in _context.DepartmentSpecificProductSet.Include("Product.ProductVersions.Units"))
                {
                    if (depProduct.Product.CheckIfProductIsActive() && department.Id == depProduct.DepartmentId)
                    {
                        departmentProductList.Add(depProduct.Product);
                    }
                }
            }

            return(departmentProductList);
        }
        /// <summary>
        /// Gets all product from the database that are departmentspecicproduct to a given department
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        public List <Product> GetDepartmentProducts(Department department)
        {
            List <Product> departmentProductList = new List <Product>();

            using (var _context = new AalborgZooContainer())
            {
                foreach (DepartmentSpecificProduct depProduct in _context.DepartmentSpecificProductSet)
                {
                    if (depProduct.Product.CheckIfProductIsActive() && String.Equals(depProduct.Department.Name, department.Name))
                    {
                        departmentProductList.Add(depProduct.Product);
                    }
                }
            }

            return(departmentProductList);
        }
        /// <summary>
        /// Opdates the product and thereby also the ProductVersions contained in the product objekt.
        /// </summary>
        /// <param name="product"></param>
        public void UpdateProductVersionList(Product product)
        {
            using (var _context = new AalborgZooContainer())
            {
                //Finds the current product in the database.
                Product Outdated = _context.ProductSet.SingleOrDefault(x => x.Id == product.Id);
                if (Outdated != null)
                {
                    //Replaces it with the new version.
                    Outdated = product;

                    _context.SaveChanges();
                }
                else
                {
                    throw new ProductDoNotExistInDatabaseException(product.Name);
                }
            }
        }