public async Task <string> UpdateInventory(InventoryThumbnail inventory) { string result = string.Empty; var data = JsonConvert.SerializeObject(JsonConvert.SerializeObject(inventory)); System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(inventory, Formatting.Indented)); _httpClient.DefaultRequestHeaders.Clear(); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", string.Format("Bearer {0}", Settings.UserToken)); StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); var response = await _httpClient.PutAsync(string.Format(InventoryEndPoint, Settings.Server, inventory.inventory_id), content); string resultContent = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { result = resultContent; } else { throw new Exception(resultContent); } return(result); }
private void OnAddItemToList(InventoryThumbnail inventory) { if (_inventoryList.Any(i => i.Item.inventory_id == inventory.inventory_id)) { Device.BeginInvokeOnMainThread(() => { PageDialogService.DisplayAlertAsync("Warnning", "Inventory exists in list", "OK"); }); } else { _inventoryList.Add(new WrappedSelection <InventoryThumbnail>() { IsSelected = false, Item = inventory }); AccessionCount = InventoryList.Select(i => i.Item.AccessionNumber).Distinct().Count(); TotalQuantity = _inventoryList.Select(i => i.Item.quantity_on_hand).Sum(); } }
public override async void OnNavigatedTo(INavigationParameters parameters) { try { if (_dataviewColumnList == null) { _dataviewColumnList = await _restClient.GetDataviewAtributeList(Settings.WorkgroupInventoryThumbnailDataview); if (_dataviewColumnList != null) { if (_dataviewColumnList.Count > 1) { Header1 = _dataviewColumnList[1].title; } if (_dataviewColumnList.Count > 2) { Header2 = _dataviewColumnList[2].title; } if (_dataviewColumnList.Count > 3) { Header3 = _dataviewColumnList[3].title; } if (_dataviewColumnList.Count > 4) { Header4 = _dataviewColumnList[4].title; } if (_dataviewColumnList.Count > 5) { Header5 = _dataviewColumnList[5].title; } if (_dataviewColumnList.Count > 6) { Header6 = _dataviewColumnList[6].title; } if (_dataviewColumnList.Count > 7) { Header7 = _dataviewColumnList[7].title; } } } if (parameters.ContainsKey("inventory")) //Update UI { InventoryThumbnail tempInventory = (InventoryThumbnail)parameters["inventory"]; WrappedSelection <InventoryThumbnail> inventoryThumbnailItem = _inventoryList.FirstOrDefault(item => item.Item.inventory_id == tempInventory.inventory_id); if (inventoryThumbnailItem == null) { InventoryList.Add(new WrappedSelection <InventoryThumbnail> { Item = tempInventory, IsSelected = false }); } else { inventoryThumbnailItem.Item = tempInventory; /* * int index = InventoryList.IndexOf(inventoryThumbnailItem); * InventoryList.Remove(inventoryThumbnailItem); * InventoryList.Insert(index, new WrappedSelection<InventoryThumbnail> { Item = tempInventory, IsSelected = false }); */ } } if (parameters.ContainsKey("InventoryThumbnail")) { InventoryThumbnail tempInventory = (InventoryThumbnail)parameters["InventoryThumbnail"]; WrappedSelection <InventoryThumbnail> inventoryThumbnailItem = _inventoryList.FirstOrDefault(item => item.Item.inventory_id == tempInventory.inventory_id); if (inventoryThumbnailItem == null) { InventoryList.Add(new WrappedSelection <InventoryThumbnail> { Item = tempInventory, IsSelected = false }); } else { inventoryThumbnailItem.Item = tempInventory; } AccessionCount = InventoryList.Select(i => i.Item.AccessionNumber).Distinct().Count(); TotalQuantity = _inventoryList.Select(i => i.Item.quantity_on_hand).Sum(); } if (parameters.ContainsKey("InventoryThumbnailList")) { List <InventoryThumbnail> inventoryList = (List <InventoryThumbnail>)parameters["InventoryThumbnailList"]; foreach (var inventoryThumbnail in inventoryList) { var wrappedInventory = InventoryList.FirstOrDefault(x => x.Item.inventory_id == inventoryThumbnail.inventory_id); if (wrappedInventory == null) { WrappedSelection <InventoryThumbnail> temp = new WrappedSelection <InventoryThumbnail>() { Item = inventoryThumbnail, IsSelected = false }; InventoryList.Add(temp); } else { wrappedInventory.Item = inventoryThumbnail; /*int index = _inventoryList.IndexOf(wrappedInventory); * InventoryList.Remove(wrappedInventory); * InventoryList.Insert(index, new WrappedSelection<InventoryThumbnail> { Item = inventoryThumbnail, IsSelected = wrappedInventory.IsSelected });*/ } } AccessionCount = InventoryList.Select(i => i.Item.AccessionNumber).Distinct().Count(); TotalQuantity = _inventoryList.Select(i => i.Item.quantity_on_hand).Sum(); } } catch (Exception ex) { await PageDialogService.DisplayAlertAsync("Error", ex.Message, "OK"); } }
private async void OnSaveInventoryCommandExecuted() { try { /*foreach (var att in InventoryAtributeList) * { * if (att.IsRequired) * { * if (att.Value == null) * { * throw new Exception(string.Format("{0} is required", att.Caption)); * } * if (att.Value.GetType() == typeof(string) && att.Type != typeof(string) && string.IsNullOrWhiteSpace(att.Value.ToString())) * { * throw new Exception(string.Format("{0} is required", att.Caption)); * } * if (att.Type == typeof(int) && (int)att.Value <= 0) * { * throw new Exception(string.Format("{0} is required", att.Caption)); * } * } * }*/ foreach (var att in InventoryAtributeList) { if (!att.IsReadOnly) { PropertyInfo[] props = typeof(Inventory).GetProperties(); var prop = props.FirstOrDefault(x => x.Name.Equals(att.Name)); if (prop != null) { if (att.ControlType.Equals("TEXTPICKER")) { string value; if (att.IsPicker) { value = att.Value == null ? null : (string)att.Value; } else { value = att.SecondValue; } prop.SetValue(NewInventory, value); } else if (att.ControlType.Equals("DROPDOWN")) { if (att.CodeValueList != null && att.CodeValue != null) { prop.SetValue(NewInventory, (string)att.CodeValue.ValueMember); } else { prop.SetValue(NewInventory, null); } } else { //check if Value is null if (att.Value == null) { prop.SetValue(NewInventory, null); } else { if (att.Value.GetType() == typeof(string)) //If value is empty and attribute type is different from string, assign null or 0? { TypeConverter converter = TypeDescriptor.GetConverter(att.Type); converter = TypeDescriptor.GetConverter(att.Type); var newValue = converter.ConvertFrom(att.Value); prop.SetValue(NewInventory, newValue); } else { if (att.ControlType.Equals("CHECKBOX") && att.Value.GetType() == typeof(bool)) { if ((bool)att.Value) { prop.SetValue(NewInventory, "Y"); } else { prop.SetValue(NewInventory, "N"); } } else { prop.SetValue(NewInventory, att.Value); } } } } } } } string result = null; List <InventoryThumbnail> newInventoryList = null; if (_isNewInventory) { result = await _restClient.CreateInventory(NewInventory); await PageDialogService.DisplayAlertAsync("Saved Inventory Id", result, "OK"); newInventoryList = await _restClient.Search("@inventory.inventory_id = " + result, "get_mob_inventory_thumbnail", "inventory"); } else { result = await _restClient.UpdateInventory(NewInventory); await PageDialogService.DisplayAlertAsync("Message", "Successfully saved", "OK"); newInventoryList = await _restClient.Search("@inventory.inventory_id = " + NewInventory.inventory_id, "get_mob_inventory_thumbnail", "inventory"); } InventoryThumbnail newInventory = newInventoryList[0]; var navigationParams = new NavigationParameters(); navigationParams.Add("InventoryThumbnail", newInventory); await NavigationService.GoBackAsync(navigationParams); } catch (Exception ex) { await PageDialogService.DisplayAlertAsync("Error", ex.Message, "OK"); } }
public override async void OnNavigatedTo(INavigationParameters parameters) { try { if (parameters.ContainsKey("inventoryList")) { List <InventoryThumbnail> inventoryList = (List <InventoryThumbnail>)parameters["inventoryList"]; foreach (var inventoryThumbnail in inventoryList) { var wrappedInventory = InventoryList.FirstOrDefault(x => x.Item.inventory_id == inventoryThumbnail.inventory_id); if (wrappedInventory == null) { WrappedSelection <InventoryThumbnail> temp = new WrappedSelection <InventoryThumbnail>() { Item = inventoryThumbnail, IsSelected = false }; InventoryList.Add(temp); } else { int index = _inventoryList.IndexOf(wrappedInventory); InventoryList.Remove(wrappedInventory); InventoryList.Insert(index, new WrappedSelection <InventoryThumbnail> { Item = inventoryThumbnail, IsSelected = wrappedInventory.IsSelected }); } } AccessionCount = InventoryList.Select(i => i.Item.accession_id).Distinct().Count(); } if (parameters.ContainsKey("InventoryThumbnail")) { InventoryThumbnail inventoryThumbnail = (InventoryThumbnail)parameters["InventoryThumbnail"]; WrappedSelection <InventoryThumbnail> inventoryThumbnailItem = _inventoryList.FirstOrDefault(item => item.Item.inventory_id == inventoryThumbnail.inventory_id); if (inventoryThumbnailItem == null) { InventoryList.Add(new WrappedSelection <InventoryThumbnail> { Item = inventoryThumbnail, IsSelected = false }); } else { int index = InventoryList.IndexOf(inventoryThumbnailItem); InventoryList.Remove(inventoryThumbnailItem); InventoryList.Insert(index, new WrappedSelection <InventoryThumbnail> { Item = inventoryThumbnail, IsSelected = false }); } } if (parameters.ContainsKey("message")) { await _pageDialogService.DisplayAlertAsync("Message", (string)parameters["message"], "OK"); } } catch (Exception ex) { await _pageDialogService.DisplayAlertAsync("Error", ex.Message, "OK"); } }