internal Keep Edit(Keep keepToUpdate, string userId)
        {
            Keep foundKeep = Get(keepToUpdate.Id);

            if (foundKeep.UserId != userId && foundKeep.Keeps < keepToUpdate.Keeps)
            {
                if (_repo.IncreaseKeeps(keepToUpdate))
                {
                    foundKeep.Keeps = keepToUpdate.Keeps;
                    return(foundKeep);
                }
                throw new Exception("Could not increase keeps for given keep");
            }

            if (foundKeep.UserId != userId && foundKeep.Shares < keepToUpdate.Shares)
            {
                if (_repo.IncreaseShares(keepToUpdate))
                {
                    foundKeep.Shares = keepToUpdate.Shares;
                    return(foundKeep);
                }
                throw new Exception("Could not increase shares for given keep");
            }

            if (foundKeep.UserId != userId && foundKeep.Views < keepToUpdate.Views)
            {
                if (_repo.IncreaseViews(keepToUpdate))
                {
                    foundKeep.Views = keepToUpdate.Views;
                    return(foundKeep);
                }
                throw new Exception("Could not increase views for given keep");
            }

            if (foundKeep.UserId == userId)
            {
                keepToUpdate.UserId = userId;
                if (_repo.Edit(keepToUpdate))
                {
                    return(keepToUpdate);
                }
                // return _repo.Edit(keepToUpdate, userId);
            }
            throw new Exception("You can not edit the given keep");
        }
Beispiel #2
0
        internal Keep Edit(Keep editKeep, string userId)
        {
            Keep found = Get(editKeep.Id, userId);

            if (found.Views < editKeep.Views)
            {
                if (_repo.IncreaseViews(editKeep))
                {
                    found.Views = editKeep.Views;
                    return(found);
                }
                throw new Exception("You cant do that edit.");
            }
            if (found.Shares < editKeep.Shares)
            {
                if (_repo.IncreaseShares(editKeep))
                {
                    found.Shares = editKeep.Shares;
                    return(found);
                }
                throw new Exception("You cant do that edit.");
            }
            if (found.Keeps < editKeep.Keeps)
            {
                if (_repo.IncreaseKeeps(editKeep))
                {
                    found.Keeps = editKeep.Keeps;
                    return(found);
                }
                throw new Exception("You cant do that edit.");
            }
            if (found.UserId == userId && _repo.Edit(editKeep, userId))
            {
                return(editKeep);
            }
            throw new Exception("You cant do that edit.");
        }