public List <DTO.ProductionItemDTO> GetRequestingItem(int userId, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; List <DTO.ProductionItemDTO> data = new List <DTO.ProductionItemDTO>(); DTO.ProductionItemDTO productionItemDTO; DTO.WorkOrderDTO workOrderDTO; try { using (PurchaseRequestMngEntities context = CreateContext()) { var requestingItem = context.PurchaseRequestMng_RequestingItem_View.ToList(); var productionItems = from item in requestingItem group item by new { item.ProductionItemID, item.ProductionItemUD, item.ProductionItemNM, item.Unit, item.SuggestedFactoryRawMaterialID } into g select new { g.Key.ProductionItemID, g.Key.ProductionItemUD, g.Key.ProductionItemNM, g.Key.Unit, g.Key.SuggestedFactoryRawMaterialID, RequestingQnt = g.Sum(o => o.RequestingQnt) }; foreach (var item in productionItems) { productionItemDTO = new DTO.ProductionItemDTO(); productionItemDTO.WorkOrderDTOs = new List <DTO.WorkOrderDTO>(); data.Add(productionItemDTO); productionItemDTO.ProductionItemID = item.ProductionItemID; productionItemDTO.ProductionItemUD = item.ProductionItemUD; productionItemDTO.ProductionItemNM = item.ProductionItemNM; productionItemDTO.Unit = item.Unit; productionItemDTO.SuggestedFactoryRawMaterialID = item.SuggestedFactoryRawMaterialID; productionItemDTO.RequestQnt = item.RequestingQnt; foreach (var wItem in requestingItem.Where(o => o.ProductionItemID == item.ProductionItemID)) { workOrderDTO = new DTO.WorkOrderDTO(); productionItemDTO.WorkOrderDTOs.Add(workOrderDTO); workOrderDTO.WorkOrderID = wItem.WorkOrderID; workOrderDTO.WorkOrderUD = wItem.WorkOrderUD; workOrderDTO.ProformaInvoiceNo = wItem.ProformaInvoiceNo; workOrderDTO.ClientUD = wItem.ClientUD; workOrderDTO.RequestingQnt = wItem.RequestingQnt; } } return(data); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(data); } }
public void DTO2DB_ProductionItem(DTO.ProductionItemDTO dtoItem, ref ProductionItem dbItem) { AutoMapper.Mapper.Map <DTO.ProductionItemDTO, ProductionItem>(dtoItem, dbItem); }
public object GetProductionItemBaseOn(int userID, int?branchID, string workOrderIDs, string searchItem, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; List <DTO.ProductionItemDTO> data = new List <DTO.ProductionItemDTO>(); try { Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory(); int?companyID = fwFactory.GetCompanyID(userID); using (var context = CreateContext()) { if (string.IsNullOrEmpty(workOrderIDs)) // Free item { data = converter.DB2DTO_ProductionItem(context.PurchaseRequestMng_function_GetProductionItem(companyID, branchID, searchItem).ToList()); } else // WorkOrder item { var dbItem = context.PurchaseRequestMng_function_GetProductionItemByWorkOrder2(companyID, workOrderIDs, branchID, searchItem).ToList(); int?productionItemID = null; DTO.ProductionItemDTO dtoItem = null; foreach (var item in dbItem) { if (item != null /* && item.ProductionItemTypeID != 3*/) // Not get items depend on type is piece { if (productionItemID == null || productionItemID != item.ProductionItemID) { dtoItem = new DTO.ProductionItemDTO(); dtoItem.ProductionItemID = item.ProductionItemID; dtoItem.ProductionItemUD = item.ProductionItemUD; dtoItem.ProductionItemNM = item.ProductionItemNM; dtoItem.UnitNM = item.UnitNM; dtoItem.ETA = null; dtoItem.IsApproved = item.IsApproved; dtoItem.OrderQnt = item.OrderQnt; dtoItem.StockQnt = item.StockQnt; dtoItem.ProductionItemGroupID = item.ProductionItemGroupID; dtoItem.WorkOrderDTOs = new List <DTO.WorkOrderDTO>(); data.Add(dtoItem); productionItemID = item.ProductionItemID; } DTO.WorkOrderDTO dtoWorkOrder = new DTO.WorkOrderDTO(); dtoWorkOrder.WorkOrderID = item.WorkOrderID; dtoWorkOrder.WorkOrderUD = item.WorkOrderUD; dtoWorkOrder.ProformaInvoiceNo = item.ProformaInvoiceNo; dtoWorkOrder.RequestingQnt = item.RequestQnt; dtoItem.WorkOrderDTOs.Add(dtoWorkOrder); } } } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(data); }