Example #1
0
        /// <summary>
        /// Add instance to database
        /// </summary>
        /// <param name="entity">new instance</param>
        /// <returns>error message if error happaned, otherwise return instance</returns>
        public virtual async Task <(T instance, string errorMessage)> AddAsync(T entity)
        {
            try
            {
                dbContext.Set <T>().Add(entity);
                await dbContext.SaveChangesAsync();

                return(entity, string.Empty);
            }
            catch (DbUpdateException e) { return(entity, e?.InnerException?.Message ?? e.Message); }
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Url,Author")] Image images)
        {
            if (ModelState.IsValid)
            {
                images.Created = DateTime.Now;
                _context.Add(images);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(images));
        }
Example #3
0
        public async Task SetImage(string title, string tags, Uri uri)
        {
            var image = new GalleryImage
            {
                Title   = title,
                Tags    = ParseTags(tags),
                Url     = uri.AbsoluteUri,
                Created = DateTime.Now
            };

            _context.Add(image);
            await _context.SaveChangesAsync();
        }
Example #4
0
        public async Task SetImage(string title, string tags, Uri uri)
        {
            var image = new GalleryImage
            {
                Title = title,

                Tags                     = tags != null?ParseTags(tags) : new List <ImageTag>(),
                                     Url = uri.AbsoluteUri
            };

            _ctx.Add(image);
            await _ctx.SaveChangesAsync();
        }
Example #5
0
        public async Task SetImage(string title, string tags, Uri uri)
        {
            // Check tags is null or isn't
            List <ImageTag> listTags = null;

            if (tags == null)
            {
                listTags = ParseTags(tags);
            }

            var image = new GalleryImage()
            {
                Title   = title,
                Tags    = listTags,
                Url     = uri.AbsoluteUri,
                Created = DateTime.Now,
            };

            _context.Add(image);
            await _context.SaveChangesAsync();
        }