Exemple #1
0
        public HorarioDeExpedienteDto Create(Guid idEmpresa, String Descricao, DbContextTransaction Transacao = null)
        {
            //var UsingTransactionLocal = false;
            //if (Transacao == null)
            //{
            //    Transacao = Contexto.Database.BeginTransaction();
            //    UsingTransactionLocal = true;
            //}

            //using (Transacao)
            try
            {
                HorarioDeExpediente newOfficeHour = new HorarioDeExpediente();

                newOfficeHour.Empresa   = new Empresa();
                newOfficeHour.Id        = Guid.NewGuid();
                newOfficeHour.Empresa   = _empresaRepository.PesquisarPeloId(idEmpresa);
                newOfficeHour.Descricao = Descricao;

                _horarioDeExpedienteRepository.Salvar(newOfficeHour);

                ItemHorarioDeExpediente newItemOfficeHour0 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 0,
                    Horas = 0,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour0);

                ItemHorarioDeExpediente newItemOfficeHour1 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 1,
                    Horas = 8,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour1);

                ItemHorarioDeExpediente newItemOfficeHour2 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 2,
                    Horas = 8,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour2);

                ItemHorarioDeExpediente newItemOfficeHour3 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 3,
                    Horas = 8,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour3);

                ItemHorarioDeExpediente newItemOfficeHour4 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 4,
                    Horas = 8,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour4);

                ItemHorarioDeExpediente newItemOfficeHour5 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 5,
                    Horas = 8,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour5);

                ItemHorarioDeExpediente newItemOfficeHour6 = new ItemHorarioDeExpediente
                {
                    HorarioDeExpediente = newOfficeHour,
                    DiaSemana           = 6,
                    Horas = 0,
                    Id    = Guid.NewGuid()
                };
                _itemHorarioDeExpedienteRepository.Salvar(newItemOfficeHour6);

                //if (UsingTransactionLocal)
                //{
                //    Transacao.Commit();
                //}

                return(new HorarioDeExpedienteDto
                {
                    Id = newOfficeHour.Id,
                    Description = newOfficeHour.Descricao
                });
            }
            catch (Exception)
            {
                //ToDo Implementar log de erro
                //if (UsingTransactionLocal)
                //{
                //    Transacao.Rollback();
                //}
                throw;
            }
        }
        public OfficeHoursDTO CreateForLogin(Guid organizationId)
        {
            try
            {
                HorarioDeExpediente newOfficeHour = new HorarioDeExpediente();

                //var organization = OrganizationService.GetOrganization(organizationId);
                newOfficeHour.Empresa    = new Empresa();
                newOfficeHour.Id         = Guid.NewGuid();
                newOfficeHour.Empresa.Id = organizationId;
                newOfficeHour.Descricao  = "Horário padrão";

                OfficeHoursRepository.Salvar(newOfficeHour);

                #region 'Itens de Hora de expediente 0'

                ItemHorarioDeExpediente itemHorarioPadrao0 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 0,
                    Horas               = 0,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao0);

                #endregion
                #region 'Itens de Hora de expediente 1'

                ItemHorarioDeExpediente itemHorarioPadrao1 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 1,
                    Horas               = 8,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao1);

                #endregion
                #region 'Itens de Hora de expediente 2'

                ItemHorarioDeExpediente itemHorarioPadrao2 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 2,
                    Horas               = 8,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao2);

                #endregion
                #region 'Itens de Hora de expediente 3'

                ItemHorarioDeExpediente itemHorarioPadrao3 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 3,
                    Horas               = 8,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao3);

                #endregion
                #region 'Itens de Hora de expediente 4'

                ItemHorarioDeExpediente itemHorarioPadrao4 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 4,
                    Horas               = 8,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao4);

                #endregion
                #region 'Itens de Hora de expediente 5'

                ItemHorarioDeExpediente itemHorarioPadrao5 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 5,
                    Horas               = 8,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao5);

                #endregion
                #region 'Itens de Hora de expediente 6'

                ItemHorarioDeExpediente itemHorarioPadrao6 = new ItemHorarioDeExpediente()
                {
                    Id                  = Guid.NewGuid(),
                    DiaSemana           = 6,
                    Horas               = 0,
                    HorarioDeExpediente = newOfficeHour,
                    Criacao             = DateTime.Now.Date
                };

                ItemHorarioRepository.Salvar(itemHorarioPadrao6);

                #endregion

                return(new OfficeHoursDTO
                {
                    Id = newOfficeHour.Id,
                    Description = newOfficeHour.Descricao
                });
            }
            catch (Exception)
            {
                //ToDo Implementar log de erro
                throw;
            }
        }