public long SaveInventory(Inventory inventory, string userId) { var inventoryDTO = new DTO.InventoryDTO() { ItemName = inventory.ItemName, Description = inventory.Description, PurchaseDate = inventory.PurchaseDate, Price = inventory.Price, Quantity = inventory.Quantity, InventoryCategoryId = inventory.InventoryCategoryId, Amount = inventory.Amount, BranchId = inventory.BranchId, SectorId = inventory.SectorId, StoreId = inventory.StoreId, TransactionSubTypeId = inventory.TransactionSubTypeId, InventoryId = inventory.InventoryId, Deleted = inventory.Deleted, CreatedBy = inventory.CreatedBy, CreatedOn = inventory.CreatedOn }; var InventoryId = this._dataService.SaveInventory(inventoryDTO, userId); if (inventory.InventoryId == 0) { long transactionTypeId = 0; var transactionSubtype = _transactionSubTypeService.GetTransactionSubType(inventoryDTO.TransactionSubTypeId); if (transactionSubtype != null) { transactionTypeId = transactionSubtype.TransactionTypeId; } var transaction = new TransactionDTO() { BranchId = inventoryDTO.BranchId, SectorId = inventoryDTO.SectorId, Amount = inventoryDTO.Amount, TransactionSubTypeId = inventoryDTO.TransactionSubTypeId, TransactionTypeId = transactionTypeId, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var transactionId = _transactionDataService.SaveTransaction(transaction, userId); } return(InventoryId); }
/// Custom function get data (new version) /// FactoryWarehouses: list selected from front-end /// ProductionTeamID /// StartDate, EndDate public object CustomGetDataWithFilter(int userID, Hashtable filters, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; DTO.InventoryDTO data = new DTO.InventoryDTO(); try { string factoryWarehouses = null; int? productionTeamID = null; string startDate = null; string endDate = null; if (filters.ContainsKey("factoryWarehouses") && filters["factoryWarehouses"] != null && !string.IsNullOrEmpty(filters["factoryWarehouses"].ToString())) { factoryWarehouses = filters["factoryWarehouses"].ToString(); } if (filters.ContainsKey("productionTeamID") && filters["productionTeamID"] != null && !string.IsNullOrEmpty(filters["productionTeamID"].ToString())) { productionTeamID = (int?)Convert.ToInt32(filters["productionTeamID"].ToString()); } if (filters.ContainsKey("startDate") && filters["startDate"] != null && !string.IsNullOrEmpty(filters["startDate"].ToString())) { startDate = filters["startDate"].ToString(); } if (filters.ContainsKey("endDate") && filters["endDate"] != null && !string.IsNullOrEmpty(filters["endDate"].ToString())) { endDate = filters["endDate"].ToString(); } if (factoryWarehouses == null && productionTeamID == null) { notification.Type = NotificationType.Error; notification.Message = "Please select factory warehouse or production team!"; return(data); } if (startDate == null || endDate == null) { notification.Type = NotificationType.Error; notification.Message = "Please fill start date and end date!"; return(data); } using (var context = CreateContext()) { if (!string.IsNullOrEmpty(factoryWarehouses)) { List <InventoryRpt_function_InventorySearchResult2_Result> dbItem = context.InventoryRpt_function_InventorySearchResult2(factoryWarehouses, startDate, endDate).ToList(); List <InventoryRpt_function_InventorySearchResult4_Result> dbItemDetail = context.InventoryRpt_function_InventorySearchResult4(factoryWarehouses, startDate, endDate).ToList(); data.Inventory = AutoMapper.Mapper.Map <List <InventoryRpt_function_InventorySearchResult2_Result>, List <DTO.InventoryData> >(dbItem); data.InventoryDetail = AutoMapper.Mapper.Map <List <InventoryRpt_function_InventorySearchResult4_Result>, List <DTO.InventoryDetailData> >(dbItemDetail); } if (productionTeamID.HasValue) { List <InventoryRpt_function_InventorySearchResult3_Result> dbItem = context.InventoryRpt_function_InventorySearchResult3(productionTeamID, startDate, endDate).ToList(); List <InventoryRpt_function_InventorySearchResult5_Result> dbItemDetail = context.InventoryRpt_function_InventorySearchResult5(productionTeamID, startDate, endDate).ToList(); data.Inventory = AutoMapper.Mapper.Map <List <InventoryRpt_function_InventorySearchResult3_Result>, List <DTO.InventoryData> >(dbItem); data.InventoryDetail = AutoMapper.Mapper.Map <List <InventoryRpt_function_InventorySearchResult5_Result>, List <DTO.InventoryDetailData> >(dbItemDetail); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(data); }