private async Task InsertService() { if (ValidateInputs()) { ServiceInsertVM serviceInsertVM = new ServiceInsertVM() { Name = TbName.Text, Price = decimal.Parse(TbPrice.Text) }; ls.LblLoading.Text = "Adding"; ls.Show(); bool success = await serviceApi.InsertService(serviceInsertVM); ls.Close(); if (success) { Close(); } else { MessageBox.Show("Fail!"); } } else { MessageBox.Show("All input fields are required and price must be a number!"); } }
public bool InsertService(ServiceInsertVM serviceInsertVM) { Service service = new Service() { Name = serviceInsertVM.Name, Price = serviceInsertVM.Price }; unitOfWork.Services.Add(service); int success = unitOfWork.Complete(); return(success > 0); }
public async Task <bool> InsertService(ServiceInsertVM serviceInsertVM) { StringContent content = GetStringContent(serviceInsertVM); HttpClient request = new HttpClient(); HttpResponseMessage response = await request.PostAsync($"{ API_URL }/InsertService", content); if (response.IsSuccessStatusCode) { bool result = await response.Content.ReadAsAsync <bool>(); return(result); } return(false); }