示例#1
0
        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());
        }
示例#2
0
        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);
        }
示例#3
0
文件: emImage.cs 项目: db-jt/JesTpro
        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);
        }
示例#4
0
        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());
        }
示例#5
0
        public async Task <ActionResult <ImageDto[]> > SetDefault([FromBody] ImageEditDto value)
        {
            var res = await _service.SetDefault(value);

            return(res);
        }
示例#6
0
        public async Task <ActionResult <ImageDto> > Post([FromBody] ImageEditDto value)
        {
            var res = await _service.Save(value);

            return(res);
        }