예제 #1
0
        public ViewResult Edit(int id)
        {
            Award award = Repository.GetAwardByID(id);

            AwardEditView view = new AwardEditView
            {
                Id           = award.AwardID,
                Title        = award.Title,
                Description  = award.Description,
                ExistingPath = award.ImagePath
            };

            return(View(view));
        }
예제 #2
0
        public ActionResult Edit(AwardEditView awardView)
        {
            Award award = null;

            try
            {
                if (ModelState.IsValid)
                {
                    award = Repository.GetAwardByID(awardView.Id);

                    award.Title       = awardView.Title;
                    award.Description = awardView.Description;

                    if (awardView.Image != null)
                    {
                        if (awardView.ExistingPath != null)
                        {
                            string oldPath = Path
                                             .Combine(@"C:\Users\Brother\Desktop\Epam\module8\SimpleApp\SimpleApp\wwwroot\img", Path.GetFileName(awardView.Image.FileName));
                            System.IO.File.Delete(oldPath);
                        }
                        string filePath = SetPhotoPath(awardView);
                        string path     = "/img/" + Path.GetFileName(awardView.Image.FileName);
                        award.ImagePath = path;
                    }

                    Repository.UpdateAward(award);
                    Repository.Save();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(award));
        }