Пример #1
0
 /// <summary>
 /// Busca registros de ponto de uma determinado período e usuário
 /// </summary>
 /// <param name="startDate">Data em formato GMT</param>
 /// <param name="endDate">Data em formato GMT</param>
 /// <param name="userId">Id do usuário</param>
 /// <param name="desc">Verdadeiro para ordernar decrescente e Falso para ordernar crescente</param>
 /// <returns></returns>
 public List<RegisterModel> LoadBetween(DateTime startDate, DateTime endDate, int userId, bool desc)
 {
     using (var appontoContext = new AppontoContext())
     {
         return Load(startDate, endDate.AddDays(1), userId, desc);
     }
 }
Пример #2
0
        public bool Exist(string email)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.ds_email == email).FirstOrDefault();

                return (tbUser != null);
            }
        }
Пример #3
0
        public CompanyModel Get(string token)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_company tbCompany = appontoContext.tb_company.Where(x => x.ds_token == token).FirstOrDefault();

                return ToModel(tbCompany);
            }
        }
Пример #4
0
        public bool Authenticate(UserModel user)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.SingleOrDefault(x => x.ds_email == user.Email);

                return (tbUser != null && tbUser.ds_password == user.Password);
            }
        }
Пример #5
0
        public UserModel GetByEmail(UserModel user)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.ds_email == user.Email).FirstOrDefault();

                return ToModel(tbUser);
            }
        }
Пример #6
0
        public UserModel Get(int userId)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.id_user == userId).FirstOrDefault();

                return ToModel(tbUser);

            }
        }
        public ConfigurationLimitationModel Add(ConfigurationLimitationModel configurationLimitation)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_configuration_limitation tbConfiguracaoLimitacao= ToDbModel(configurationLimitation);
                appontoContext.tb_configuration_limitation.Add(tbConfiguracaoLimitacao);
                appontoContext.SaveChanges();

                ConfigurationLimitationModel ret = ToModel(tbConfiguracaoLimitacao);

                return ret;
            }
        }
        public List<AccessLevelModel> Get(int userId)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.id_user == userId).FirstOrDefault();
                List<AccessLevelModel> ret = new List<AccessLevelModel>();

                foreach (tb_access_level accessLevel in tbUser.tb_access_level)
                    ret.Add(ToModel(accessLevel));

                return ret;
            }
        }
        public List<AccessLevelModel> Get()
        {
            using (var appontoContext = new AppontoContext())
            {
                List<tb_access_level> tbAccessLevels = appontoContext.tb_access_level.ToList();
                List<AccessLevelModel> ret = new List<AccessLevelModel>();

                foreach (tb_access_level tbAccessLevel in tbAccessLevels)
                    ret.Add(ToModel(tbAccessLevel));

                return ret;
            }
        }
Пример #10
0
        public List<UserModel> Get()
        {
            using (var appontoContext = new AppontoContext())
            {
                List<tb_user> tbUsers = appontoContext.tb_user.ToList();
                List<UserModel> ret = new List<UserModel>();

                foreach (tb_user tbUser in tbUsers)
                    ret.Add(ToModel(tbUser));

                return ret;
            }
        }
Пример #11
0
        public CompanyModel Add(CompanyModel  company)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_company tbCompany = ToDbModel(company);
                appontoContext.tb_company.Add(tbCompany);
                appontoContext.SaveChanges();

                CompanyModel ret = ToModel(tbCompany);

                return ret;
            }
        }
Пример #12
0
        public List<UserModel> GetByCompany(int companyId)
        {
            using (var appontoContext = new AppontoContext())
            {
                List<tb_user> tbUsers = appontoContext.tb_user.Where(x => x.tb_company_id_company == companyId).ToList();
                List<UserModel> ret = new List<UserModel>();

                foreach (tb_user tbUser in tbUsers)
                    ret.Add(ToModel(tbUser));

                return ret;

            }
        }
Пример #13
0
        private List<RegisterModel> Load(DateTime startDate, DateTime endDate, int userId, bool desc)
        {
            using (var appontoContext = new AppontoContext())
            {
                List<tb_register> tbRegisterList;
                List<RegisterModel> ret = new List<RegisterModel>();
                tbRegisterList = appontoContext.tb_register.Where(x => x.tb_user.id_user == userId
                                                                 && DbFunctions.AddHours(x.dt_register, x.vl_gmt) >= startDate && DbFunctions.AddHours(x.dt_register, x.vl_gmt) < endDate).OrderBy(x => x.dt_register).ToList();
                if(desc)
                    tbRegisterList = tbRegisterList.OrderByDescending(x => x.dt_register).ToList();

                foreach (tb_register reg in tbRegisterList)
                    ret.Add(ToModel(reg));

                return ret;
            }
        }
Пример #14
0
        private bool Add(int userId, List<AccessLevelModel> accessLevels)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.id_user == userId).FirstOrDefault();

                foreach (AccessLevelModel accessLevel in accessLevels)
                {
                    tb_access_level tbAccessLevel = ToDbModel(accessLevel);

                    appontoContext.tb_access_level.Attach(tbAccessLevel);
                    tbAccessLevel.tb_user.Add(tbUser);
                }

                appontoContext.SaveChanges();

                return true;
            }
        }
