コード例 #1
0
ファイル: KeepService.cs プロジェクト: cunningdan/Keepr
 public void Edit(Keep keepData, string userId)
 {
     if (userId != keepData.CreatorId)
     {
         throw new System.Exception("Access Denied");
     }
     _repo.Edit(keepData);
 }
コード例 #2
0
        public Keep Edit(Keep editData, string userId)
        {
            Keep original = _kr.GetById(editData.Id);

            if (editData.Name == null)
            {
                editData.Name = original.Name;
            }
            if (editData.Description == null)
            {
                editData.Description = original.Description;
            }
            if (editData.Img == null)
            {
                editData.Img = original.Img;
            }
            if (editData.CreatorId == null)
            {
                editData.CreatorId = original.CreatorId;
            }
            if (editData.Views == 0)
            {
                editData.Views = original.Views;
            }
            if (editData.Shares == 0)
            {
                editData.Shares = original.Shares;
            }
            if (editData.Keeps == 0)
            {
                editData.Keeps = original.Keeps;
            }
            if (editData.CreatorId == original.CreatorId)
            {
                if (original == null)
                {
                    throw new Exception("Bad Id");
                }
            }
            else if (editData.Img != original.Img || editData.Name != original.Name || editData.Description != original.Description)
            {
                if (original == null)
                {
                    throw new Exception("Bad Id");
                }
                throw new Exception("Bad Id");
            }
            else
            {
                throw new Exception("Not the Creator");
            }
            _kr.Edit(editData);

            return(_kr.GetById(editData.Id));
        }
コード例 #3
0
ファイル: VaultKeepService.cs プロジェクト: cunningdan/Keepr
        public VaultKeep Create(VaultKeep newVaultKeep)
        {
            Vault foundVault = _vrepo.GetOne(newVaultKeep.VaultId);

            if (foundVault.CreatorId != newVaultKeep.CreatorId)
            {
                throw new System.Exception("There is no vault by that Id : Access Denied");
            }
            Keep foundKeep = _ks.GetOne(newVaultKeep.KeepId);

            foundKeep.Keeps++;
            _krepo.Edit(foundKeep);
            newVaultKeep.Id = _repo.Create(newVaultKeep);
            return(newVaultKeep);
        }
コード例 #4
0
        internal Keep Edit(Keep updated)
        {
            Keep original = GetById(updated.Id);

            if (updated.CreatorId != original.CreatorId && updated.Name != null)
            {
                updated.Views  = updated.Views != null ? updated.Views : original.Views;
                updated.Shares = updated.Shares != null ? updated.Shares : original.Shares;
                throw new Exception("You can only edit your own data");
            }
            updated.Name        = updated.Name != null ? updated.Name : original.Name;
            updated.Description = updated.Description != null ? updated.Description : original.Description;
            updated.Keeps       = updated.Keeps != null ? updated.Keeps : original.Keeps;
            updated.Shares      = updated.Shares != null ? updated.Shares : original.Shares;
            updated.Views       = updated.Views != null ? updated.Views : original.Views;

            return(_repo.Edit(updated));
        }