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 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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }