Exemplo n.º 1
0
        public ActionResult Create(IdeaFormViewModel viewModel, HttpPostedFileBase Image)
        {
            if (!ModelState.IsValid)
            {
                return(View("IdeaForm", viewModel));
            }

            if (viewModel.Image != null)
            {
                string p    = $"{Guid.NewGuid()}{Path.GetExtension(Image.FileName)}";
                string path = Path.Combine(Server.MapPath("~/UploadedFiles"), p);
                Image.SaveAs(path);
                viewModel.Image = "/UploadedFiles/" + p;
            }
            else
            {
                return(View("IdeaForm", viewModel));
            }

            Idea idea = new Idea(viewModel, User.Identity.GetUserId());

            _ideaRepository.Add(idea);

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
 public Idea Post([FromBody] Idea idea)
 {
     idea.ProjectId = SessionUser.ActiveProject;
     return(_ideaRepository.Add(idea));
 }