public async Task <ActionResult> EditSocial([FromRoute] int id, [FromBody] SocialCreateDTO social) { var _social = await _context.Socials.FindAsync(id); if (_social == null) { return(NotFound(id)); } if (social.PlatformTypeId.HasValue) { var type = await _context.SocialPlatformTypes.FindAsync(social.PlatformTypeId); if (type == null) { return(BadRequest(new { error = $"The platform type with id: {social.PlatformTypeId} don't exists" })); } _social.PlatformType = type; } _social = _mapper.Map <SocialCreateDTO, Social>(social, _social); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> CreateSocial([FromBody] SocialCreateDTO social) { var type = await _context.SocialPlatformTypes.FindAsync(social.PlatformTypeId); if (type == null) { return(BadRequest(new { error = $"The platform type with id: {social.PlatformTypeId} don't exists" })); } var _social = _mapper.Map <Social>(social); _social.PlatformType = type; await _context.Socials.AddAsync(_social); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateSocial), new { id = _social.Id })); }