예제 #1
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,TalentImage")] KnownTalents knownTalents)
 {
     if (ModelState.IsValid)
     {
         db.Entry(knownTalents).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(knownTalents));
 }
예제 #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,TalentImage")] KnownTalents knownTalents,
                                   HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    var savePath = "~/Images/" + knownTalents.Name + "/";
                    var dir      = new DirectoryInfo(HttpContext.Server.MapPath(savePath));
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    file = Request.Files[i];
                    file.SaveAs(HttpContext.Server.MapPath(savePath)
                                + file.FileName);
                    if (knownTalents.TalentImage != null)
                    {
                        knownTalents.TalentImage.Add(
                            new Media {
                            Path = "/Images/" + knownTalents.Name + "/" + file.FileName
                        });
                    }
                    else
                    {
                        knownTalents.TalentImage =
                            new List <Media> {
                            new Media {
                                Path = "/Images/" + knownTalents.Name + "/" + file.FileName
                            }
                        }
                    };
                }

                db.KnownTalents.Add(knownTalents);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(knownTalents));
        }