コード例 #1
0
        internal Keep EditKeepViews(Keep editedKeep)
        {
            Keep original = _repo.GetById(editedKeep.Id);

            if (original == null)
            {
                throw new Exception("Invalid Id... from keepsService");
            }



            editedKeep.Name        = editedKeep.Name == null ? original.Name : editedKeep.Name;
            editedKeep.Description = editedKeep.Description == null ? original.Description : editedKeep.Description;
            editedKeep.Img         = editedKeep.Img == null ? original.Img : editedKeep.Img;
            editedKeep.Views       = editedKeep.Views == 0 ? original.Views : editedKeep.Views;
            editedKeep.Keeps       = editedKeep.Keeps == 0 ? original.Keeps : editedKeep.Keeps;
            editedKeep.Creator     = editedKeep.Creator == null ? original.Creator : editedKeep.Creator;

            return(_repo.EditKeepViews(editedKeep));
        }
コード例 #2
0
ファイル: KeepsService.cs プロジェクト: micahjbartron/keepr
        internal Keep Edit(Keep editKeep, string userId)
        {
            Keep foundKeep = GetById(editKeep.Id);

            if (foundKeep.Views < editKeep.Views)
            {
                if (_repo.EditKeepViews(editKeep))
                {
                    foundKeep.Views = editKeep.Views;
                    return(foundKeep);
                }
                throw new Exception("didn't increas numbers");
            }
            if (foundKeep.Shares < editKeep.Shares)
            {
                if (_repo.EditKeepShares(editKeep))
                {
                    foundKeep.Shares = editKeep.Shares;
                    return(foundKeep);
                }
                throw new Exception("didn't increas numbers");
            }
            if (foundKeep.Keeps < editKeep.Keeps)
            {
                if (_repo.EditKeepKeeps(editKeep))
                {
                    foundKeep.Keeps = editKeep.Keeps;
                    return(foundKeep);
                }
                throw new Exception("didn't increase numbers");
            }
            if (foundKeep.UserId == userId && _repo.Edit(editKeep, userId))
            {
                return(editKeep);
            }
            throw new Exception("you can't edit that, its not your keep");
        }