public async Task <ImageDto> Save(ImageEditDto itemToEdit) { Image res; if (itemToEdit.Id != Guid.Empty) { _logger.LogDebug($"Calling Update image for id=[{itemToEdit.Id}]"); //edit res = await this.GetInner(itemToEdit.Id); if (res == null) { throw new NotFoundException($"Image with id={itemToEdit.Id} not exists!"); } res.Path = itemToEdit.Path; _dbCtx.Images.Update(res); _dbCtx.SaveChanges(); } else { //insert res = itemToEdit.ToEntity(); res.Id = Guid.NewGuid(); _logger.LogDebug($"Calling Insert image for id=[{res.Id}] (temp id, not created yet!)"); await _dbCtx.Images.AddAsync(res); _dbCtx.SaveChanges(); } return(res.ToDto()); }
public async Task <ActionResult <ImageDto> > Put([FromBody] ImageEditDto value) { if (value.Id == Guid.Empty) { throw new Exception("Unable to edit a Image without ID"); } var res = await _service.Save(value); return(res); }
public static Image ToEntity(this ImageEditDto e) { if (e == null) { return(null); } var res = new Image(); res.Id = e.Id; res.Path = e.Path; return(res); }
public async Task <ImageDto[]> SetDefault(ImageEditDto itemToEdit) { Image[] imageList = new Image[] { }; foreach (var image in imageList) { if (image.Id == itemToEdit.Id) { image.IsDefault = true; } else { image.IsDefault = false; } } _dbCtx.UpdateRange(imageList); await _dbCtx.SaveChangesAsync(); return(imageList.Select(x => x.ToDto()).ToArray()); }
public async Task <ActionResult <ImageDto[]> > SetDefault([FromBody] ImageEditDto value) { var res = await _service.SetDefault(value); return(res); }
public async Task <ActionResult <ImageDto> > Post([FromBody] ImageEditDto value) { var res = await _service.Save(value); return(res); }