示例#1
0
        public async Task <IServiceResult> RemoveAsync(string id)
        {
            try
            {
                var imageId = id.ToGuid();

                var image = await _repository.GetSingleAsync(imageId, true);

                if (image == null)
                {
                    throw new NotFoundException(nameof(image), imageId);
                }

                _repository.Remove(image);
                if (!await _unitOfWork.CompleteAsync())
                {
                    throw new SaveFailedException(nameof(image));
                }
                ;
                _logger.LogInformation($"Deleted {nameof(image)} with id: {image.Id}.");

                return(new ServiceResult());
            }
            catch (Exception e)
            {
                _logger.LogError($"Deleting image with id: {id} failed. {e.Message}");

                return(new ServiceResult(false, e.Message));
            }
        }
示例#2
0
        public object Delete(Img deleted)
        {
            string msgError = "";
            bool   result   = repository.Remove(deleted, ref msgError);

            object json = new
            {
                success = result,
                message = msgError
            };

            return(json);
        }
        public ActionResult Edit(ExampleParentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var parent = _exampleParentsRepository.Get(model.Id);
                parent.Text     = model.Text;
                parent.LongText = model.LongText;

                if (model.RemovePhoto)
                {
                    _imagesRepository.Remove(parent.PhotoId.Value);

                    parent.PhotoId = null;
                    _exampleParentsRepository.Update(parent);
                    _exampleParentsRepository.SaveChanges();

                    _imagesRepository.SaveChanges();
                }
                else if (model.Upload != null)
                {
                    try
                    {
                        var image = new Photo()
                        {
                            ObjectId       = parent.Id,
                            ObjectTypeName = nameof(ExampleParent),
                            FileName       = $"Image{parent.Id}",
                            DirectoryPath  = "ExampleParents",
                            Title          = "NoTitle"
                        };

                        _imagesRepository.Upload(image, model.Upload);
                        _imagesRepository.SaveChanges();

                        parent.PhotoId = image.Id;
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }

                _exampleParentsRepository.Update(parent);
                _exampleParentsRepository.SaveChanges();

                return(RedirectToAction(JMap.Example.ExampleParents.List()));
            }

            return(View(model));
        }
示例#4
0
 public void DeleteImage(int id)
 {
     repository.Remove(id);
 }