Exemple #1
0
        public async Task HandleAsync(AddBillOfMaterial command)
        {
            var article = await _repository.GetAsync <Article>(command.ArticleId);

            var input = (await _repository.LoadSomeAsync <Article>(command.Input.Select(i => i.articleId)))
                        .Select(a => new InventoryItem(a, command.Input.Single(i => i.articleId == a.Id).amount)).ToHashSet();

            var bom = article.BillsOfMaterial.FirstOrDefault(b => b.Input.SetEquals(input));

            if (bom != null)
            {
                throw new DomainException(IdenticalBomExists(bom));
            }

            var newBom = new BillOfMaterial(command.Id, command.Name)
            {
                Article = article,
                Input   = input,
                Output  = command.Output,
                Primary = false
            };

            await _repository.AddAsync(newBom);

            article.BillsOfMaterial.Add(newBom);

            await _eventTransmitter.BroadcastAsync(new DomainEvent <BillOfMaterial>(newBom, Trigger.Added,
                                                                                    command.InitiatorId));
        }
        private List <BillOfMaterial> GetDummyBillOfMaterial()
        {
            List <BillOfMaterial> billOfMaterialList = new List <BillOfMaterial>();
            BillOfMaterial        objBill1           = new BillOfMaterial();

            objBill1.ProductAssemblyID = 1;
            objBill1.AssemblyID        = 800;
            objBill1.ComponentID       = 518;
            objBill1.Name           = "ML Road Seat Assembly";
            objBill1.PerAssemblyQty = 1.00M;
            objBill1.EndDate        = null;
            objBill1.ComponentLevel = 0;
            billOfMaterialList.Add(objBill1);

            BillOfMaterial objBill2 = new BillOfMaterial();

            objBill2.ProductAssemblyID = 2;
            objBill2.AssemblyID        = 800;
            objBill2.ComponentID       = 806;
            objBill2.Name           = "ML Headset";
            objBill2.PerAssemblyQty = 1.00M;
            objBill2.EndDate        = null;
            objBill2.ComponentLevel = 0;
            billOfMaterialList.Add(objBill2);
            return(billOfMaterialList);
        }
Exemple #3
0
        public BillOfMaterial GetBillOfMaterial(int billOfMaterialsId, string propertyToInclude = null)
        {
            try
            {
                BillOfMaterial billOfMaterial = null;
                if (!String.IsNullOrEmpty(propertyToInclude))
                {
                    billOfMaterial = _ctx.BillOfMaterials.Include(propertyToInclude)
                                     .Where(c => c.BillOfMaterialsId == billOfMaterialsId)
                                     .FirstOrDefault();
                }
                billOfMaterial = _ctx.BillOfMaterials
                                 .Include(v => v.ProductAssembly)
                                 .Include(v => v.Component)
                                 .Include(v => v.UnitMeasure)
                                 .Where(c => c.BillOfMaterialsId == billOfMaterialsId).FirstOrDefault();

                return(billOfMaterial);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in GetBillOfMaterial: {ex}");
                return(null);
            }
        }
 public int SaveBillofMaterial(BillOFMaterialModel model)
 {
     try
     {
         using (_context = new HSSNInventoryEntities())
         {
             var data = new BillOfMaterial()
             {
                 BillOfMaterialId   = model.BillOfMaterialId,
                 BillOfmaterialCode = model.BillOfmaterialCode,
                 ProductId          = model.ProductId,
                 BatchQuantity      = model.BatchQuantity,
                 CartoonQuantity    = model.CartoonQuantity,
                 IsIssued           = model.IsIssued,
                 PreparedBy         = model.PreparedBy,
                 PreparedDate       = model.PreparedDate,
             };
             _context.Entry(data).State = EntityState.Added;
             _context.SaveChanges();
             return(data.BillOfMaterialId);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public async void AddBOMAsync(BillOfMaterial bom)
        {
            var client = new BOMServicesClient();
            await client.AddBOMAsync(bom);

            _eventAggregator.GetEvent <ComponentSaveEvent>().Publish(null);
        }
Exemple #6
0
        /// <summary>
        /// Map View Model to Model
        /// </summary>
        /// <param name="bomViewModel"></param>
        /// <returns></returns>
        private BillOfMaterial MapBomToModel(BillOfMaterialViewModel bomViewModel)
        {
            var bom = new BillOfMaterial();

            bom.MapFromViewModel(bomViewModel, (ClaimsIdentity)_principal.Identity);

            if (bomViewModel.TemplateId != null)
            {
                bom.TemplateId = ObjectId.Parse(bomViewModel.TemplateId);
            }

            if (!string.IsNullOrEmpty(bomViewModel.Image))
            {
                bom.Image = ObjectId.Parse(bomViewModel.Image);
            }
            bom.AddedItems = new List <AddToBom>();
            bom.Comments   = new List <BomComment>();
            if (bomViewModel.Groups != null && bomViewModel.Groups.Any())
            {
                bom.Groups = new List <BomGroup>();
                bomViewModel.Groups.ForEach(t =>
                {
                    var bomGroup = MapBomGroupToModel(t);
                    bom.Groups.Add(bomGroup);
                });
            }
            return(bom);
        }
Exemple #7
0
 public void RemoveBOM(BillOfMaterial bom)
 {
     using (var ctx = new BOMDataContext())
     {
         ctx.BillOfMaterials.Remove(bom);
         ctx.SaveChanges();
     }
 }
Exemple #8
0
        public void TestInvalidBOM(short positionX, short positionY, short width, short height)
        {
            var bom = new BillOfMaterial();

            bom.AddShape(new Rectangle(positionX, positionY, width, height));
            var output = bom.GenerateBillOfMaterials();

            Assert.AreEqual(Constants.ABORT, output);
        }
        public ActionResult Add(BillOfMaterial billOfMaterial)
        {
            ResponseMsg response = new ResponseMsg();

            billOfMaterial.CreatedBy = billOfMaterial.UpdatedBy = currUser.ID;
            BillOfMaterialLogic.SaveBillOfMaterial(billOfMaterial);
            response.IsSuccess = true;
            return(Json(response));
        }
Exemple #10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         BillOfMaterial         = new BillOfMaterial();
         litData.Text           = "";
         btnAdd.CommandArgument = Selection.Rectangle.ToString();
     }
 }
Exemple #11
0
        /// <summary>
        /// Map bom model to view model
        /// </summary>
        /// <param name="bom"></param>
        /// <returns></returns>
        private BillOfMaterialViewModel MapBomToViewModel(BillOfMaterial bom)
        {
            var bomViewModel = new BillOfMaterialViewModel();

            bomViewModel.MapFromModel(bom);

            if (bom.TemplateId != null)
            {
                bomViewModel.TemplateId = bom.TemplateId.ToString();
            }

            if (bom.Image != null)
            {
                bomViewModel.Image = bom.Image.ToString();
            }

            bomViewModel.BomUser = MapBomUserToViewModel(bom.BomUser);

            if (bom.Groups != null && bom.Groups.Any())
            {
                bomViewModel.Groups = new List <BomGroupViewModel>();
                bom.Groups.ForEach(t =>
                {
                    var bomGroupViewModel = MapBomGroupToViewModel(t);
                    bomViewModel.Groups.Add(bomGroupViewModel);
                });
            }

            if (bom.Comments != null && bom.Comments.Any())
            {
                bomViewModel.Comments = bom.Comments.Select(t =>
                {
                    var bomCommentViewModel = new BomCommentViewModel();
                    bomCommentViewModel.MapFromModel(t);
                    return(bomCommentViewModel);
                }).ToList();
            }

            if (bom.Option != null)
            {
                bomViewModel.Option = new BomOptionViewModel();
                if (bom.Option.License != null)
                {
                    bomViewModel.Option.License = bom.Option.License.ToString();
                }
                if (bom.Option.Owner != null)
                {
                    bomViewModel.Option.Owner = bom.Option.Owner.ToString();
                }
                if (bom.Option.Location != null)
                {
                    bomViewModel.Option.Location = bom.Option.Location.ToString();
                }
            }

            return(bomViewModel);
        }
 private void fillList()
 {
     foreach (BillOfMaterial m in BillOfMaterial.testing(product))
     {
         //Material temp = MaterialMapper.getMaterialById(m);
         Material derp = new Material(m.MaterialId);
         derp = MaterialMapper.getMaterialById(derp);
         string quant = m.Quantity.ToString();
         addedListBox.Items.Add("ID - " + derp.MaterialID + " - " + derp.Name + " Quantity " + quant);
     }
 }
        // PUT api/awbuildversion/5
        public void Put(BillOfMaterial value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                    adventureWorks_BC.BillOfMaterialDelete(value);
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                    adventureWorks_BC.BillOfMaterialUpdate(value);
            }
        }
Exemple #14
0
        public void GenerateEmptyBOM()
        {
            var bom            = new BillOfMaterial();
            var output         = bom.GenerateBillOfMaterials();
            var expectedOutput =
                @"----------------------------------------------------------------
Bill of Materials
----------------------------------------------------------------
----------------------------------------------------------------";

            Assert.AreEqual(expectedOutput, output);
        }
 public ActionResult Edit([Bind(Include = "BillOfMaterialsID,ProductAssemblyID,ComponentID,StartDate,EndDate,UnitMeasureCode,BOMLevel,PerAssemblyQty,ModifiedDate,isDeleted")] BillOfMaterial billOfMaterial)
 {
     if (ModelState.IsValid)
     {
         db.Entry(billOfMaterial).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ComponentID       = new SelectList(db.Products, "ProductID", "Name", billOfMaterial.ComponentID);
     ViewBag.ProductAssemblyID = new SelectList(db.Products, "ProductID", "Name", billOfMaterial.ProductAssemblyID);
     return(View(billOfMaterial));
 }
Exemple #16
0
        private async Task <bool> BeUniqueByProductAssemblyIDComponentIDStartDate(ApiBillOfMaterialRequestModel model, CancellationToken cancellationToken)
        {
            BillOfMaterial record = await this.billOfMaterialRepository.ByProductAssemblyIDComponentIDStartDate(model.ProductAssemblyID, model.ComponentID, model.StartDate);

            if (record == null || (this.existingRecordId != default(int) && record.BillOfMaterialsID == this.existingRecordId))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #17
0
        public async Task <ApiBillOfMaterialResponseModel> ByProductAssemblyIDComponentIDStartDate(int?productAssemblyID, int componentID, DateTime startDate)
        {
            BillOfMaterial record = await this.billOfMaterialRepository.ByProductAssemblyIDComponentIDStartDate(productAssemblyID, componentID, startDate);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.bolBillOfMaterialMapper.MapBOToModel(this.dalBillOfMaterialMapper.MapEFToBO(record)));
            }
        }
        public void MapEFToBOList()
        {
            var            mapper = new DALBillOfMaterialMapper();
            BillOfMaterial entity = new BillOfMaterial();

            entity.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            List <BOBillOfMaterial> response = mapper.MapEFToBO(new List <BillOfMaterial>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
Exemple #19
0
 public bool BillOfMaterialDelete(BillOfMaterial billofmaterial)
 {
     return(Execute <bool>(dal =>
     {
         BillOfMaterial billofmaterialDelete = dal.BillOfMaterial.Where(x => x.BillOfMaterialsID == billofmaterial.BillOfMaterialsID).FirstOrDefault();
         if (billofmaterialDelete != null)
         {
             dal.BillOfMaterial.DeleteOnSubmit(billofmaterialDelete);
             dal.SubmitChanges();
             return true;
         }
         return false;
     }));
 }
        // GET: BillOfMaterials/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillOfMaterial billOfMaterial = db.BillOfMaterials.Find(id);

            if (billOfMaterial == null)
            {
                return(HttpNotFound());
            }
            return(View(billOfMaterial));
        }
Exemple #21
0
 public bool BillOfMaterialExists(BillOfMaterial billOfMaterial)
 {
     try
     {
         return(_ctx.BillOfMaterials.Any(c =>
                                         c.ProductAssemblyId == billOfMaterial.ProductAssemblyId &&
                                         c.ComponentId == billOfMaterial.ComponentId &&
                                         c.BillOfMaterialsId != billOfMaterial.BillOfMaterialsId));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed in BillOfMaterialExists: {ex}");
         return(false);
     }
 }
        // PUT api/awbuildversion/5
        public void Put(BillOfMaterial value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                {
                    adventureWorks_BC.BillOfMaterialDelete(value);
                }
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                {
                    adventureWorks_BC.BillOfMaterialUpdate(value);
                }
            }
        }
        // GET: BillOfMaterials/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillOfMaterial billOfMaterial = db.BillOfMaterials.Find(id);

            if (billOfMaterial == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ComponentID       = new SelectList(db.Products, "ProductID", "Name", billOfMaterial.ComponentID);
            ViewBag.ProductAssemblyID = new SelectList(db.Products, "ProductID", "Name", billOfMaterial.ProductAssemblyID);
            return(View(billOfMaterial));
        }
        public virtual BillOfMaterial MapBOToEF(
            BOBillOfMaterial bo)
        {
            BillOfMaterial efBillOfMaterial = new BillOfMaterial();

            efBillOfMaterial.SetProperties(
                bo.BillOfMaterialsID,
                bo.BOMLevel,
                bo.ComponentID,
                bo.EndDate,
                bo.ModifiedDate,
                bo.PerAssemblyQty,
                bo.ProductAssemblyID,
                bo.StartDate,
                bo.UnitMeasureCode);
            return(efBillOfMaterial);
        }
Exemple #25
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IBillOfMaterialRepository>();
            var record = new BillOfMaterial();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new BillOfMaterialService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.BillOfMaterialModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLBillOfMaterialMapperMock,
                                                    mock.DALMapperMockFactory.DALBillOfMaterialMapperMock);

            ApiBillOfMaterialResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public virtual BOBillOfMaterial MapEFToBO(
            BillOfMaterial ef)
        {
            var bo = new BOBillOfMaterial();

            bo.SetProperties(
                ef.BillOfMaterialsID,
                ef.BOMLevel,
                ef.ComponentID,
                ef.EndDate,
                ef.ModifiedDate,
                ef.PerAssemblyQty,
                ef.ProductAssemblyID,
                ef.StartDate,
                ef.UnitMeasureCode);
            return(bo);
        }
Exemple #27
0
        public async void ByProductAssemblyIDComponentIDStartDate_Exists()
        {
            var mock   = new ServiceMockFacade <IBillOfMaterialRepository>();
            var record = new BillOfMaterial();

            mock.RepositoryMock.Setup(x => x.ByProductAssemblyIDComponentIDStartDate(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <DateTime>())).Returns(Task.FromResult(record));
            var service = new BillOfMaterialService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.BillOfMaterialModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLBillOfMaterialMapperMock,
                                                    mock.DALMapperMockFactory.DALBillOfMaterialMapperMock);

            ApiBillOfMaterialResponseModel response = await service.ByProductAssemblyIDComponentIDStartDate(default(int?), default(int), default(DateTime));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.ByProductAssemblyIDComponentIDStartDate(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <DateTime>()));
        }
Exemple #28
0
 public void AddBOM(BillOfMaterial bom)
 {
     using (var ctx = new BOMDataContext())
     {
         var bomv = ctx.BillOfMaterials.Where(b => b.ComponentID == bom.ComponentID && b.PartID == bom.PartID);
         if (bomv.Any())
         {
             var oldBOM = bomv.First();
             oldBOM.Quantity = oldBOM.Quantity + bom.Quantity;
         }
         else
         {
             ctx.BillOfMaterials.Add(bom);
         }
         ctx.SaveChanges();
     }
 }
Exemple #29
0
        public BillOfMaterial CreateBillOfMaterial(BillOfMaterial billOfMaterial, int userId = -1)
        {
            try
            {
                var billOfMaterialEntityEntry = _ctx.BillOfMaterials.Add(billOfMaterial);

                if (!Save(userId))
                {
                    return(null);
                }
                return(billOfMaterialEntityEntry.Entity);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in CreateBillOfMaterial: {ex}");
                return(null);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var res = (from c in db.BillOfMaterials
                       where c.BillOfMaterialsID == id
                       select c).FirstOrDefault();

            if (res != null)
            {
                res.isDeleted = true;
                db.SaveChanges();
                ViewBag.Message = string.Format("Congrats! Delete success");
            }
            BillOfMaterial address = db.BillOfMaterials.Find(id);



            return(View(address));
        }
        public void MapEFToBO()
        {
            var            mapper = new DALBillOfMaterialMapper();
            BillOfMaterial entity = new BillOfMaterial();

            entity.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            BOBillOfMaterial response = mapper.MapEFToBO(entity);

            response.BillOfMaterialsID.Should().Be(1);
            response.BOMLevel.Should().Be(1);
            response.ComponentID.Should().Be(1);
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PerAssemblyQty.Should().Be(1);
            response.ProductAssemblyID.Should().Be(1);
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.UnitMeasureCode.Should().Be("A");
        }
 // POST api/awbuildversion
 public void Post(BillOfMaterial value)
 {
     adventureWorks_BC.BillOfMaterialAdd(value);
 }