public async Task SaveAsync(RelativesAddress entity) { try { if (entity == null) { return; } using (var timeLineContext = _contextFactory.GetTimeLineContext()) { var entityModel = await timeLineContext .RelativesAddresses .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id)); if (entityModel == null) { entityModel = new DA.RelativesAddress(); MapForUpdateentity(entity, entityModel); await timeLineContext.RelativesAddresses.AddAsync(entityModel); } else { MapForUpdateentity(entity, entityModel); } timeLineContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Put([FromBody] RelativesAddress value) { try { var entity = _mapper.Map <BL.RelativesAddress>(value); var id = _service.SaveAsync(entity); return(Ok(id)); } catch (Exception) { return(BadRequest()); } }
private void MapForUpdateentity(RelativesAddress entity, DA.RelativesAddress daEntity) { daEntity.Id = entity.Id; }