public async Task <ActionResult <News> > PostNews([FromForm] NewsRequest request, IFormFile image)
        {
            var identity = User.Identity as System.Security.Claims.ClaimsIdentity;
            IEnumerable <System.Security.Claims.Claim> claims = identity.Claims;
            var national_code = claims.Where(p => p.Type == "national_code").FirstOrDefault()?.Value;

            var staff = _context.staffs.Where(q => q.national_code == national_code).FirstOrDefault();

            if (staff == null)
            {
                return(Unauthorized());
            }

            var news = new News
            {
                title    = request.title,
                content  = request.content,
                slide    = request.slide,
                staff_id = staff.id,
            };

            _context.news.Add(news);

            await _context.SaveChangesAsync();

            if (request.categories != null)
            {
                foreach (int category_id in request.categories)
                {
                    _context.category_news.Add(new CategoryNews
                    {
                        news_id     = news.id,
                        category_id = category_id
                    });
                }
                await _context.SaveChangesAsync();
            }

            var image_name = ImagesHelper.save(image);

            var news_id = _context.news.Find(news.id).id;

            _context.images.Add(new Image
            {
                name           = image_name,
                imageable_id   = news_id,
                imageable_type = "News"
            });

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNews", new { id = news.id }, news));
        }
        public async Task <IActionResult> PutNews(int id, [FromForm] NewsRequest request, IFormFile image)
        {
            var identity = User.Identity as System.Security.Claims.ClaimsIdentity;
            IEnumerable <System.Security.Claims.Claim> claims = identity.Claims;
            var national_code = claims.Where(p => p.Type == "national_code").FirstOrDefault()?.Value;

            var staff = _context.staffs.Where(q => q.national_code == national_code).FirstOrDefault();

            if (staff == null)
            {
                return(Unauthorized());
            }


            if (id != request.id)
            {
                return(BadRequest());
            }

            var news = new News
            {
                title      = request.title,
                content    = request.content,
                slide      = request.slide,
                updated_at = DateTime.Now,
                staff_id   = staff.id,
            };

            _context.Entry(news).State = EntityState.Modified;

            if (request.categories != null)
            {
                _context.Entry(_context.category_news.Where(q => q.news_id == news.id)).State = EntityState.Deleted;
                foreach (int category_id in request.categories)
                {
                    var category = _context.categories.Find(category_id);
                    _context.category_news.Add(new CategoryNews
                    {
                        news_id     = news.id,
                        category_id = category_id
                    });
                }
            }

            if (image != null)
            {
                string image_name;

                var pImage = _context.images.Where(i => (i.imageable_id == request.id && i.imageable_type == "News")).FirstOrDefault();

                ImagesHelper.delete(pImage.name);

                image_name = ImagesHelper.save(image);

                var local = _context.Set <Image>().Local.FirstOrDefault(i => i.id == pImage.id);

                if (local != null)
                {
                    _context.Entry(local).State = EntityState.Detached;
                }

                _context.Entry(new Image
                {
                    id             = pImage.id,
                    name           = image_name,
                    imageable_id   = request.id,
                    imageable_type = "News"
                }).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }