Ejemplo n.º 1
0
        public long AddLink(long userId, long movieId, string name, string description, string url)
        {
            if (!UserDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            if (LinkDao.ExistsForMovieAndName(movieId, name))
            {
                throw new DuplicateInstanceException <LinkDetails>("movieId", movieId, "name", name);
            }
            if (LinkDao.ExistsForMovieAndUrl(movieId, url))
            {
                throw new DuplicateInstanceException <LinkDetails>("movieId", movieId, "url", url);
            }

            Link link = Link.CreateLink(-1, movieId, userId, name, description, url, DateTime.Now);

            link.reportRead = false;

            try
            {
                LinkDao.Create(link);
            }
            catch (DuplicateInstanceException <Link> ex)
            {
                throw new DuplicateInstanceException <LinkDetails>(ex.Properties);
            }

            return(link.linkId);
        }
Ejemplo n.º 2
0
        public void UpdateLink(long userId, long linkId, string name, string description)
        {
            if (!UserDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            Link link;

            try
            {
                link = LinkDao.Find(linkId);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InstanceNotFoundException <LinkDetails>(ex.Properties);
            }

            if ((link.name != name) && (LinkDao.ExistsForMovieAndName(link.movieId, name)))
            {
                throw new DuplicateInstanceException <LinkDetails>("movieId", link.movieId, "name", name);
            }

            if (userId != link.UserProfile.userId)
            {
                throw new UserNotAuthorizedException <LinkDetails>(userId, "linkId", linkId);;
            }

            link.name        = name;
            link.description = description;

            try
            {
                LinkDao.Update(link);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InternalErrorException(ex);
            }
        }