public async Task SaveAsync(EntranceExam entity)
        {
            try
            {
                if (entity == null)
                {
                    return;
                }

                using (var timeLineContext = _contextFactory.GetTimeLineContext())
                {
                    var entityModel = await timeLineContext
                                      .EntranceExams
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.EntranceExam();
                        MapForUpdateentity(entity, entityModel);
                        await timeLineContext.EntranceExams.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateentity(entity, entityModel);
                    }


                    timeLineContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
 public async Task <IActionResult> Put([FromBody] EntranceExam value)
 {
     try
     {
         var entity = _mapper.Map <BL.EntranceExam>(value);
         var id     = _service.SaveAsync(entity);
         return(Ok(id));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
 private void MapForUpdateentity(EntranceExam entity, DA.EntranceExam daEntity)
 {
     daEntity.Id = entity.Id;
 }