public void Seed()
        {
            if (!dbContext.Clients.Any())
            {
                var client = new Domain.Entities.Client()
                {
                    API       = "[email protected]:zKR4gkYNHP5tvH".ToBasicAuth(),
                    Authority = new Agent()
                    {
                        Account = new Account()
                        {
                            Name     = "Sample Client",
                            HomePage = new Uri("https://bitflipping.net")
                        }
                    }.ToJson(),
                    Name   = "Sample Client",
                    Scopes = new List <string> {
                        "all"
                    },
                    Enabled   = true,
                    CreatedAt = DateTimeOffset.UtcNow,
                    UpdatedAt = DateTimeOffset.UtcNow
                };
                dbContext.Clients.Add(client);

                dbContext.SaveChanges();
            }
        }
        public void Post([FromBody] DTO.Client client)
        {
            Console.WriteLine($"DEBUG: Entering {nameof(Post)}");
            Console.WriteLine($"DEBUG: Request body contained: {client}");
            // TODO: updatedBy
            var updatedBy = "SYSTEM";

            using (var db = new TransactionServiceDbContext())
            {
                var dbClient = db.Clients.FindAsync(client.ClientId).Result;
                if (dbClient == null)
                {
                    // PK is serial, so should be automatically generated
                    dbClient = new Domain.Entities.Client
                    {
                        CreatedBy = updatedBy,
                        CreatedOn = DateTime.UtcNow
                    };
                    db.Add(dbClient);
                }
                dbClient.Name        = client.Name;
                dbClient.Description = client.Description;
                dbClient.UpdatedBy   = updatedBy;
                dbClient.UpdatedOn   = DateTime.UtcNow;
                db.SaveChangesAsync();
            }
        }
        public async Task Create(ClientDto dto)
        {
            var client = new Domain.Entities.Client
            {
                Name        = dto.Name,
                LastName    = dto.LastName,
                Dni         = dto.Dni,
                Cuil        = dto.Cuil,
                CellPhone   = dto.CellPhone,
                BirthDate   = dto.BirthDate,
                Email       = dto.Email,
                ErasedState = false
            };

            await _clientRepository.Create(client);
        }
Exemplo n.º 4
0
        public async Task <BaseResponse> Handle(UpdateClientCommandRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"[Begin] - Updating client : { JsonSerializer.Serialize(request) }");

            try
            {
                var validationResult = request.Validate();

                if (!validationResult.IsValid)
                {
                    var validationResultErrors = ValidationResultHelper.GetValidationResultErrors(validationResult);

                    _logger.LogInformation($"[Error] - Request not valid: { validationResultErrors }");

                    return(new BaseResponse(false, "Ocorreu um problema ao atualizar o cliente!", HttpStatusCode.BadRequest, validationResultErrors));
                }

                if (await _clientService.CheckIfClientExists(request.Id))
                {
                    _logger.LogInformation($"[Error] - Request not valid: { request }");

                    return(new BaseResponse(false, "Cliente não existe na base de dados!", HttpStatusCode.NotFound, request));
                }

                if (!await _clientService.CheckIfClientCpfIsUnique(request.Cpf, request.Id))
                {
                    _logger.LogInformation($"[Error] - Request not valid: { request }");

                    return(new BaseResponse(false, "Já existe um cliente cadastrado com o mesmo cpf!", HttpStatusCode.BadRequest, request));
                }

                var client = new Domain.Entities.Client(request.Id, request.FirstName, request.LastName, request.Cpf, request.Email, request.Username, request.Password, request.Role, request.IsActive);

                await _repository.Update(client);

                _logger.LogInformation($"[End] - Client successfully updated: { JsonSerializer.Serialize(client) }");

                return(new BaseResponse(true, "Cliente atualizado com sucesso!", HttpStatusCode.OK, client));
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"[Error] - An error occurred while updating the client: { JsonSerializer.Serialize(ex) }");

                return(new BaseResponse(false, "Ocorreu um problema ao atualizar o cliente!", HttpStatusCode.InternalServerError, ex.InnerException.ToString()));
            }
        }
