public async Task <IActionResult> Edit(int id, [Bind("id,Metro,NameLine,CountStation,Image,ImageMimeTypeOfData")] MetroLines metroLines)
        {
            if (id != metroLines.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(metroLines);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MetroLinesExists(metroLines.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(metroLines));
        }
        public async Task <IActionResult> AddImage(int?id, IFormFile uploads)
        {
            if (id != null)
            {
                if (uploads != null)
                {
                    MetroLines metroline = await _context.MetroLines.Where(x => x.id == id).FirstOrDefaultAsync();

                    byte[] p1 = null;
                    using (var fs1 = uploads.OpenReadStream())
                        using (var ms1 = new MemoryStream())
                        {
                            fs1.CopyTo(ms1);
                            p1 = ms1.ToArray();
                        }
                    metroline.ImageMimeTypeOfData = uploads.ContentType;
                    metroline.Image = p1;
                    _context.MetroLines.Update(metroline);
                    _context.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("id,Metro,NameLine,CountStation,Image,ImageMimeTypeOfData")] MetroLines metroLines)
        {
            var   remoteIpAddres = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            Users user           = _context.User.Where(x => x.IpAddress.Contains(remoteIpAddres)).FirstOrDefault();

            if (user != null && user.Status == "true")
            {
                ViewBag.user = user;
            }
            if (ModelState.IsValid)
            {
                _context.Add(metroLines);
                Trace.WriteLine(metroLines);
                await _context.SaveChangesAsync();

                MetroLines metroLinesSelect = _context.MetroLines.Where(x => x.NameLine == metroLines.NameLine).FirstOrDefault();
                TempData["LineID"] = metroLinesSelect.id;
                Trace.WriteLine(metroLinesSelect.id);
                return(RedirectToAction(nameof(AddImageForm)));
            }
            return(View(metroLines));
        }
        public FileContentResult GetImage(int id)
        {
            MetroLines lines = _context.MetroLines
                               .FirstOrDefault(g => g.id == id);

            if (lines != null)
            {
                try
                {
                    Trace.WriteLine(lines.NameLine);
                    Trace.WriteLine(lines.ImageMimeTypeOfData);
                    var file = File(lines.Image, lines.ImageMimeTypeOfData);
                    return(file);
                }catch (Exception exp)
                {
                    Trace.WriteLine(exp.ToString());
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }