private async void Button_Clicked(object sender, EventArgs e) { GoodsDetailViewModel gdvm = BindingContext as GoodsDetailViewModel; if (gdvm.GoodsModel.User.Name == App.StaticUser.Name) { await App.GoodsManager.DeleteGoodsTaskAsync(gdvm.GoodsModel); GoodsViewModel.refresh(); DependencyService.Get <IToastService>().LongAlert("删除商品成功!"); await Navigation.PopAsync(); } else { if (App.StaticUser.TomatoPoints >= gdvm.GoodsModel.Price) { App.StaticUser.TomatoPoints -= gdvm.GoodsModel.Price; await App.UserManager.ModifyUserTaskAsync(App.StaticUser); DependencyService.Get <IToastService>().LongAlert("购买商品成功!"); await Navigation.PopAsync(); } else { DependencyService.Get <IToastService>().LongAlert("番茄点不足,不能购买!"); } } }
public async Task <IActionResult> GoodsInfo(string id) { GoodsDetailViewModel webModel = new GoodsDetailViewModel(); if (!string.IsNullOrEmpty(id)) { //编辑信息,加载物品相关信息 webModel = await _service.GetGoodsAsync(Convert.ToInt64(id), _context); } return(View(webModel)); }
protected override void OnAppearing() { GoodsDetailViewModel gdvm = BindingContext as GoodsDetailViewModel; if (gdvm.GoodsModel.User.Name == App.StaticUser.Name) { bt.Text = "删除"; } else { bt.Text = "购买"; } }
/// <summary> /// 获取物品详细信息 /// </summary> /// <param name="id"></param> /// <param name="context"></param> /// <returns></returns> public async Task <GoodsDetailViewModel> GetGoodsAsync(long id, ApplicationDbContext context) { var webModel = new GoodsDetailViewModel(); try { var model = await AdmissionRepository.GetGoodsAsync(id, context); webModel.Id = model.Id.ToString(); webModel.Description = model.Description; webModel.Name = model.Name; webModel.Size = model.Size; } catch (Exception ex) { _logger.LogError("获取物品数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); } return(webModel); }
private void Button_Clicked_1(object sender, EventArgs e) { GoodsDetailViewModel gdvm = BindingContext as GoodsDetailViewModel; CharPageViewModel.AUser CurrentUser = new CharPageViewModel.AUser() { UserId = App.StaticUser.UserId, Name = App.StaticUser.Name, Avatar = App.StaticUser.Imgurl }; CharPageViewModel.AUser SendToUser = new CharPageViewModel.AUser() { UserId = gdvm.GoodsModel.UserId, Name = gdvm.GoodsModel.User.Name, Avatar = gdvm.GoodsModel.User.Imgurl }; Navigation.PushAsync(new ChatPage() { BindingContext = new CharPageViewModel(CurrentUser, SendToUser) }); }