Exemplo n.º 1
0
        public ActionResult Create(TopCreateViewModel model, HttpPostedFileBase file)
        {
            //Get user ID here
            model.WriterID    = topicUnitOfWork.AspNetUserRepository.Get(s => s.UserName == User.Identity.Name).FirstOrDefault().Id;
            model.CreatedDate = DateTime.Now;

            //File uploade code
            if (file != null && file.ContentLength > 0)
            {
                string path = "/Content/img/TopicImg";
                // extract only the fielname
                model.ImageUrl = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                model.ImageUrl = Path.Combine(Server.MapPath(path), model.ImageUrl);
                file.SaveAs(model.ImageUrl);
                model.ImageUrl = path + "/" + Path.GetFileName(file.FileName);
            }

            if (functionModel.CreateTopic(model))
            {
                return(RedirectToAction("OwnList"));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            TopCreateViewModel model = new TopCreateViewModel();

            return(View(model));
        }