Exemplo n.º 5
0
        private void DetalheAluguel_Load(object sender, EventArgs e)
        {
            Images = Load_Image();
            Domain.Entities.Car    car    = Load_Car();
            Domain.Entities.Client client = Load_Client();
            if (Rent.idEmployee != 0)
            {
                Domain.Entities.Employee employee = Load_Employee();
                this.employee.Text    = employee.Name;
                this.employee.Visible = true;
                employeeTitle.Visible = true;
            }
            this.client.Text = client.Name;
            email.Text       = client.Email;
            pickUp.Text      = Rent.PickUpDate.ToString("dd/MM/yyyy HH:mm");
            dropOff.Text     = Rent.DropOffDate.ToString("dd/MM/yyyy HH:mm");
            status.Text      = car.Status == true ? "Disponível" : "Indisponível";
            amount.Text      = Rent.Value.ToString("C2", CultureInfo.CurrentCulture);

            if (Rent.PaymentType == Domain.Entities.PaymentTypeEnum.Billet)
            {
                payment.Text = "Boleto";
            }
            else if (Rent.PaymentType == Domain.Entities.PaymentTypeEnum.Card)
            {
                payment.Text = "Cartão";
            }
            else
            {
                payment.Text = "Dinheiro";
            }

            branch.Text = car.Branch;
            model.Text  = car.Model;
            board.Text  = car.Board;
            doors.Text  = car.Doors.ToString();
            board.Text  = car.Board;
            fuel.Text   = car.Fuel;
            color.Text  = car.Color;
            year.Text   = car.Year.ToString();
            if (Images.Any())
            {
                image.Image = Image.FromFile(Servers.path + Images.Select(x => x.Path).FirstOrDefault() + Images.Select(x => x.Name).FirstOrDefault());
            }
        }
Exemplo n.º 6
0
        public void Execute(ChangeClientNameCommandContext commandContext)
        {
            Domain.Entities.Client client = _clientService.GetClientById(commandContext.Id);
            _clientService.ChangeClientName(client, commandContext.Name);

            string databaseName = commandContext.DatabasePath;

            using (SQLiteConnection conn = new SQLiteConnection(string.Format(@"Data Source={0};", databaseName)))
            {
                conn.Open();
                SQLiteCommand command =
                    new SQLiteCommand(
                        string.Format(
                            @"UPDATE Clients SET Name=@newname where Id=@id"), conn);
                command.Parameters.AddWithValue("@id", commandContext.Id);
                command.Parameters.AddWithValue("@newname", commandContext.Name);
                command.ExecuteNonQuery();
            }
        }
Exemplo n.º 7
0
        public Rent(Domain.Entities.Car car, AmountCar amount, User user, MetroStyleManager manager, Domain.Entities.Client client = null)
        {
            InitializeComponent();
            this.StyleManager = manager;
            Load_Page();
            Images     = new List <Image>();
            User       = new User();
            FullClient = new Domain.Entities.ClientCardCNH();
            Car        = new Domain.Entities.Car();

            Car  = car;
            User = user;

            Images = _appImage.GetImages(car.Id);
            if (User.isAdmin)
            {
                FullClient = _appClient.GetClientCNHByUser(client.User_Id);
            }
            else
            {
                FullClient = _appClient.GetClientCNHByUser(User.Id);
            }

            imageCount = Images.Count;

            List <Card> cards = new List <Card>();

            cards = _appCard.GetCard(FullClient.Client.Id);

            FullClient.Card.AddRange(cards);

            drop_offDate.MinDate = DateTime.Today.AddDays(1).AddSeconds(-10);
            drop_offDate.Value   = DateTime.Now.AddDays(1);

            pick_upDate.MinDate = DateTime.Today.AddSeconds(-10);
            pick_upDate.Value   = DateTime.Now;

            DateTime time = DateTime.Today;

            for (DateTime _time = time.AddHours(00); _time < time.AddHours(24); _time = _time.AddMinutes(30)) //from 16h to 18h hours
            {
                metroComboBox1.Items.Add(_time.ToShortTimeString());
                metroComboBox2.Items.Add(_time.ToShortTimeString());
            }

            AmountPerDay.Text = amount.Amount.ToString("C2", CultureInfo.CurrentCulture);

            fillFieldsCar();
            Load_Images();
            Load_Cards();
            Set_date(this, new EventArgs());

            Money  = money;
            Billet = billet;
            if (panelMoney.Controls.OfType <RadioButton>().Any())
            {
                Card = panelCard.Controls.OfType <RadioButton>();
                foreach (var item in Card)
                {
                    item.Checked = false;
                }
            }

            Money.Checked  = true;
            Billet.Checked = false;
        }