Пример #15
0
        public RegisterModel Add(RegisterModel register)
        {
            using (var appontoContext = new AppontoContext())
            {
                RegisterModel lastRegister = LoadCurrentDay(register.Date, register.User.Id, true).FirstOrDefault();

                if (lastRegister != null)
                {
                    register.IdLastRegister = lastRegister.Id;
                }

                register.Gmt = register.User.Gmt;

                tb_register tbRegister = ToDbModel(register);
                appontoContext.tb_register.Add(tbRegister);
                appontoContext.SaveChanges();

                RegisterModel ret = ToModel(tbRegister);

                return ret;
            }
        }
        public UserModel Update(int userId, ConfigurationLimitationModel configurationLimitation)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.SingleOrDefault(x => x.id_user == userId);

                tbUser.tb_configuration.tb_configuration_limitation.tb_limitation_type_id_limitation_type = configurationLimitation.LimitationType.Id;
                if (configurationLimitation.LimitationType.Id == (int)LimitationTypeEnum.Gps)
                {
                    tbUser.tb_configuration.tb_configuration_limitation.vl_latitude = configurationLimitation.Latitude;
                    tbUser.tb_configuration.tb_configuration_limitation.vl_longitude = configurationLimitation.Longitude;
                }
                else if (configurationLimitation.LimitationType.Id == (int)LimitationTypeEnum.Wifi)
                {
                    tbUser.tb_configuration.tb_configuration_limitation.ds_host = configurationLimitation.Host;
                }

                appontoContext.SaveChanges();

                UserModel ret = new UserService().ToModel(tbUser);

                return ret;
            }
        }
Пример #17
0
        public UserModel UpdatePersonalInformation(UserModel user)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.SingleOrDefault(x => x.id_user == user.Id);

                tbUser.ds_name = user.Name;
                tbUser.ds_lastname = user.LastName;
                tbUser.id_identification = user.Identification;

                appontoContext.SaveChanges();

                UserModel ret = ToModel(tbUser);

                return ret;
            }
        }
Пример #18
0
        public UserModel New(UserModel user)
        {
            using (var appontoContext = new AppontoContext())
            {
                #region Configurações iniciais do usuário
                ConfigurationModel configuration = new ConfigurationModel();
                ConfigurationLimitationModel configurationLimitation = new ConfigurationLimitationModel();

                ConfigurationService configurationService = new ConfigurationService();
                ConfigurationLimitationService configurationLimitationService = new ConfigurationLimitationService();

                configurationLimitation.LimitationType = new LimitationTypeModel() { Id = (int)LimitationTypeEnum.Nenhuma };
                configurationLimitation = configurationLimitationService.Add(configurationLimitation);

                configuration.ConfigurationLimitation = configurationLimitation;

                user.Configuration = configurationService.Add(configuration);
                user.Gmt = -3;
                #endregion

                tb_user tbUser = ToDbModel(user);

                #region Empresa
                bool newCompany = false;

                if (user.Company != null)
                {
                    CompanyService companyService = new CompanyService();

                    if (string.IsNullOrEmpty(user.Company.Token))
                    {
                        newCompany = true;
                        user.Company.Token = Guid.NewGuid().ToString().Substring(0, 10);
                        tbUser.tb_company = companyService.ToDbModel(user.Company);
                    }
                    else
                    {
                        tbUser.tb_company_id_company = companyService.Get(user.Company.Token).Id;
                    }
                }
                #endregion

                #region Permissões iniciais do usuário
                AccessLevelService accessLevelService = new AccessLevelService();
                List<AccessLevelModel> accessLevels = new List<AccessLevelModel>();

                if (user.Company != null && newCompany)
                    accessLevels.Add(new AccessLevelModel() { Id = (int)AccessLevelEnum.Administrator });
                else
                    accessLevels.Add(new AccessLevelModel() { Id = (int)AccessLevelEnum.User });

                user.AccessLevel = accessLevels;
                foreach (AccessLevelModel accessLevel in accessLevels)
                {
                    tb_access_level tbAccessLevel = accessLevelService.ToDbModel(accessLevel);
                    appontoContext.tb_access_level.Attach(tbAccessLevel);
                    tbUser.tb_access_level.Add(tbAccessLevel);
                }
                #endregion

                appontoContext.tb_user.Add(tbUser);
                appontoContext.SaveChanges();

                UserModel ret = ToModel(tbUser);

                return ret;
            }
        }
Пример #19
0
        private bool Remove(int userId)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.id_user == userId).FirstOrDefault();

                var accessLevels = tbUser.tb_access_level.ToList();
                accessLevels.ForEach(x => tbUser.tb_access_level.Remove(x));

                appontoContext.SaveChanges();

                return true;
            }
        }
Пример #20
0
        public bool UpdateAccessInformation(UserModel user)
        {
            using (var appontoContext = new AppontoContext())
            {
                tb_user tbUser = appontoContext.tb_user.Where(x => x.id_user == user.Id).FirstOrDefault();

                if (tbUser.ds_password != user.OldPassword)
                    return false;

                tbUser.ds_password = user.Password;

                appontoContext.SaveChanges();

                return true;
            }
        }