Esempio n. 1
0
 public ActionResult Edit(EditPlace model)
 {
     if (ModelState.IsValid)
     {
         service.UpdatePlace(model);
         return RedirectToAction("Index").AndNotice("修改成功!");
     }
     return View(model);
 }
Esempio n. 2
0
        public void UpdatePlace(EditPlace viewModel)
        {
            var place = repository.GetById(viewModel.Id);
            place.Name = viewModel.Name;
            place.Body = viewModel.Body;

            if (viewModel.VideoFile != null)
            {
                FileUploads.DeleteFile(place.VideoFile);
                place.VideoFile = FileUploads.UploadFile(viewModel.VideoFile, videoUploadDir, viewModel.UrlKey);
                place.VideoSize = viewModel.VideoFile.ContentLength;
            }

            if (viewModel.MapFile != null)
            {
                FileUploads.DeleteFile(place.MapFile);
                FileUploads.DeleteFile(place.MapThumbnailFile);
                place.MapFile = FileUploads.UploadFile(viewModel.MapFile, mapUploadDir, viewModel.UrlKey);
                place.MapSize = viewModel.MapFile.ContentLength;
                place.MapThumbnailFile = FileUploads.UploadFile(viewModel.MapFile, mapUploadDir, string.Format("{0}-Thumbnail", viewModel.UrlKey), settings.MapThumbnailWidth);
            }

            repository.Update(place);
            SavePlace();
        }