public async Task <ActionResult> Put(int id, [FromForm] SponsorCreationDTO sponsorCreationDTO) { var entity = await applicationDbContext.Sponsors.FirstOrDefaultAsync(x => x.Id == id); if (entity == null) { return(NotFound()); } entity = mapper.Map(sponsorCreationDTO, entity); if (sponsorCreationDTO.SponsorIcon != null) { if (!string.IsNullOrEmpty(entity.SponsorIcon)) { await fileStorage.RemoveFile(entity.SponsorIcon, ApplicationConstants.ImageContainerNames.SponsorContainer); } entity.SponsorIcon = await SaveIcon(sponsorCreationDTO.SponsorIcon); } applicationDbContext.Entry(entity).State = EntityState.Modified; await applicationDbContext.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Post([FromForm] SponsorCreationDTO sponsorCreationDTO) { var entity = mapper.Map <Sponsor>(sponsorCreationDTO); if (sponsorCreationDTO.SponsorIcon != null) { entity.SponsorIcon = await SaveIcon(sponsorCreationDTO.SponsorIcon); } applicationDbContext.Add(entity); await applicationDbContext.SaveChangesAsync(); var readDTO = mapper.Map <SponsorDTO>(entity); return(new CreatedAtRouteResult("GetSponsor", new { id = readDTO.Id }, readDTO)); }