public async Task CreateInventoryDocument(MaterialsRequestNote Model, string Type) { //string inventoryDocumentURI = "inventory/inventory-documents"; string storageURI = "master/storages"; string uomURI = "master/uoms"; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); /* Get UOM */ Dictionary <string, object> filterUOM = new Dictionary <string, object> { { "unit", "MTR" } }; var responseUOM = httpClient.GetAsync($@"{APIEndpoint.Core}{uomURI}?filter=" + JsonConvert.SerializeObject(filterUOM)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultUOM = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseUOM.Result); var jsonUOM = resultUOM.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> uom = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonUOM.ToString())[0]; /* Get Storage */ var storageName = Model.UnitName.Equals("PRINTING") ? "Gudang Greige Printing" : "Gudang Greige Finishing"; Dictionary <string, object> filterStorage = new Dictionary <string, object> { { "name", storageName } }; var responseStorage = httpClient.GetAsync($@"{APIEndpoint.Core}{storageURI}?filter=" + JsonConvert.SerializeObject(filterStorage)).Result.Content.ReadAsStringAsync(); Dictionary <string, object> resultStorage = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseStorage.Result); var jsonStorage = resultStorage.Single(p => p.Key.Equals("data")).Value; Dictionary <string, object> storage = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonStorage.ToString())[0]; /* Create Inventory Document */ List <InventoryDocumentItem> inventoryDocumentItems = new List <InventoryDocumentItem>(); List <MaterialsRequestNote_Item> list = Model.MaterialsRequestNote_Items .GroupBy(m => new { m.ProductId, m.ProductCode, m.ProductName }) .Select(s => new MaterialsRequestNote_Item { ProductId = s.First().ProductId, ProductCode = s.First().ProductCode, ProductName = s.First().ProductName, Length = s.Sum(d => d.Length) }).ToList(); foreach (MaterialsRequestNote_Item item in list) { InventoryDocumentItem inventoryDocumentItem = new InventoryDocumentItem(); inventoryDocumentItem.ProductId = int.Parse(item.ProductId); inventoryDocumentItem.ProductCode = item.ProductCode; inventoryDocumentItem.ProductName = item.ProductName; inventoryDocumentItem.Quantity = item.Length; inventoryDocumentItem.UomId = int.Parse(uom["Id"].ToString()); inventoryDocumentItem.UomUnit = uom["Unit"].ToString(); inventoryDocumentItems.Add(inventoryDocumentItem); } InventoryDocument inventoryDocument = new InventoryDocument { Date = DateTimeOffset.UtcNow, ReferenceNo = Model.Code, ReferenceType = "Surat Permintaan Barang", Type = Type, StorageId = int.Parse(storage["_id"].ToString()), StorageCode = storage["code"].ToString(), StorageName = storage["name"].ToString(), Items = inventoryDocumentItems }; InventoryDocumentFacade inventoryDocumentFacade = (InventoryDocumentFacade)ServiceProvider.GetService(typeof(InventoryDocumentFacade)); await inventoryDocumentFacade.Create(inventoryDocument, Username); //var response = httpClient.PostAsync($"{APIEndpoint.Inventory}{inventoryDocumentURI}", new StringContent(JsonConvert.SerializeObject(inventoryDocument).ToString(), Encoding.UTF8, General.JsonMediaType)).Result; //response.EnsureSuccessStatusCode(); }
public InventoryDocumentDataUtil(InventoryDocumentItemDataUtil inventoryDocumentItemDataUtil, InventoryDocumentFacade facade) { this.inventoryDocumentItemDataUtil = inventoryDocumentItemDataUtil; this.facade = facade; }
public InventoryDocumentController(IMapper mapper, InventoryDocumentFacade facade, IdentityService identityService) { _mapper = mapper; _facade = facade; this.identityService = identityService; }