Beispiel #1
0
        public ActionResult AddImages(NewPostImageViewModel newPostImageViewModel)
        {
            string filename = Path.GetFileNameWithoutExtension(newPostImageViewModel.Imagesz.ImageFile.FileName);
            string exention = Path.GetExtension(newPostImageViewModel.Imagesz.ImageFile.FileName);
            filename = filename + DateTime.Now.ToString("yymmddssffff") + exention;
            newPostImageViewModel.Imagesz.Url = "~/Images/" + filename;
            filename = Path.Combine(Server.MapPath("~/Images/"), filename);
            newPostImageViewModel.Imagesz.Date = DateTime.Now;
            if (_context.Images.Count().Equals(null))
            {
                newPostImageViewModel.Imagesz.Id = 1;
            }
            else
            {
                newPostImageViewModel.Imagesz.Id = _context.Images.Count() + 1;
            }
            newPostImageViewModel.Imagesz.Title = User.Identity.GetUserName().ToString() + DateTime.Now.ToString("yymmddssffff");
            newPostImageViewModel.Imagesz.ImageFile.SaveAs(filename);
            daImages = newPostImageViewModel.Imagesz;
            _context.Images.Add(newPostImageViewModel.Imagesz);
            _context.SaveChanges(); 


            

            NewPostImageViewModel cnewPostImageViewModel = new NewPostImageViewModel()
            {
                Categories = _context.Categories.ToList(),
                Imagesz = newPostImageViewModel.Imagesz


            };
            return View("ControlPost", cnewPostImageViewModel);
        }
Beispiel #2
0
        public ActionResult ControlPost()
        {
            NewPostImageViewModel newPostImageViewModel = new NewPostImageViewModel()
            {
                Categories = _context.Categories.ToList(),

                
                
               
              
            };

            try
            {
                newPostImageViewModel.Imagesz = _context.Images.OrderByDescending(m => m.Url).First();
            }
            catch (Exception)
            {

            }
            return View(newPostImageViewModel);
        }