private async void ShowInfoCus(int?obj) { if (obj != null) { var index = (int)obj; var cus = ListCustomer.SingleOrDefault(t => t.CusID == index); if (cus != null) { Name = cus.Name; CusID = cus.CusID.ToString(); ImgCus = cus.Avatar.LoadImage(); Phone = cus.Phone; if (cus.Sex == true) { IsB = true; } if (cus.Sex == false) { IsG = true; } Address = cus.Address; Email = cus.Email; if (cus.Kind != null) { int indexcus = (int)cus.Kind; Kind = ListKinds.ElementAt(indexcus); } else { Kind = null; } } await DialogHost.Show(new CustomerProfile(), DialogHostId); } }
private async void Submit(string obj) { try { var newcus = new Customer() { Email = Email, Address = Address, Avatar = ImgCus.ConvertToByte(), Name = Name, Phone = Phone, }; if (IsB) { newcus.Sex = true; } if (IsG) { newcus.Sex = false; } if (Kind != null) { newcus.Kind = ListKinds.IndexOf(Kind); } if (string.IsNullOrEmpty(obj)) { //Create new customer var objresult = await customer_repo.Add(newcus); if (objresult != null) { dc = new DialogContent() { Content = "Thêm Thành Công", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; DialogHost.CloseDialogCommand.Execute(null, null); await DialogHost.Show(dialog, DialogHostId); ListCustomer.Add(objresult); } else { dc = new DialogContent() { Content = "Thêm Thất Bại", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; DialogHost.CloseDialogCommand.Execute(null, null); await DialogHost.Show(dialog, DialogHostId); } } else { //update customer newcus.CusID = Convert.ToInt32(obj); if (await customer_repo.Update(newcus)) { dc = new DialogContent() { Content = "Cập Nhật Thành Công", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; DialogHost.CloseDialogCommand.Execute(null, null); await DialogHost.Show(dialog, DialogHostId); ListCustomer = new ObservableCollection <Customer>(await customer_repo.GetAllAsync()); } else { dc = new DialogContent() { Content = "Cập Nhật Thất Bại", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; DialogHost.CloseDialogCommand.Execute(null, null); await DialogHost.Show(dialog, DialogHostId); } } } catch { dc.Content = "Có Lỗi"; dc.Tilte = "Thông Báo"; dialog = new DialogOk() { DataContext = dc }; DialogHost.CloseDialogCommand.Execute(null, null); await DialogHost.Show(dialog, DialogHostId); } }