Ejemplo n.º 1
0
        public ActionResult CreatePost(postViewModel model)
        {
            Post newpost = new Post();

            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                if (model.Photo != null)
                {
                    string upload        = hostingEnvironment.ContentRootPath;
                    var    uploadsFolder = Path.Combine(upload, "wwwroot/images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                newpost.Headline        = model.Headline;
                newpost.Date            = model.Date;
                newpost.WhoPosted       = model.whoIsPosting;
                newpost.PosterPhotopath = model.Photopath;
                newpost.Discription     = model.Description;
                newpost.postWriteUp     = model.postWriteUp;
                newpost.Photopath       = uniqueFileName;
                var postToServe = _blogRepository.savePost(newpost);
                newpost        = postToServe;
                newpost.PostId = postToServe.PostId;

                return(RedirectToAction("Details", new { Id = "/" + (newpost.PostId) }));
            }
            return(View("~/Views/Admin/CreatePost.cshtml"));
        }
Ejemplo n.º 2
0
        public async Task <ViewResult> Create()
        {
            var all = GetAllpost();

            ViewBag.Allpost = (IEnumerable <RePost>)all;
            var typcount = _blogRepository.TypeCount();

            ViewBag.CatigoryTypeCount = (PostTypeCount)typcount;
            //var Crypto = await returnCoinToLayout();
            //ViewBag.Crypto = Crypto;
            postViewModel PostVM = new postViewModel();

            return(View("~/Views/Admin/CreatePost.cshtml", PostVM));
        }