예제 #1
0
        public async Task <IActionResult> EditPostAsset(PostAssetViewModel assetvm)
        {
            string returnurl = assetvm.ReturnUrl;
            var    postAsset = new PostAsset
            {
                Id      = assetvm.Id,
                Caption = assetvm.Caption,
            };

            if (assetvm.Asset == null)
            {
                postAsset.Asset = assetvm.CurrentAsset;
            }
            else
            {
                if (!string.IsNullOrEmpty(assetvm.CurrentAsset))
                {
                    _fileManager.RemovePostAsset(assetvm.CurrentAsset);
                }
                postAsset.Asset = _fileManager.SavePostAsset(assetvm.Asset);
            }
            if (postAsset.Id > 0)
            {
                _repo.UpdatePostAsset(postAsset);
            }
            else
            {
                var post = _repo.GetPostForAssets(assetvm.PostId);
                postAsset.Post = post;
                _repo.AddPostAsset(postAsset);
            }
            if (await _repo.SaveChangesAsync())
            {
                return(LocalRedirect(returnurl));
            }
            else
            {
                return(View(postAsset));
            }
        }
예제 #2
0
 public IActionResult EditPostAsset(int?id, int postid, string returnurl)
 {
     if (id == null)
     {
         var vm = new PostAssetViewModel()
         {
             PostId    = postid,
             ReturnUrl = returnurl
         };
         return(View(vm));
     }
     else
     {
         var postAsset = _repo.GetPostAsset((int)id);
         return(View(new PostAssetViewModel
         {
             Id = postAsset.Id,
             PostId = postid,
             CurrentAsset = postAsset.Asset,
             Caption = postAsset.Caption,
             ReturnUrl = returnurl
         }));
     }
 }