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