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