public async Task <ActionResult> Put(int id, [FromForm] TechnologyCreationDTO technologyCreationDTO) { var entity = await context.Technologies.FirstOrDefaultAsync(t => t.Id == id); if (entity == null) { return(NotFound()); } entity = mapper.Map(technologyCreationDTO, entity); if (technologyCreationDTO.TechnologyIcon != null) { if (!string.IsNullOrEmpty(entity.TechnologyIcon)) { await fileStorage.RemoveFile(entity.TechnologyIcon, ApplicationConstants.ImageContainerNames.TechnologyContainer); } entity.TechnologyIcon = await SaveIcon(technologyCreationDTO.TechnologyIcon); } context.Entry(entity).State = EntityState.Modified; await context.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Post([FromForm] TechnologyCreationDTO technologyCreationDTO) { var entity = mapper.Map <Technology>(technologyCreationDTO); if (technologyCreationDTO.TechnologyIcon != null) { entity.TechnologyIcon = await SaveIcon(technologyCreationDTO.TechnologyIcon); } context.Add(entity); await context.SaveChangesAsync(); return(new CreatedAtRouteResult("GetTechnology", new { id = entity.Id }, mapper.Map <TechnologyDTO>(entity))); }