Пример #1
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();
                }
            }
        }
Пример #2
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);
            }
        }
 public void Add(ShoppingList shoppingList)
 {
     using (var context = new AalborgZooContainer())
     {
         context.ShoppingListSet.Add(shoppingList);
         context.SaveChanges();
     }
 }
        public Department AddDepartment(Department department)
        {
            using (var db = new AalborgZooContainer())
            {
                Department departmentWithID = db.DepartmentSet.Add(department);
                db.SaveChanges();

                return(departmentWithID);
            }
        }
        public Product AddProduct(Product product)
        {
            using (var _context = new AalborgZooContainer())
            {
                Product productWithKey = _context.ProductSet.Add(product);
                _context.SaveChanges();

                return(productWithKey);
            }
        }
Пример #6
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();
        }
        /// <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);
                }
            }
        }
Пример #8
0
        public ShoppingList AddToShoppingList(List <Order> orders, int shopperId)
        {
            ShoppingList shoppingList = new ShoppingList();

            shoppingList.CreatedByID = shopperId;
            shoppingList.Shopper     = (Shopper)_contextForShopper.EmployeeSet.FirstOrDefault(x => x is Shopper && x.Id == shopperId);
            shoppingList.DateCreated = DateTime.Now;

            shoppingList.Orders = orders;

            foreach (Order order in orders)
            {
                order.ShoppingList = shoppingList;
                _contextForShopper.Entry(order).State = System.Data.Entity.EntityState.Modified;
            }

            _contextForShopper.SaveChanges();

            _contextForShopper.ShoppingListSet.Add(shoppingList);
            _contextForShopper.Dispose();
            return(shoppingList);
        }