//сохранение товара private async void SaveGoods(object goodsObject) { tdGoods goods = goodsObject as tdGoods; if (goods != null) { IsBusy = true; // редактирование if (goods.tdGoodsID > 0) { tdGoods updGoods = await mobileService.Update(goods); // заменяем объект в списке на новый if (updGoods != null) { int pos = Goods.IndexOf(updGoods); Goods.RemoveAt(pos); Goods.Insert(pos, updGoods); } } // добавление else { tdGoods addedGoods = await mobileService.Add(goods); if (addedGoods != null) { Goods.Add(addedGoods); } } IsBusy = false; } Back(); }
// обновляем товар public async Task <tdGoods> Update(tdGoods goods) { HttpClient client = GetClient(); var response = await client.PutAsync(Url + "/" + goods.tdGoodsID, new StringContent( JsonConvert.SerializeObject(goods), Encoding.UTF8, "application/json")); if (response.StatusCode != HttpStatusCode.OK) { return(null); } return(JsonConvert.DeserializeObject <tdGoods>( await response.Content.ReadAsStringAsync())); }
//удаляем товар private async void DeleteGoods(object goodsObject) { tdGoods goods = goodsObject as tdGoods; if (goods != null) { IsBusy = true; tdGoods deletedGoods = await mobileService.Delete(goods.tdGoodsID); if (deletedGoods != null) { Goods.Remove(deletedGoods); } IsBusy = false; } Back(); }