/// <summary> /// Add a new model to the database /// </summary> /// <param name="model">A valid <see cref="ConcursoSena"/> model</param> /// <exception cref="ArgumentException"></exception> /// <exception cref="DbException"></exception> /// <exception cref="DuplicateKeyException"></exception> /// <returns>Returns the <see cref="ConcursoSena" /> model</returns> public async Task <ConcursoSena> Add(ConcursoSena model) { var existingModel = await _concursos.FirstOrDefault(f => f.Concurso.Equals(model.Concurso)); if (existingModel != null) { throw new DuplicateKeyException(existingModel, "Same concurso number already added to the database."); } return(await _concursos.Add(model)); }
/// <summary> /// Updates an existing model /// </summary> /// <param name="id">A valid <see cref="int"> id.</param> /// <param name="model">A valid <see cref="ConcursoSena"/> model</param> /// <exception cref="ArgumentNullException" /> /// <exception cref="EntryPointNotFoundException" /> /// <exception cref="DbException" /> /// <returns>Returns the updated <see cref="ConcursoSena" /> model</returns> public async Task <ConcursoSena> Update(int id, ConcursoSena model) { var existingModel = await _concursos.FirstOrDefault(f => f.Id.Equals(id)); if (existingModel == null) { throw new EntryPointNotFoundException( message: "Could not update model on specified id." ); } existingModel = _mapper.Map(model, existingModel); return(await _concursos.Update(existingModel)); }