Esempio n. 1
0
        public bool AddContentImage(ContentImageDto contentImage)
        {
            if (contentImage.File != null && !string.IsNullOrEmpty(contentImage.Description))
            {
                string path = _imgService.CreateImage(contentImage.File);
                if (!string.IsNullOrEmpty(path))
                {
                    ContentImage content = new ContentImage
                    {
                        CarImagePath    = path,
                        Description     = contentImage.Description,
                        ExtraData       = contentImage.ExtraData,
                        ContentForTabId = contentImage.ContentForTabId
                    };

                    try
                    {
                        _ctx.ContentImages.Add(content);
                        _ctx.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException ex)
                    {
                        _logger.LogInformation($"Cannot add image {ex.Message}");
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        public string EditContentImage(ContentImageDto contentImage)
        {
            if (ContentImageExists(contentImage.ContentImageId))
            {
                string imagePath = null;
                if (contentImage.File != null)
                {
                    imagePath = _imgService.EditImage(contentImage.File, contentImage.OldImage);
                }
                ContentImage contentImageToEdit = _ctx.ContentImages.Where(cI => cI.ContentImageId == contentImage.ContentImageId)
                                                  .Select(cI => new ContentImage
                {
                    Description     = contentImage.Description ?? cI.Description,
                    ExtraData       = contentImage.ExtraData ?? cI.ExtraData,
                    CarImagePath    = imagePath ?? cI.CarImagePath,
                    ContentImageId  = cI.ContentImageId,
                    ContentForTabId = contentImage.ContentForTabId
                }).SingleOrDefault();
                try
                {
                    _ctx.ContentImages.Update(contentImageToEdit);
                    _ctx.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    _logger.LogInformation($"Could not update file because of {ex.Message}");
                }

                return(imagePath);
            }
            return(null);
        }
Esempio n. 3
0
        public IActionResult Create(ContentImageDto content)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                _con.AddContentImage(content);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Esempio n. 4
0
        public IActionResult Edit(int id, ContentImageDto content)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id }));
            }
            if (id != content.ContentImageId)
            {
                return(RedirectToAction("Edit", new { id }));
            }
            try
            {
                _con.EditContentImage(content);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }