Exemplo n.º 1
0
        public ApiPattern CreateOrUpdate(ApiPattern apiPattern, Guid authorId, int scale, String filterName)
        {
            var patternImage = imagesLogic.CanvasesToPatternImage(apiPattern, scale, filterName);

            imagesLogic.SaveImage(patternImage);
            var jsonRawData     = JsonConvert.SerializeObject(apiPattern.Canvases);
            var originalRawData = Encoding.UTF8.GetBytes(jsonRawData);
            var originalImage   = new PatternImage()
            {
                RawData = originalRawData
            };

            patternImagesRepository.Save(originalImage);
            var user    = usersRepository.GetById(authorId);
            var pattern = patternsRepository.GetById(apiPattern.Id);

            if (pattern != null && pattern.Author != null && pattern.Author.Id == authorId)
            {
                ApplyChanges(apiPattern, pattern, patternImage, originalImage, user);
                patternsRepository.SaveChanges();
            }
            if (pattern == null)
            {
                pattern = new Pattern();
                ApplyChanges(apiPattern, pattern, patternImage, originalImage, user);
                patternsRepository.Save(pattern);
            }
            var savedApiPattern = patternsRepository.GetApiPattern(pattern.Id, authorId);

            return(savedApiPattern);
        }
Exemplo n.º 2
0
        public ApiComment AddComment(Guid patternId, Guid authorId, string text)
        {
            ApiComment apiComment = null;
            var        user       = usersRepository.GetById(authorId);
            var        pattern    = patternsRepository.GetById(patternId);

            if (user != null && pattern != null)
            {
                var comment = new Comment()
                {
                    Author  = user,
                    Pattern = pattern,
                    Text    = text
                };
                commentsRepository.Save(comment);
                apiComment = commentsRepository.GetApiComment(comment.Id);
            }
            return(apiComment);
        }
Exemplo n.º 3
0
        public ApiLike Like(Guid userId, Guid patternId)
        {
            var apiLike = likesRepository.GetApiLike(userId, patternId);

            if (apiLike == null)
            {
                var user    = usersRepository.GetById(userId);
                var pattern = patternsRepository.GetById(patternId);
                if (user != null && pattern != null)
                {
                    var like = new Like()
                    {
                        User    = user,
                        Pattern = pattern
                    };
                    likesRepository.Save(like);
                    apiLike = likesRepository.GetApiLike(userId, patternId);
                }
            }
            return(apiLike);
        }