예제 #1
0
        public IActionResult UploadImage(MessengerUser user, string userid)
        {
            user = _context.User.FirstOrDefault(o => o.Id == userid);
            if (user.Id != null)
            {
                foreach (var file in Request.Form.Files)
                {
                    var img = new Image {
                        UserID = user.Id, ImageTitle = file.FileName
                    };

                    using (var ms = new MemoryStream())
                    {
                        file.CopyTo(ms);
                        img.ImageData = ms.ToArray();
                        ms.Close();
                        ms.Dispose();
                    }

                    _context.SaveImage(img);
                }

                TempData["message"] = "Image(s) stored in  database!";
            }
            else
            {
                TempData["message"] = "Cannot add images to a non existent product!";
            }

            return(RedirectToAction("Index"));
        }