示例#1
0
        /// <summary>
        /// Get Added Items of BOM.
        /// </summary>
        /// <param name="bomId"></param>
        /// <returns></returns>
        public IResult GetAddedItemsOfBom(string bomId)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                if (!string.IsNullOrEmpty(bomId))
                {
                    var bom = _bomRepository.GetChildDocument(x => x.BomId == ObjectId.Parse(bomId), "AddedItems", "BomId");
                    if (bom.AddedItems != null && bom.AddedItems.Any())
                    {
                        var item         = new Item();
                        var materialIds  = bom.AddedItems.Where(x => x.ItemType == BomItemType.Material).Select(x => x.RegardingId).ToList();
                        var equipmentIds = bom.AddedItems.Where(x => x.ItemType == BomItemType.Equipment).Select(x => x.RegardingId).ToList();

                        var materialList = _materialManager.GetListofMaterials(materialIds);
                        if (materialList != null && materialList.Any())
                        {
                            item.Materials = materialList;
                        }
                        var equipmentList = _equipmentManager.GetListofEquipments(equipmentIds);
                        if (equipmentList != null && equipmentList.Any())
                        {
                            item.Equipments = equipmentList;
                        }
                        result.Body = item;
                    }
                    else
                    {
                        result.Message = BomNotification.NoAddedItem;
                    }
                }
                else
                {
                    result.Status  = Status.Fail;
                    result.Message = CommonErrorMessages.NoIdentifierProvided;
                }
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Fail;
            }
            return(result);
        }