コード例 #1
0
 public ActionResult NewSave(HttpPostedFileBase postedFile, Munkaim munkaim)
 {
     if (postedFile.ContentLength > 0)
     {
         string _FileName = Path.GetFileName(postedFile.FileName);
         string _path     = Path.Combine(Server.MapPath("~/Content/Works"), _FileName);
         postedFile.SaveAs(_path);
         munkaim.eleresiUt = _FileName;
         if (!ModelState.IsValid)
         {
             var vm = new WorkViewModel
             {
                 Munkaim = munkaim
             };
             return(View("New", vm));
         }
         if (munkaim.HozzaadasDatuma == null)
         {
             munkaim.HozzaadasDatuma = DateTime.Now;
         }
         _context.Munkaim.Add(munkaim);
         _context.SaveChanges();
         TempData["success"] = "You successfully uploaded a new project!";
         return(RedirectToAction("Index", "MyWork"));
     }
     return(View("Index"));
 }
コード例 #2
0
        public ActionResult Save(Munkaim munkaim)
        {
            if (!ModelState.IsValid)
            {
                var vm = new WorkViewModel
                {
                    Munkaim = munkaim
                };
                TempData["error"] = "Something went wrong! Please try again later!";
                return(View("Edit", vm));
            }

            if (munkaim.Id == null || munkaim.Id == 0)
            {
                _context.Munkaim.Add(munkaim);
            }
            else
            {
                var letezoMunka = _context.Munkaim.Single(u => u.Id == munkaim.Id);
                letezoMunka.Cim             = munkaim.Cim;
                letezoMunka.Csillagozott    = munkaim.Csillagozott;
                letezoMunka.HozzaadasDatuma = munkaim.HozzaadasDatuma;
                letezoMunka.SlideShow       = munkaim.SlideShow;
                letezoMunka.Leiras          = munkaim.Leiras;
            }
            TempData["success"] = "You successfully uploaded a new project!";
            _context.SaveChanges();
            return(RedirectToAction("Index", "MyWork"));
        }