private static void CreateNewRelocationPlaces(Candidate destination, CandidateDTO source, IRepository <City> locationRepo) { source.RelocationPlaces.Where(x => x.IsNew()).ToList().ForEach(newRelocationPlace => { var toDomain = DTOService.ToEntity <RelocationPlaceDTO, RelocationPlace>(newRelocationPlace); destination.RelocationPlaces.Add(toDomain); }); }
public virtual IHttpActionResult Add([FromBody] ViewModel entity) { if (ModelState.IsValid) { var newEntity = DTOService.ToEntity <ViewModel, DomainEntity>(entity); _currentRepo.Add(newEntity); return(Json(DTOService.ToDTO <DomainEntity, ViewModel>(_currentRepo.GetAll().Last()))); } return(BadRequest()); }
public virtual IHttpActionResult Put(int id, [FromBody] ViewModel changedEntity) { if (ModelState.IsValid) { if (changedEntity != null) { var changedDomainEntity = DTOService.ToEntity <ViewModel, DomainEntity>(changedEntity); _currentRepo.Update(changedDomainEntity); return(Json(DTOService.ToDTO <DomainEntity, ViewModel>(_currentRepo.Get(changedDomainEntity.Id)), SERIALIZER_SETTINGS)); } return(NotFound()); } return(BadRequest()); }