Esempio n. 1
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTextBox())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        await carService.AddAsync(
                            new Car
                        {
                            Name            = txtName.Text,
                            ChassisNumber   = txtChassisNumber.Text,
                            EngineNumber    = txtEngineNumber.Text,
                            PlacaNumber     = txtPlacaNumber.Text,
                            CarBrandId      = (int)cbBrand.SelectedValue,
                            CarCategoryId   = (int)cbCarCategory.SelectedValue,
                            CarModelId      = (int)cbCarModel.SelectedValue,
                            FluelCategoryId = (int)cbFluelCategory.SelectedValue,
                            CreatedBy       = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await carService.GetByIdAsync(int.Parse(txtIdEmployee.Text));

                        entity.Name            = txtName.Text;
                        entity.ChassisNumber   = txtChassisNumber.Text;
                        entity.EngineNumber    = txtEngineNumber.Text;
                        entity.PlacaNumber     = txtPlacaNumber.Text;
                        entity.CarBrandId      = (int)cbBrand.SelectedValue;
                        entity.CarCategoryId   = (int)cbCarCategory.SelectedValue;
                        entity.CarModelId      = (int)cbCarModel.SelectedValue;
                        entity.FluelCategoryId = (int)cbFluelCategory.SelectedValue;
                        entity.CreatedBy       = Program.CurrentUser.UserName;
                        await carService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }

                    isNew  = false;
                    isEdit = false;

                    EnableBottons();
                    ClearTextBox();
                    LoadEmployees();
                    ClearErrorProvider();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 2
0
        public async static Task <PostResultModel> PostEmpresaBindingModel(this IEntityService <Empresa> service, PostEmpresaBindingModel model, ProfileMongoModel user)
        {
            var empresaResult = await service.GetEmpresasByDocumentoAsync(new GetEmpresasByDocumento { CNPJ = model.CNPJ });

            if (empresaResult.IsValid)
            {
                return(new PostResultModel {
                    IsValid = false, Message = string.Format("Já existe uma empresa com o CNPJ {0} informado.", model.CNPJ), StatusCode = 400
                });
            }

            var entity = model.CreateInstanceOf <Empresa>(user.UsuarioId);

            entity.Modulo = EnumUtility.GetEnumText(Modulo.Gestor);
            var entityId = await service.AddAsync(entity);

            var mongoObj = entity.CreateInstanceOf <EmpresaClienteMongoModel>();

            model.CopyProperties(mongoObj);
            mongoObj.ParentId = entityId.ToString();
            var mongoId = await service.MongoService.InsertMongoObject <EmpresaClienteMongoModel>(mongoObj);

            var result = new PostResultModel {
                Id = mongoId, IsValid = true, ParentId = mongoObj.ParentId, StatusCode = 200
            };

            return(result);
        }
        public virtual async Task <IActionResult> CreateAsync(TCreateDto item)
        {
            var mapping = _mapper.Map <TEntity>(item);
            var result  = new Result <TEntity>();

            try
            {
                var data = await _service.AddAsync(mapping);

                result.ResultObject       = mapping;
                result.ResultCode         = data.ResultCode;
                result.ResultStatus       = data.ResultStatus;
                result.ResultMessage      = data.ResultMessage;
                result.ResultInnerMessage = data.ResultInnerMessage;
                if (data.ResultCode == (int)ResultStatusCode.Created)
                {
                    return(Ok(result));
                }
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                result.ResultObject       = mapping;
                result.ResultCode         = (int)ResultStatusCode.BadRequest;
                result.ResultStatus       = false;
                result.ResultMessage      = e.Message;
                result.ResultInnerMessage = e.InnerException?.ToString();
                return(BadRequest(result));
            }
        }
Esempio n. 4
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.IsNotNullOrEmpty())
                {
                    MessageBoxUtil.MessageError(this, AlertMessages.MISSING_DATA);
                    errorIcon.SetError(txtName, AlertMessages.ENTER_A_NAME);
                }
                else
                {
                    if (isNew)
                    {
                        await carModelService.AddAsync(
                            new CarModel
                        {
                            Name        = txtName.Text,
                            Description = txtDescription.Text,
                            CreatedDate = DateTime.Now,
                            CarBrandId  = (int)cbCarBrand.SelectedValue,
                            CreatedBy   = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await carModelService.GetByIdAsync(int.Parse(txtIdCarModel.Text));

                        var Model = new CarModelViewModel
                        {
                            Id           = int.Parse(txtIdCarModel.Text),
                            Name         = txtName.Text,
                            Description  = txtDescription.Text,
                            CarBrandId   = entity.CarBrandId,
                            CreatedDate  = entity.CreatedDate,
                            ModifiedDate = DateTime.Now,
                            CreatedBy    = Program.CurrentUser.UserName
                        };
                        entity = mapper.Map(Model, entity);


                        await carModelService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }
                    this.isNew  = false;
                    this.isEdit = false;

                    this.EnableBottons();
                    this.ClearTextBox();
                    this.LoadCarModels();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 5
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (FormControlsHasError())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        var user = new User
                        {
                            EmployeeId   = selectedEmployee.Id,
                            UserName     = txtName.Text,
                            UserPassword = ComputeSha256Hash(txtPassword.Text),
                            CreatedDate  = DateTime.Now,
                            UserRoles    = new HashSet <UserRole>(),
                            CreatedBy    = Program.CurrentUser.UserName
                        };

                        foreach (var item in userRoles)
                        {
                            user.UserRoles.Add(item);
                        }

                        await userService.AddAsync(user);

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await userService.GetByIdAsync(int.Parse(txtId.Text));

                        entity.Id           = int.Parse(txtId.Text);
                        entity.EmployeeId   = selectedEmployee.Id;
                        entity.UserPassword = ComputeSha256Hash(txtPassword.Text);
                        entity.UserName     = txtName.Text;
                        entity.CreatedDate  = entity.CreatedDate;
                        entity.CreatedBy    = Program.CurrentUser.UserName;

                        await userService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }
                    isNew  = false;
                    isEdit = false;

                    EnableBottons();
                    ClearTextBox();
                    LoadRoles();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.IsNotNullOrEmpty())
                {
                    MessageBoxUtil.MessageError(this, "Falta ingresar algunos datos, serán remarcados");
                    errorIcon.SetError(txtName, "Ingrese un Nombre");
                }
                else
                {
                    if (isNew)
                    {
                        await carCategoryService.AddAsync(
                            new CarCategory
                        {
                            Name        = txtName.Text,
                            Description = txtDescription.Text,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, "Se Insertó de forma correcta el registro");
                    }
                    else
                    {
                        var entity = await carCategoryService.GetByIdAsync(int.Parse(txtIdCarBrand.Text));

                        var brand = new CarCategoryViewModel
                        {
                            Id           = int.Parse(txtIdCarBrand.Text),
                            Name         = txtName.Text,
                            Description  = txtDescription.Text,
                            CreatedDate  = entity.CreatedDate,
                            ModifiedDate = DateTime.Now,
                            CreatedBy    = Program.CurrentUser.UserName
                        };
                        entity = mapper.Map(brand, entity);


                        await carCategoryService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, "Se Actualizó de forma correcta el registro");
                    }
                    this.isNew  = false;
                    this.isEdit = false;

                    this.EnableBottons();
                    this.ClearTextBox();
                    this.LoadCarCategory();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 7
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTextBox())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        await employeeService.AddAsync(
                            new Employee
                        {
                            Name = txtName.Text,
                            IdentificationCard = txtIdentificationCard.Text,
                            CreatedDate        = DateTime.Now,
                            CreatedBy          = Program.CurrentUser.UserName,
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await employeeService.GetByIdAsync(int.Parse(txtIdEmployee.Text));

                        var employeeVm = new EmployeeViewModel
                        {
                            Id   = int.Parse(txtIdEmployee.Text),
                            Name = txtName.Text,
                            IdentificationCard = txtIdentificationCard.Text,
                            CreatedDate        = entity.CreatedDate,
                            ModifiedDate       = DateTime.Now,
                            CreatedBy          = Program.CurrentUser.UserName
                        };
                        entity = mapper.Map(employeeVm, entity);

                        await employeeService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }

                    isNew  = false;
                    isEdit = false;

                    EnableBottons();
                    ClearTextBox();
                    LoadEmployees();
                    ClearErrorProvider();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 8
0
        public static async Task AddSearchBindingModel(this IEntityService <Search> service, PostSearchBindingModel model)
        {
            var entity = model.CreateInstanceOf <Search>();
            await service.AddAsync(entity);

            var objMongo = model.CreateInstanceOf <SearchMongoModel>();

            objMongo.ParentId = entity.Id.ToString();
            var idMongo = await service.MongoService.InsertMongoObject <SearchMongoModel>(objMongo);
        }
Esempio n. 9
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.IsNotNullOrEmpty())
                {
                    MessageBoxUtil.MessageError(this, AlertMessages.MISSING_DATA);
                    errorIcon.SetError(txtName, AlertMessages.ENTER_A_NAME);
                }
                else
                {
                    if (isNew)
                    {
                        await roleService.AddAsync(
                            new Role
                        {
                            Name        = txtName.Text,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await roleService.GetByIdAsync(int.Parse(txtId.Text));

                        entity.Id          = int.Parse(txtId.Text);
                        entity.Name        = txtName.Text;
                        entity.CreatedDate = entity.CreatedDate;
                        entity.CreatedBy   = Program.CurrentUser.UserName;

                        await roleService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }
                    isNew  = false;
                    isEdit = false;

                    EnableBottons();
                    ClearTextBox();
                    LoadRoles();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 10
0
        public async static Task <PessoaAddResultModel> Register(this IEntityService <Pessoa> service, IComponentContext container, IEntityService <Estado> estadoService, IEntityService <Configuracao> configuracaoService, ApplicationUserManager userManager, PessoaRegisterBindingModel model, ApplicationUser usuario)
        {
            try
            {
                int pessoaId = 0;
                var pessoa   = await service.GetByEmailAsync(model.Email);

                if (pessoa != null)
                {
                    throw new Exception("E-mail já registrado");
                }

                pessoa = await service.GetByDocumentAsync(model.CPF);

                if (pessoa != null)
                {
                    throw new Exception("CPF já registrado");
                }

                pessoa           = new Pessoa();
                pessoa.CPF       = model.CPF;
                pessoa.Email     = model.Email;
                pessoa.Nome      = model.Nome;
                pessoa.UsuarioId = usuario.Id;
                pessoa.Telefone  = model.PhoneNumber;

                pessoaId = await service.AddAsync(pessoa);

                var profile = new ProfileMongoModel();
                profile.ParentId   = pessoa.Id.ToString();
                profile.UsuarioId  = usuario.Id;
                profile.Email      = pessoa.Email;
                profile.Telefone   = usuario.PhoneNumber;
                profile.Nome       = pessoa.Nome;
                profile.CPF        = pessoa.CPF;
                profile.Cargo      = pessoa.Cargo;
                profile.Permissoes = new string[0];

                await service.MongoService.InsertMongoObject <ProfileMongoModel>(profile);

                return(new PessoaAddResultModel {
                    Id = pessoaId, IsValid = true, StatusCode = 200
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTextBox())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        await rentDevolutionService.AddAsync(
                            new RentDevolution
                        {
                            CarId        = selectedCart.Id,
                            ClientId     = selectedClient.Id,
                            EmployeeId   = 1,
                            RentDate     = dtpRentDate.Value,
                            DayQuantity  = (int)nupDayQuantiy.Value,
                            Comentary    = txtComentary.Text,
                            AmountPerDay = nudAmount.Value,
                            CreatedBy    = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        if (isEdit)
                        {
                            var rentDevolution = await rentDevolutionService.GetByIdAsync(int.Parse(txtId.Text));

                            rentDevolution.CarId        = selectedCart.Id;
                            rentDevolution.ClientId     = selectedClient.Id;
                            rentDevolution.DayQuantity  = (int)nupDayQuantiy.Value;
                            rentDevolution.EmployeeId   = 1;
                            rentDevolution.RentDate     = dtpRentDate.Value;
                            rentDevolution.Comentary    = txtComentary.Text;
                            rentDevolution.AmountPerDay = nudAmount.Value;
                            rentDevolution.CreatedBy    = Program.CurrentUser.UserName;

                            await rentDevolutionService.UpdateAsync(rentDevolution);

                            MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                        }
                        else
                        {
                            var rentDevolution = await rentDevolutionService.GetByIdAsync(int.Parse(txtId.Text));

                            rentDevolution.CarId          = selectedCart.Id;
                            rentDevolution.ClientId       = selectedClient.Id;
                            rentDevolution.EmployeeId     = 1;
                            rentDevolution.RentDate       = dtpRentDate.Value;
                            rentDevolution.DayQuantity    = (int)nupDayQuantiy.Value;
                            rentDevolution.DevolutionDate = dtpDevolutionDate.Value;
                            rentDevolution.DayQuantity    = dtpDevolutionDate.Value.Subtract(dtpRentDate.Value).Days;
                            rentDevolution.Comentary      = txtComentary.Text;
                            rentDevolution.AmountPerDay   = nudAmount.Value;
                            rentDevolution.CreatedBy      = Program.CurrentUser.UserName;

                            await rentDevolutionService.UpdateAsync(rentDevolution);

                            MessageBoxUtil.MessageOk(this, "Devolucion Exitosa");
                        }
                    }
                    this.isNew  = false;
                    this.isEdit = false;

                    EnableBottons();
                    ResetFormControls();
                    LoadRentDevolution();
                    ClearErrorProvider();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 12
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTextBox())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        await clientService.AddAsync(
                            new Client
                        {
                            Name = txtName.Text.ToString(),
                            IdentificationCard = txtIdentificationCard.Text.ToString(),
                            CreditCardNumber   = txtCreditCardNumber.Text.ToString(),
                            CreditLimit        = numericDownCreditLimit.Value,
                            CreatedDate        = DateTime.Now,
                            PersonTypeId       = (int)cbPersonType.SelectedValue,
                            CreatedBy          = Program.CurrentUser.UserName
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await clientService.GetByIdAsync(int.Parse(txtIdClient.Text));

                        var model = new ClientViewModel
                        {
                            Id                 = int.Parse(txtIdClient.Text),
                            Name               = txtName.Text.ToString(),
                            PersonTypeId       = (int)cbPersonType.SelectedValue,
                            IdentificationCard = txtIdentificationCard.Text.ToString(),
                            CreditCardNumber   = txtCreditCardNumber.Text.ToString(),
                            CreditLimit        = numericDownCreditLimit.Value,
                            CreatedDate        = entity.CreatedDate,
                            ModifiedDate       = DateTime.Now
                        };
                        entity = mapper.Map(model, entity);


                        await clientService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }
                    this.isNew  = false;
                    this.isEdit = false;

                    EnableBottons();
                    ClearTextBox();
                    LoadClients();
                    ClearErrorProvider();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 13
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateTextBox())
                {
                    return;
                }
                else
                {
                    if (isNew)
                    {
                        await carInspectionService.AddAsync(
                            new CarInspection
                        {
                            CarId               = selectedCart.Id,
                            ClientId            = selectedClient.Id,
                            EmployeeId          = 1,
                            FluelQuantity       = (float)nudFluelQuantity.Value,
                            BackLeftTireState   = chbBackLeftTireState.Checked,
                            BackRightTireState  = chbBackRightTireState.Checked,
                            FrontLeftTireState  = chbFrontLeftTireState.Checked,
                            FrontRightTireState = chbBrokenCrystal.Checked,
                            HasBrokenCrystal    = chbBrokenCrystal.Checked,
                            HasReplacementTires = chbHasReplacementTires.Checked,
                            HasTires            = chbHasTires.Checked,
                            HasHydraulicJack    = chbHasHydraulicJack.Checked,
                            InspectionsDate     = DateTime.Now
                        });

                        MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY);
                    }
                    else
                    {
                        var entity = await carInspectionService.GetByIdAsync(int.Parse(txtId.Text));

                        entity.CarId               = selectedCart.Id;
                        entity.ClientId            = selectedClient.Id;
                        entity.EmployeeId          = 1;
                        entity.FluelQuantity       = (float)nudFluelQuantity.Value;
                        entity.BackLeftTireState   = chbBackLeftTireState.Checked;
                        entity.BackRightTireState  = chbBackRightTireState.Checked;
                        entity.FrontLeftTireState  = chbFrontLeftTireState.Checked;
                        entity.FrontRightTireState = chbBrokenCrystal.Checked;
                        entity.HasBrokenCrystal    = chbBrokenCrystal.Checked;
                        entity.HasReplacementTires = chbHasReplacementTires.Checked;
                        entity.HasTires            = chbHasTires.Checked;
                        entity.HasHydraulicJack    = chbHasHydraulicJack.Checked;
                        entity.InspectionsDate     = DateTime.Now;

                        await carInspectionService.UpdateAsync(entity);

                        MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY);
                    }
                    this.isNew  = false;
                    this.isEdit = false;

                    EnableBottons();
                    ResetFormControls();
                    LoadInspections();
                    ClearErrorProvider();
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtil.MessageError(this, ex.Message);
            }
        }
Esempio n. 14
0
 public async Task <bool> AddAsync(Entity entity)
 {
     return(await _entityService.AddAsync(entity));
 }
 public async Task AddAsync(EntityDTO entityDTO)
 {
     await _entityService.AddAsync(Mapper.Map <Entity>(entityDTO));
 }
Esempio n. 16
0
        public async Task <ActionResult <T> > Post([FromBody] T command)
        {
            await _baseService.AddAsync(command);

            return(Accepted(command));
        }
Esempio n. 17
0
 public Task <bool> AddAsync(TEntity entity)
 {
     return(_Service.AddAsync(entity));
 }