public async Task <ActionResult> Post([FromForm] AreaCreationDTO areaCreationDTO) { var entity = mapper.Map <Area>(areaCreationDTO); if (areaCreationDTO.AreaIcon != null) { entity.AreaIcon = await SaveIcon(areaCreationDTO.AreaIcon); } context.Add(entity); await context.SaveChangesAsync(); return(new CreatedAtRouteResult("GetArea", new { id = entity.Id }, mapper.Map <AreaDTO>(entity))); }
public async Task <ActionResult> Put(int id, [FromForm] AreaCreationDTO areaCreationDTO) { var entity = await context.Areas.FirstOrDefaultAsync(area => area.Id == id); if (entity == null) { return(NotFound()); } entity = mapper.Map(areaCreationDTO, entity); if (areaCreationDTO.AreaIcon != null) { if (!string.IsNullOrEmpty(entity.AreaIcon)) { await fileStorage.RemoveFile(entity.AreaIcon, ApplicationConstants.ImageContainerNames.AreaContainer); } entity.AreaIcon = await SaveIcon(areaCreationDTO.AreaIcon); } context.Entry(entity).State = EntityState.Modified; await context.SaveChangesAsync(); return(NoContent()); }