public async Task FetchCurrentScmStock() { if (this.PhoneNumberChanged) { this.ScmUnitsInStock.Clear(); } if (this.ScmUnitsInStock.Count > 0) { return; } this.NextButtonEnabled = false; this.IsBusy = true; this.ScmHasStock = true; // though we dont know yet try { this._previousPhoneNumber = this.DsrPhoneNumber; string urlParams = string.Format("?dsrPersonId={0}&productTypeId={1}", this.DsrStock.PersonId, string.Empty); List <Product> productsListResponse = await this.RemoteProductService.GetProducts(urlParams); List <List <Product> > groupedProductList = productsListResponse.GroupBy(u => u.ProductTypeId).Select(grp => grp.ToList()).ToList(); ObservableCollection <ScmStock> productList = new ObservableCollection <ScmStock>(); foreach (List <Product> products in groupedProductList) { ScmStock scmStock = new ScmStock(); List <string> units = new List <string>(); foreach (var product in products) { scmStock.ProductTypeId = product.ProductTypeId; scmStock.Name = product.ProductName; units.Add(product.SerialNumber); } scmStock.SerialNumbers = units; productList.Add(scmStock); } this.ScmUnitsInStock = productList; } finally { this.NextButtonEnabled = true; this.IsBusy = false; } }
public async Task <ManageStockPostApiResponse> ReceiveStock() { this.ProgressDialogMessage = this._deviceResource.PleaseWait; this.IsBusy = true; ReturnedProduct product = new ReturnedProduct { DsrPhone = this.DsrPhoneNumber, PersonId = this.DsrStock.PersonId, PersonRoleId = this.DsrStock.PersonRoleId }; product.Reason = this.SelectedReason.Reason; List <List <DeviceAllocationItem> > groupedSelectedList = this.SelectedUnits.GroupBy(u => u.ProductTypeId).Select(grp => grp.ToList()).ToList(); List <ScmStock> returnObj = new List <ScmStock>(); foreach (List <DeviceAllocationItem> products in groupedSelectedList) { ScmStock stock = new ScmStock(); stock.ProductTypeId = products[0].ProductTypeId; stock.Name = products[0].HeaderText; List <string> units = new List <string>(); foreach (var item in products) { units.Add(item.SerialNumber); } stock.SerialNumbers = units; returnObj.Add(stock); } product.Units = returnObj; ManageStockPostApiResponse response = await this.DsrStockAllocationService.ReceiveStockFromDsr(product); this.IsBusy = false; if (response == null) { return(new ManageStockPostApiResponse { Success = false, Text = "Units could not be returned." }); } return(response); }
private void StockListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs) { ScmStock selectedProduct = this.ManageStockViewModel.ScmUnitsInStock[(int)itemClickEventArgs.Id]; ScmStock previousSelection = this.ManageStockViewModel.SelectedProduct; // If we select a different product, clear any previous selection as we don't support multiple products yet! if (previousSelection != null && previousSelection.Name != selectedProduct.Name) { this.ManageStockViewModel.SelectedUnits.Clear(); } this.ManageStockViewModel.SelectedProduct = selectedProduct; FragmentTransaction ft = FragmentManager.BeginTransaction(); var fragment = new FragmentSelectUnits(); ft.Replace(Resource.Id.main_content, fragment, ManageStockView.MainContentFragmentTag); ft.Commit(); this.ManageStockViewModel.ShowNoInternetAlert = false; }
public async Task <ManageStockPostApiResponse> AllocateSelectedUnits() { this.ProgressDialogMessage = this._deviceResource.PleaseWait; this.IsBusy = true; SelectedProduct product = new SelectedProduct { DsrPhone = this.DsrPhoneNumber, PersonId = this.DsrStock.PersonId, PersonRoleId = this.DsrStock.PersonRoleId }; List <string> units = new List <string>(); foreach (var unit in this.SelectedUnits) { units.Add(unit.SerialNumber); } ScmStock scmStock = new ScmStock { ProductTypeId = this.SelectedProduct.ProductTypeId, SerialNumbers = units }; product.Units = new List <ScmStock> { scmStock }; ManageStockPostApiResponse response = await this.DsrStockAllocationService.AllocateUnitsToDsr(product); this.IsBusy = false; if (response == null) { return(new ManageStockPostApiResponse { Success = false, Text = this._deviceResource.UnitsCouldNotBeAllocated }); } return(response); }