public GetProfileDto AddProfile(AddProfileDto addProfileDto) { AddProfileDtoValidate(addProfileDto); var profile = _mapper.Map <Profile>(addProfileDto); _dbContext.Profiles.Add(profile); _dbContext.SaveChanges(); return(_mapper.Map <GetProfileDto>(profile)); }
public async Task <GetProfileDto> AddProfileAsync(AddProfileDto addProfileDto) { AddProfileDtoValidate(addProfileDto); var profile = _mapper.Map <Profile>(addProfileDto); await _dbContext.Profiles.AddAsync(profile); await _dbContext.SaveChangesAsync(); return(_mapper.Map <GetProfileDto>(profile)); }
private static void AddProfileDtoValidate(AddProfileDto addProfileDto) { if (addProfileDto == null) { throw new ArgumentNullException(nameof(addProfileDto)); } if (!addProfileDto.Validate()) { throw new InvalidOperationException(); } }
public async Task <ActionResult <GetProfileDto> > CreateProfile(AddProfileDto addProfileDto) { GetProfileDto getProfileDto = null; try { getProfileDto = await _profileService.AddProfileAsync(addProfileDto); } catch { return(BadRequest()); } return(CreatedAtRoute(nameof(GetProfileById), new { id = getProfileDto.Id }, getProfileDto)); }