コード例 #1
0
        public ActionResult EditPicture(CowPictureEditVM cow)
        {
            string relativePath = "~/Content/Images/" + cow.PicturePath;
            string absolutePath = HttpContext.Server.MapPath(relativePath);

            if (System.IO.File.Exists(absolutePath))
            {
                CowDataManager.UpdateCowPicture(cow.CowID, cow.PicturePath);
                return(RedirectToAction("Cows"));
            }
            else if (cow.PicturePath == null || cow.PicturePath.Trim() == "")
            {
                CowDataManager.UpdateCowPicture(cow.CowID, null);
                return(RedirectToAction("Cows"));
            }
            else
            {
                CowVM entireCow = CowDataManager.GetCowById(cow.CowID);
                ModelState.AddModelError("CustomError", "Error: picture not found on server." +
                                         "Please enter a relative path within \"/Content/Images/\", including the file extension." +
                                         "Or leave empty to delete the picture.");
                return(View(entireCow));
            }
        }
コード例 #2
0
        public ActionResult EditPicture(int id)
        {
            CowVM cow = CowDataManager.GetCowById(id);

            return(View(cow));
        }