public ActionResult AddPerson(AddPersonEntity person) { //Do any custom validations needed try { if (ModelState.IsValid) { //save this.SearchService.SavePerson(person); return(Json(new { success = true, responseText = "" })); } else { string modelErrorMessages = string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage)); return(Json(new { success = false, responseText = modelErrorMessages })); } } catch (Exception ex) { throw; } }
public void SavePerson(AddPersonEntity personEntity) { if (personEntity == null) { throw new ArgumentNullException("personEntity"); } try { Person person = new Person(); personEntity.TrimStringProperties(); Mapper.Map <AddPersonEntity, Person>(personEntity, person); //Create Model Entity from the UI representation entity //If we use byte[] for image //person.Picture = Convert.FromBase64String(personEntity.Base64Picture.Replace("data:image/jpeg;base64,", String.Empty)); this.SearchRepository.SavePerson(person); } catch (Exception ex) { throw; } }