private async void BtnSubmit_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtBox_CountryDetails.Text) || string.IsNullOrEmpty(txtBox_CountryName.Text) || picBox_CountryPic.Image == null) { MessageBox.Show("Fields can't be empty", "OK"); return; } var request = new CountryInsertRequest { CountryName = txtBox_CountryName.Text, CountryDetails = txtBox_CountryDetails.Text }; using (MemoryStream stream = new MemoryStream()) { picBox_CountryPic.Image.Save(stream, picBox_CountryPic.Image.RawFormat); request.Picture = stream.ToArray(); } CountryInsertRequest res = null; if (_id.HasValue) { res = await _service.Update <CountryInsertRequest>(_id.Value, request); } else { res = await _service.Insert <CountryInsertRequest>(request); } var message = (res != null) ? "Successufully added new country" : "Error: can not add new country"; MessageBox.Show(message); }
public Model.Country Insert(CountryInsertRequest request) { Database.Country entity = _mapper.Map <Database.Country>(request); _context.Country.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Country>(entity)); }
public Model.Country Update(int id, CountryInsertRequest request) { Database.Country entity = _context.Country.Where(x => x.CountryId == id).FirstOrDefault(); _context.Country.Attach(entity); _context.Country.Update(entity); entity = _mapper.Map(request, entity); _context.SaveChanges(); return(_mapper.Map <Model.Country>(entity)); }
private async void btnSubmit_Click(object sender, EventArgs e) { if (ValidateChildren()) { var request = new CountryInsertRequest { Name = txtName.Text }; CountryModel entity = null; entity = await _countryService.Insert <CountryModel>(request); if (entity != null) { MessageBox.Show("Success!"); if (Form.ActiveForm != null) { Form.ActiveForm.Close(); } } } }