public async Task <ActionResult> EditSocialPlatformType([FromRoute] int id, [FromBody] SocialPlatformTypeCreateDTO socialPlatformType) { var _socialPlatformType = await _context.SocialPlatformTypes.FindAsync(id); if (_socialPlatformType == null) { return(NotFound(id)); } _socialPlatformType = _mapper.Map <SocialPlatformTypeCreateDTO, SocialPlatformType>( socialPlatformType, _socialPlatformType); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> CreateSocialPlatformType([FromBody] SocialPlatformTypeCreateDTO socialPlatformType) { if ((await _context.SocialPlatformTypes.FirstOrDefaultAsync(x => x.Name == socialPlatformType.Name)) != null) { return(BadRequest(new { error = "Already exists a social platform type with this name" })); } var _socialPlatformType = _mapper.Map <SocialPlatformType>(socialPlatformType); await _context.SocialPlatformTypes.AddAsync(_socialPlatformType); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateSocialPlatformType), new { id = _socialPlatformType.Id })); }