Example #1
0
        public Guid AddUser(UserModelCreateDto newUser)
        {
            if (newUser == null)
            {
                throw new Exception("Usuario invalido");
            }

            var validate = new UserModelCreateDtoValidator().Validate(newUser);

            if (!validate.IsValid)
            {
                throw new Exception("Usuario invalido");
            }

            User model = new User
            {
                Id           = Guid.NewGuid(),
                Name         = newUser.Name,
                Email        = newUser.Email,
                Password     = EncryptHelper.EncryptMD5(newUser.Password),
                Gender       = newUser.Gender,
                UpdateDate   = DateTimeOffset.Now,
                CreationDate = DateTimeOffset.Now,
                Active       = true,
            };

            _unitOfWork.Users.Add(model);
            _unitOfWork.Commit();

            return(model.Id);
        }
Example #2
0
        public string AtivarVeiculoService(Guid id)
        {
            var retorno = GetVeiculoById(id);

            if (retorno.Active != true)
            {
                retorno.Active = true;

                _unitOfWork.Veiculos.Update(retorno);
                _unitOfWork.Commit();
                return(Mensagem.MSG_D001);
            }
            return(Mensagem.MSG_D003);
        }
Example #3
0
        public Guid AddAddress(AddressModelCreateDto newAddress)
        {
            if (newAddress == null)
            {
                throw new Exception("Endereço invalido");
            }

            var validate = new AddressModelCreateDtoValidator().Validate(newAddress);

            if (!validate.IsValid)
            {
                throw new Exception("Endereço invalido");
            }

            var userExists = _unitOfWork.Users.Query(x => x.Id == newAddress.UserId);

            if (userExists == null)
            {
                throw new Exception("Usuario invalido");
            }

            var addressExistsForUser = _unitOfWork.Addresses.FindAddressByUserId(newAddress.UserId);

            if (addressExistsForUser != null)
            {
                throw new Exception("Usuario já contém um endereço");
            }


            Address model = new Address
            {
                Id           = Guid.NewGuid(),
                City         = newAddress.City,
                UserId       = newAddress.UserId,
                Street       = newAddress.Street,
                Number       = newAddress.Number,
                Complement   = newAddress.Complement,
                Neighborhood = newAddress.Neighborhood,

                UpdateDate   = DateTimeOffset.Now,
                CreationDate = DateTimeOffset.Now,
                Active       = true,
            };

            _unitOfWork.Addresses.Add(model);
            _unitOfWork.Commit();

            return(model.Id);
        }
Example #4
0
        public string AtivarEventoService(Guid id)
        {
            var desativarEvento = BuscarEventoPorIdService(id);

            if (desativarEvento.Active != true)
            {
                desativarEvento.Active = true;

                _unitOfWork.Evento.Update(desativarEvento);
                _unitOfWork.Commit();
                return(Message.MSG_S002);
            }

            return(Message.MSG_S003);
        }
Example #5
0
        public string AtivarCompraService(Guid id)
        {
            var desativarCompra = BuscarCompraPorIdService(id);

            if (desativarCompra.Active != true)
            {
                desativarCompra.Active = true;

                _unitOfWork.Compra.Update(desativarCompra);
                _unitOfWork.Commit();
                return(Message.MSG_S002);
            }

            return(Message.MSG_D003);
        }
Example #6
0
        public string AtivarLivroService(Guid id)
        {
            var desativarLivro = GetLivroByIdService(id);

            if (desativarLivro.Active != true)
            {
                desativarLivro.Active = true;

                _unitOfWork.Livro.Update(desativarLivro);
                _unitOfWork.Commit();
                return(Message.MSG_S002);
            }

            return(Message.MSG_S003);
        }
Example #7
0
        public string AtivarAutorService(Guid id)
        {
            var desativarAutor = GetAutorByIdService(id);

            if (desativarAutor.Active != true)
            {
                desativarAutor.Active = true;

                _unitOfWork.Autor.Update(desativarAutor);
                _unitOfWork.Commit();
                return(Message.MSG_S002);
            }

            return(Message.MSG_D003);
        }
Example #8
0
        public void Add(LogCreateDTO log)
        {
            Domain.Model.Log model = new Domain.Model.Log()
            {
                Id              = Guid.NewGuid(),
                ClassName       = log.ClassName,
                LogDate         = DateTimeOffset.Now,
                Message         = log.Message,
                MethodName      = log.MethodName,
                UserId          = log.UserId,
                UserEmail       = log.UserEmail,
                ControllerName  = log.ControllerName,
                Exception       = log.Exception,
                FriendlyMessage = log.FriendlyMessage,
                StackTrace      = log.StackTrace
            };

            _unitOfWork.Logs.Add(model);
            _unitOfWork.Commit();
        }
Example #9
0
 public string CadastrarUsuario(Usuario user)
 {
     _unitOfWork.Users.Add(user);
     _unitOfWork.Commit();
     return(Mensagem.MSG_S001);
 }