Ejemplo n.º 1
0
        public void Execute(RegisterUserDto request)
        {
            var cases = new List <int> {
                14, 19, 16
            };

            _validator.ValidateAndThrow(request);
            var user = new User
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Email     = request.Email,
                Password  = request.Password,
                Username  = request.Username
            };

            _context.Users.Add(user);
            _context.SaveChanges();
            _sender.Send(new SendEmailDto
            {
                Content = "<h1>Successfuly registration</h1>",
                SendTo  = request.Email,
                Subject = "Registration"
            });
            foreach (var i in cases)
            {
                var userUseCase = new UserUseCase
                {
                    UseCaseId = i,
                    UserId    = user.Id
                };
                _context.Add(userUseCase);
            }
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Execute(RegisterUserDto request)
        {
            _validator.ValidateAndThrow(request);

            var kor = _context.Users.Add(new Domain.User
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Password  = request.Password,
                Email     = request.Email
            });

            kor.Context.SaveChanges();

            _context.UserUserCase.Add(new Domain.UserUserCase
            {
                UserId    = kor.Entity.Id,
                UseCaseId = 4
            });
            _context.UserUserCase.Add(new Domain.UserUserCase
            {
                UserId    = kor.Entity.Id,
                UseCaseId = 5
            });

            _context.SaveChanges();


            _sender.Send(new SendEmailDto
            {
                Content = "<h1>Successfull registration!</h1>",
                SendTo  = request.Email,
                Subject = "Registration"
            });
        }