Exemplo n.º 8
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            error.Tag = 0;
            error.Clear();
            if (nomeTXT.Text.Length < 3)
            {
                error.SetError(this.nomeTXT, "O nome tem que ter de 3 a 50 caracteres");
                error.Tag = 1;
            }
            if (!email.Text.Contains("@") && !email.Text.Contains(".com"))
            {
                error.SetError(this.email, "Insira um endereço de email válido");
                error.Tag = 1;
            }
            if (email.Text.Length < 5)
            {
                error.SetError(this.email, "Insira um endereço de email válido");
                error.Tag = 1;
            }
            if (cpf.Text.Length < 11)
            {
                error.SetError(this.cpf, "Insira um CPF válido");
                error.Tag = 1;
            }
            else
            {
                if (!Check_CPF(cpf.Text))
                {
                    error.SetError(this.cpf, "Insira um CPF válido");
                    error.Tag = 1;
                }
            }
            if (telefone.Text.Length < 11)
            {
                error.SetError(this.telefone, "Insira um número de telefone válido");
                error.Tag = 1;
            }
            if (cnh.Text.Length < 11)
            {
                error.SetError(this.cnh, "Insira um número de CNH válido");
                error.Tag = 1;
            }
            if (dateValidateCNH.Value < dateOfBirth.Value)
            {
                error.SetError(this.dateValidateCNH, "Insira uma data válida");
                error.Tag = 1;
            }
            DateTime dateExpected = DateTime.Now.AddYears(-18);

            if (dateOfBirth.Value > dateExpected)
            {
                error.SetError(this.dateOfBirth, "Você deve ter no mínimo 18 anos para realizar o cadastro");
                error.Tag = 1;
            }
            if ((int)error.Tag == 0)
            {
                Client = new Domain.Entities.Client()
                {
                    Name        = nomeTXT.Text,
                    Email       = email.Text,
                    CPF         = long.Parse(cpf.Text),
                    DateOfBirth = DateTime.Parse(dateOfBirth.Text),
                    Genero      = genero.Text,
                    Phone       = long.Parse(telefone.Text),
                };

                CNH = new CNH()
                {
                    Name         = nomeTXT.Text,
                    Number       = long.Parse(cnh.Text),
                    ValidateDate = DateTime.Parse(dateValidateCNH.Text)
                };

                try
                {
                    User.Id        = _appUser.Insert(User);
                    Client.CNH_Id  = _appCNH.Insert(CNH);
                    Client.User_Id = User.Id;
                    _appClient.Insert(Client);
                    MetroMessageBox.Show(this, "Cliente Cadastrado com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Question, 100);
                    Login form = new Login();
                    this.Hide();
                    form.ShowDialog();
                    this.Close();
                }
                catch
                {
                    MetroMessageBox.Show(this, "Erro Inesperado. Por favor entre em contato com seu administrador", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error, 100);
                }
            }
        }
Exemplo n.º 9
0
        private void metroLinkSalvar_Click(object sender, EventArgs e)
        {
            error.Tag = 0;
            error.Clear();
            if (name.Text.Length < 3)
            {
                error.SetError(this.name, "O nome tem que ter de 3 a 50 caracteres");
                error.Tag = 1;
            }
            if (!email.Text.Contains("@") && !email.Text.Contains(".com"))
            {
                error.SetError(this.email, "Insira um endereço de email válido");
                error.Tag = 1;
            }
            if (email.Text.Length < 5)
            {
                error.SetError(this.email, "Insira um endereço de email válido");
                error.Tag = 1;
            }
            if (cpf.Text.Length < 11)
            {
                error.SetError(this.cpf, "Insira um CPF válido");
                error.Tag = 1;
            }
            else
            {
                if (!Check_CPF(cpf.Text))
                {
                    error.SetError(this.cpf, "Insira um CPF válido");
                    error.Tag = 1;
                }
            }
            if (phone.Text.Length < 11)
            {
                error.SetError(this.phone, "Insira um número de phone válido");
                error.Tag = 1;
            }
            if (cnh.Text.Length < 11)
            {
                error.SetError(this.cnh, "Insira um número de CNH válido");
                error.Tag = 1;
            }
            if (validateCNHdate.Value < dateofBirth.Value)
            {
                error.SetError(this.validateCNHdate, "Insira uma data válida");
                error.Tag = 1;
            }
            DateTime dateExpected = DateTime.Now.AddYears(-18);

            if (dateofBirth.Value > dateExpected)
            {
                error.SetError(this.dateofBirth, "Você deve ter no mínimo 18 anos para realizar o cadastro");
                error.Tag = 1;
            }
            if ((int)error.Tag == 0)
            {
                Domain.Entities.Client Client = new Domain.Entities.Client()
                {
                    Name        = name.Text,
                    Email       = email.Text,
                    Phone       = long.Parse(phone.Text),
                    Genero      = gener.Text,
                    CPF         = long.Parse(cpf.Text),
                    DateOfBirth = DateTime.Parse(dateofBirth.Text),
                };
                Domain.Entities.CNH CNH = new CNH()
                {
                    Name         = name.Text,
                    Number       = long.Parse(cnh.Text),
                    ValidateDate = DateTime.Parse(validateCNHdate.Text),
                };
                Domain.Entities.User User = new User()
                {
                    Name     = user.Text,
                    Password = password.Text,
                    isAdmin  = false
                };
                try
                {
                    var idCNH  = _appCNH.Insert(CNH);
                    var idUser = _appUser.Insert(User);
                    Client.CNH_Id  = idCNH;
                    Client.User_Id = idUser;
                    _appClient.Insert(Client);
                    MetroFramework.MetroMessageBox.Show(this, "Cliente Cadastrado com sucesso", "Sucesso", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question, 100);
                    this.Close();
                }
                catch
                {
                    MetroFramework.MetroMessageBox.Show(this, "Erro inesperado. Por favor entre em contato com seu administrador", "Erro", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question, 100);
                }
            }
        }