Ejemplo n.º 1
0
        protected override Part AddEntity(BomContext entityContext, Part part)
        {
            var newPart = entityContext.Parts.Add(part);

            UpdateComponentsOfAssembly(entityContext, newPart);
            return(newPart);
        }
Ejemplo n.º 2
0
        public HierarchyNode <ProductTree> GetProductTree()
        {
            var productTree = new HierarchyNode <ProductTree>();

            using (BomContext entityContext = new BomContext())
            {
                var productTreeQuery = from part in entityContext.Parts
                                       join s in entityContext.Subassemblies on part.Id equals s.SubassemblyId into ps
                                       from s in ps.DefaultIfEmpty()
                                       select new ProductTree
                {
                    Id              = part.Id,
                    ParentId        = (s == null ? 0 : s.AssemblyId),
                    PartDescription = part.Description,
                    OwnCost         = part.OwnCost,
                    ComponentsCost  = part.ComponentsCost,
                    Capability      = part.Capability,
                    Count           = part.Count,
                    CountDate       = part.CountDate,
                    Demand          = part.Demand,
                    OnOrder         = part.OnOrder,
                    Notes           = part.Notes
                };

                productTree = productTreeQuery.ToFullyLoaded().AsHierarchy(e => e.Id, e => e.ParentId).FirstOrDefault();
            }
            return(productTree);
        }
        protected override Order AddEntity(BomContext entityContext, Order order)
        {
            //Prevent Entity Framework from creating new Supplier. ToDo confirm.
            order.Supplier = null;
            var newOrder = entityContext.Orders.Add(order);

            return(newOrder);
        }
Ejemplo n.º 4
0
 protected override Part UpdateEntity(BomContext entityContext, Part entity)
 {
     if (entity.Components != null)
     {
         UpdateComponentsOfAssembly(entityContext, entity);
     }
     return((entityContext.Parts.Where(e => e.Id == entity.Id)).FirstOrDefault());
 }
 protected override Order UpdateEntity(BomContext entityContext, Order entity)
 {
     if (entity.Items != null)
     {
         UpdateOrderDetailOfOrder(entityContext, entity);
     }
     //Prevent Entity Framework from creating new Supplier. ToDo confirm.
     entity.Supplier = null;
     //entity.Items = null;
     //entityContext.Entry(entity).State = EntityState.Modified;
     //entityContext.Entry(entity.Supplier).State = EntityState.Detached;
     return((entityContext.Orders.Where(e => e.Id == entity.Id)).FirstOrDefault());
 }
Ejemplo n.º 6
0
        public IEnumerable <Subassembly> GetComponents(int assemblyId)
        {
            IEnumerable <Subassembly> subassemblies;

            using (BomContext entityContext = new BomContext())
            {
                subassemblies = entityContext.Subassemblies.Where(e => e.AssemblyId == assemblyId).ToFullyLoaded();
                foreach (var subassembly in subassemblies)
                {
                    subassembly.PartDescription = entityContext.Parts.Single(p => p.Id == subassembly.SubassemblyId).Description;
                }
            }
            return(subassemblies);
        }
        public IEnumerable <OrderDetail> GetItems(int orderId)
        {
            IEnumerable <OrderDetail> Items;

            using (BomContext entityContext = new BomContext())
            {
                Items = entityContext.OrderDetails.Where(e => e.OrderId == orderId).ToFullyLoaded();
                foreach (var item in Items)
                {
                    item.PartDescription = entityContext.Parts.Single(p => p.Id == item.PartId).Description;
                }
            }
            return(Items);
        }
Ejemplo n.º 8
0
        public IEnumerable <StockItemsInfo> GetAllStockItemsInfo()
        {
            using (BomContext entityContext = new BomContext())
            {
                IQueryable <StockItemsInfo> query = from s in entityContext.Stocks
                                                    join p in entityContext.Parts on s.PartId equals p.Id
                                                    select new StockItemsInfo()
                {
                    Stock = s,
                    Part  = p
                };

                return(query.ToFullyLoaded());
            }
        }
Ejemplo n.º 9
0
        public void RecalculateCostsForAssembly(int partId)
        {
            using (BomContext entityContext = new BomContext())
            {
                var id = new SqlParameter("@id", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Input,
                    Value     = partId
                };
                var cost = new SqlParameter("@cost", SqlDbType.Decimal)
                {
                    Direction = ParameterDirection.Output
                };

                entityContext.Database.ExecuteSqlCommand("EXEC dbo.RecalculateCostsForAssembly @partId = @id, @TotalCost = @cost output",
                                                         id, cost);
            }
        }
Ejemplo n.º 10
0
        private static void UpdateComponentsOfAssembly(BomContext entityContext, Part entity)
        {
            entityContext.Subassemblies.RemoveRange(entityContext.Subassemblies.Where(s => s.AssemblyId == entity.Id));
            if (entity.Components == null)
            {
                return;
            }

            foreach (var component in entity.Components)
            {
                entityContext.Subassemblies.Add(new Subassembly
                {
                    AssemblyId       = entity.Id,
                    SubassemblyId    = component.SubassemblyId,
                    CostContribution = component.CostContribution,
                    Notes            = component.Notes
                });
            }
        }
        private static void UpdateOrderDetailOfOrder(BomContext entityContext, Order entity)
        {
            entityContext.OrderDetails.RemoveRange(entityContext.OrderDetails.Where(s => s.OrderId == entity.Id));

            if (entity.Items == null)
            {
                return;
            }

            foreach (var component in entity.Items)
            {
                entityContext.OrderDetails.Add(new OrderDetail
                {
                    OrderId         = entity.Id,
                    Count           = component.Count,
                    Price           = component.Price,
                    Notes           = component.Notes,
                    PartId          = component.PartId,
                    PartDescription = component.PartDescription
                });
            }
        }
Ejemplo n.º 12
0
        public void Recalculate(int partId, int productsNeeded)
        {
            using (BomContext entityContext = new BomContext())
            {
                var id = new SqlParameter("@id", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Input,
                    Value     = partId
                };
                var demand = new SqlParameter("@demand", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Input,
                    Value     = productsNeeded
                };
                var count = new SqlParameter("@count", SqlDbType.Decimal)
                {
                    Direction = ParameterDirection.Output
                };

                entityContext.Database.ExecuteSqlCommand("EXEC dbo.Recalculate @partId = @id, @ProductsDemand = @demand, @ProductsCount = @count output",
                                                         id, demand, count);
            }
        }
Ejemplo n.º 13
0
 protected override Supplier AddEntity(BomContext entityContext, Supplier entity)
 {
     return(entityContext.Suppliers.Add(entity));
 }
Ejemplo n.º 14
0
 protected override IEnumerable <Stock> GetEntities(BomContext entityContext)
 {
     return(entityContext.Stocks.Select(e => e));
 }
Ejemplo n.º 15
0
 protected override Stock UpdateEntity(BomContext entityContext, Stock entity)
 {
     return((entityContext.Stocks.Where(e => e.Id == entity.Id)).FirstOrDefault());
 }
Ejemplo n.º 16
0
 protected override Stock AddEntity(BomContext entityContext, Stock entity)
 {
     return(entityContext.Stocks.Add(entity));
 }
        protected override Order GetEntity(BomContext entityContext, int id)
        {
            var order = (entityContext.Orders.Where(e => e.Id == id).Include(o => o.Supplier)).Single();

            return(order);
        }
Ejemplo n.º 18
0
 protected override IEnumerable <Part> GetEntities(BomContext entityContext)
 {
     return(entityContext.Parts.Select(e => e));
 }
Ejemplo n.º 19
0
 protected override IEnumerable <Supplier> GetEntities(BomContext entityContext)
 {
     return(entityContext.Suppliers.Select(e => e));
 }
Ejemplo n.º 20
0
 protected override Part GetEntity(BomContext entityContext, int id)
 {
     return((entityContext.Parts.Where(e => e.Id == id)).FirstOrDefault());
 }
Ejemplo n.º 21
0
 protected override Supplier GetEntity(BomContext entityContext, int id)
 {
     return((entityContext.Suppliers.Where(e => e.Id == id)).FirstOrDefault());
 }
Ejemplo n.º 22
0
 protected override Supplier UpdateEntity(BomContext entityContext, Supplier entity)
 {
     return((entityContext.Suppliers.Where(e => e.Id == entity.Id)).FirstOrDefault());
 }
 protected override IEnumerable <Order> GetEntities(BomContext entityContext)
 {
     return(entityContext.Orders.Select(e => e).Include(o => o.Supplier));
 }