Ejemplo n.º 3
0
        public IActionResult Put(int id, [FromBody] PostDto dto, [FromServices] UpdatePostValidator validator)
        {
            dto.Id = id;

            var post = _context.Posts.Find(id);

            if (post == null)
            {
                return(NotFound());
            }

            var result = validator.Validate(dto);

            if (!result.IsValid)
            {
                return(result.AsUnprocessableEntity());
            }

            _mapper.Map(dto, post);


            try
            {
                _context.SaveChanges();
                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 4
0
        public void Execute(GroupDto request)
        {
            var group = new Group
            {
                Name = request.Name
            };

            _context.Groups.Add(group);

            _context.SaveChanges();
        }
Ejemplo n.º 5
0
        void ICommand <CategoryDto> .Execute(CategoryDto request)
        {
            _validator.ValidateAndThrow(request);
            var category = new Category
            {
                Name = request.Name
            };

            _context.Categories.Add(category);
            _context.SaveChanges();
        }
Ejemplo n.º 6
0
 public void Log(IUseCase useCase, IApplicationActor actor, object useCaseData)
 {
     _context.UseCaseLogs.Add(new Domain.UseCaseLog
     {
         Actor       = actor.Indenty,
         Data        = JsonConvert.SerializeObject(useCaseData),
         Date        = DateTime.UtcNow,
         UseCaseName = useCase.Name
     });
     _context.SaveChanges();
 }
Ejemplo n.º 7
0
        void ICommandUpdate <CategoryDto, int> .Execute(CategoryDto request, int id)
        {
            _validator.ValidateAndThrow(request);
            var category = _context.Categories.Find(id);

            if (category == null)
            {
                throw new EntityNotFoundException(id, typeof(Category));
            }
            category.Name = request.Name;
            _context.SaveChanges();
        }
Ejemplo n.º 8
0
        public void Execute(CommentDto request)
        {
            var comm = new Comment
            {
                PostId  = request.PostId,
                UserId  = _actor.Id,
                Content = request.Content
            };

            _context.Comments.Add(comm);

            _context.SaveChanges();
        }
Ejemplo n.º 9
0
        public void Execute(int request)
        {
            var group = _context.Groups.Find(request);

            if (group == null)
            {
                throw new EntityNotFoundException(request, typeof(Group));
            }

            _context.Groups.Remove(group);

            _context.SaveChanges();
        }
Ejemplo n.º 10
0
        public void Execute(CommentDto request)
        {
            _validator.ValidateAndThrow(request);
            var comment = new Comment
            {
                TextComment = request.TextComment,
                PostId      = request.PostId,
                UserId      = request.UserId
            };

            _context.Add(comment);
            _context.SaveChanges();
        }
Ejemplo n.º 11
0
        public void Execute(int request)
        {
            var category = _context.Categories.Find(request);

            if (category == null)
            {
                throw new EntityNotFoundException(request, typeof(Category));
            }
            category.DeletedAt = DateTime.Now;
            category.IsDeleted = true;
            category.IsActive  = false;
            _context.SaveChanges();
        }
Ejemplo n.º 12
0
        public void Execute(int request)
        {
            var comment = _context.Comments.Find(request);

            if (comment == null)
            {
                throw new EntityNotFoundException(request, typeof(Comment));
            }
            comment.DeletedAt = DateTime.Now;
            comment.IsDeleted = true;
            comment.IsActive  = false;
            _context.SaveChanges();
        }
Ejemplo n.º 13
0
        public void Execute(int request)
        {
            var user = _context.Users.Find(request);

            if (user == null)
            {
                throw new EntityNotFoundException(request, typeof(User));
            }

            _context.Users.Remove(user);

            _context.SaveChanges();
        }
Ejemplo n.º 14
0
        public void Execute(int request)
        {
            var post = _context.Posts.Find(request);

            if (post == null)
            {
                throw new EntityNotFoundException(request, typeof(Post));
            }
            //_context.Posts.Remove(post);
            post.DeletedAt = DateTime.Now;
            post.IsActive  = false;
            post.IsDeleted = true;
            _context.SaveChanges();
        }
Ejemplo n.º 15
0
        public void Execute(int request)
        {
            var user = _context.Users.Find(request);

            if (user == null)
            {
                throw new EntityNotFoundException(request, typeof(User));
            }
            //_context.Users.Remove(user);
            user.DeletedAt = DateTime.Now;
            user.IsActive  = false;
            user.IsDeleted = true;
            _context.SaveChanges();
        }
Ejemplo n.º 16
0
        public void Execute(PostDto request)
        {
            _validator.ValidateAndThrow(request);
            var post = new Post
            {
                Text      = request.Text,
                Title     = request.Title,
                PictureId = request.PictureId,
                UserId    = request.UserId
            };

            _context.Posts.Add(post);
            _context.SaveChanges();
            foreach (var c in request.Category)
            {
                var categories = new CategoryPost
                {
                    PostId     = post.Id,
                    CategoryId = c.Id
                };
                _context.CategoryPost.Add(categories);
                _context.SaveChanges();
            }
        }
Ejemplo n.º 17
0
        void ICommandUpdate <CommentDto, int> .Execute(CommentDto request, int id)
        {
            _validator.ValidateAndThrow(request);
            var comment = _context.Comments.Find(id);

            if (comment == null)
            {
                throw new EntityNotFoundException(id, typeof(Comment));
            }
            ;
            comment.TextComment = request.TextComment;
            comment.PostId      = request.PostId;
            comment.UserId      = request.UserId;
            _context.SaveChanges();
        }
Ejemplo n.º 18
0
        void ICommand <UserDto> .Execute(UserDto request)
        {
            _validator.ValidateAndThrow(request);
            var user = new User
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Email     = request.Email,
                Password  = request.Password,
                Username  = request.Username
            };

            _context.Users.Add(user);
            _context.SaveChanges();
        }
Ejemplo n.º 19
0
        void ICommandUpdate <PostDto, int> .Execute(PostDto request, int id)
        {
            _validator.ValidateAndThrow(request);
            var post = _context.Posts.Find(id);

            if (post == null)
            {
                throw new EntityNotFoundException(id, typeof(User));
            }
            post.Title     = request.Title;
            post.Text      = request.Text;
            post.PictureId = request.PictureId;
            post.UserId    = request.UserId;
            _context.SaveChanges();
        }
Ejemplo n.º 20
0
        public void Execute(int request)
        {
            var post = _context.Posts.Find(request);
            var pid  = _context.Photos.Where(x => x.PostId.Equals(request));
            var poto = pid.First();

            if (post == null)
            {
                throw new EntityNotFoundException(request, typeof(Post));
            }

            _context.Photos.Remove(poto);
            _context.Posts.Remove(post);

            _context.SaveChanges();
        }
Ejemplo n.º 21
0
        void ICommandUpdate <UserDto, int> .Execute(UserDto request, int id)
        {
            _validator.ValidateAndThrow(request);
            var user = _context.Users.Find(id);

            if (user == null)
            {
                throw new EntityNotFoundException(id, typeof(User));
            }

            user.FirstName = request.FirstName;
            user.LastName  = request.LastName;
            user.Email     = request.Email;
            user.Password  = request.Password;
            user.Username  = request.Username;
            _context.SaveChanges();
        }
Ejemplo n.º 22
0
        public void Execute(PictureDto request)
        {
            var guid        = Guid.NewGuid();
            var extension   = Path.GetExtension(request.Image.FileName);
            var newFileName = guid + extension;
            var path        = Path.Combine("wwwroot", "images", newFileName);
            var alt         = Path.GetFileName(request.Image.Name);

            using (var fileStrem = new FileStream(path, FileMode.Create))
            {
                request.Image.CopyTo(fileStrem);
            }
            var picture = new Picture
            {
                Src = newFileName,
                Alt = alt
            };

            _context.Pictures.Add(picture);
            _context.SaveChanges();
        }
Ejemplo n.º 23
0
        public void Execute(RateDto request, int id)
        {
            var userPost = _context.Rates.Where(x => x.IdPost == request.IdPost).Select(x => x.IdUser);

            if (request.Number > 5)
            {
                throw new ArgumentException("Number must be under 6");
            }
            if (userPost.Contains(_actor.Id))
            {
                throw new ArgumentException("Voted");
            }
            var rate = new Rate
            {
                Number = request.Number,
                IdUser = _actor.Id,
                IdPost = id
            };

            _context.Rates.Add(rate);
            _context.SaveChanges();
        }
Ejemplo n.º 24
0
        public void Execute(PostDto request)
        {
            var post = new Post
            {
                Name        = request.Name,
                UserId      = _actor.Id,
                GroupId     = request.GroupId,
                Description = request.Description
            };

            var pp = _context.Posts.Add(post);

            pp.Context.SaveChanges();

            _context.Photos.Add(new Photo
            {
                PostId = pp.Entity.Id,
                Name   = request.ImageName,
                Path   = request.Path
            });
            _context.SaveChanges();
        }
Ejemplo n.º 25
0
        public IActionResult Delete(int id)
        {
            var post = _context.Comments.Find(id);

            if (post == null)
            {
                return(NotFound());
            }

            post.IsDeleted = true;
            post.IsActive  = false;
            post.DeletedAt = DateTime.Now;

            try
            {
                _context.SaveChanges();
                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }