public static bool Remove(int Id) { using (var Dc = new TemplateEntities()) { var Rol = Dc.Rol.Include("RolUsuario").Include("RolMenu").FirstOrDefault(X => X.Id == Id); if (Rol == null) { throw new Exception("No se puede Borrar el Rol porque <strong>no existe</strong>."); } if (Rol.RolMenu.Count > 0) { throw new Exception("No se puede Borrar el Rol porque tiene <strong>Opciones de Menú Asociados</strong>."); } if (Rol.RolUsuario.Count > 0) { throw new Exception("No se puede Borrar el Rol porque tiene <strong>Cuentas de Usuarios Asociados</strong>."); } Dc.Rol.Remove(Rol); var Result = Dc.SaveChanges(); return(Result > 0); } }
public static List <Menu> GetMenu(string Url_, string Texto, string Ayuda, bool?Estado) { using (var Dc = new TemplateEntities()) { var Menu_ = Dc.Menu.Include("Menu2").AsQueryable(); if (!string.IsNullOrEmpty(Url_)) { Menu_ = Menu_.Where(X => X.Url.Contains(Url_.Trim())); } if (!string.IsNullOrEmpty(Texto)) { Menu_ = Menu_.Where(X => X.Texto.Contains(Texto.Trim())); } if (!string.IsNullOrEmpty(Ayuda)) { Menu_ = Menu_.Where(X => X.Ayuda.Contains(Ayuda.Trim())); } if (Estado.HasValue) { Menu_ = Menu_.Where(X => X.Activo == Estado.Value); } return(Menu_.ToList()); } }
public Users GetUserByEmail(string email) { #region GetUserByEmail without Entity //var SQLConnection_ = new SQLConnection(); //var listParam = new List<BaseParamSQL>(){ // new BaseParamSQL() // { // Key = "Email", // Value = email, // LenType = 150, // Type = BaseParamSQL.AllType.VarChar // } // }; //var model = new BaseDataSQL() //{ // Cmd = "[dbo].[GetUserByEmail]", // CmdType = BaseDataSQL.AllCmdType.SP, // Param = listParam //}; //var User = ChangeToModel(SQLConnection_.SendSQL(model), ModelsName.User); #endregion TemplateEntities_ = new TemplateEntities(); var users = TemplateEntities_.GetUserByEmail(email).FirstOrDefault(); Users_ = new Users() { UserID = users.UserID, UserName = users.UserName, Email = users.Email, Available = users.Available }; return(Users_); }
public static bool Edit(int Id, string Nombre, string Descripcion, bool?Activo = null) { using (var Dc = new TemplateEntities()) { var Role = Dc.Rol.Find(Id); if (Role == null) { throw new Exception("No se pudo <strong>Encontrar</strong> el Rol para su <strong>Edición</strong>."); } var Role_ = Dc.Rol.FirstOrDefault(X => X.Nombre.Trim().ToLower() == Nombre.Trim().ToLower() && X.Id != Id); if (Role_ != null) { throw new Exception("No se puede <strong>Editar</strong> el Rol porque <strong>Ya Existe</strong> otro Rol con el mismo <strong>Nombre</strong>."); } Role.Nombre = Nombre.Trim(); Role.Descripcion = Descripcion.Trim(); if (Activo.HasValue) { Role.Activo = Activo.Value; } Dc.Rol.Attach(Role); var Role2_ = Dc.Entry(Role); Role2_.Property(X => X.Nombre).IsModified = true; Role2_.Property(X => X.Descripcion).IsModified = true; Role2_.Property(X => X.Activo).IsModified = true; var Result = Dc.SaveChanges(); return(Result > 0); } }
public Users GetUserById(int id) { #region GetUserById without Entity //var SQLConnection_ = new SQLConnection(); //var model = new BaseDataSQL() //{ // Cmd = "SELECT * FROM [Users] WHERE [UserID] = " + id + ";", // CmdType = BaseDataSQL.AllCmdType.TSql, // Param = null //}; //return ChangeToModel(SQLConnection_.SendSQL(model), BaseServices.ModelsName.Users); #endregion TemplateEntities_ = new TemplateEntities(); var users = TemplateEntities_.GetUserByID(id).FirstOrDefault(); Users_ = new Users() { UserID = users.UserID, UserName = users.UserName, Email = users.Email, Available = users.Available }; return(Users_); }
/// <summary> /// Insert a lign in the database with the result of the mail /// </summary> /// <param name="EMail"></param> /// <param name="AttachmentNumber"></param> /// <param name="CCUsersNumber"></param> /// <returns></returns> public bool InsertEMailAudit(Email EMail, int AttachmentNumber, int CCUsersNumber) { bool result = false; try { var context = new TemplateEntities(); _emailAuditRepo = new GenericRepository <DataEntities.Model.EmailAudit>(context); EmailAudit Audit = new EmailAudit(); Audit.UserId = EMail.UserId; Audit.EMailTypeLanguageId = EMail.EMailTypeLanguageId; Audit.EMailFrom = EMail.FromEmail; Audit.EMailTo = EMail.ToEmail; Audit.Date = DateTime.UtcNow; Audit.AttachmentNumber = AttachmentNumber; Audit.CCUsersNumber = CCUsersNumber; Audit.ScheduledTaskId = EMail.RelatedScheduledTaskId; Audit.Comment = EMail.Comment; _emailAuditRepo.Add(Audit); result = _emailAuditRepo.Save(); } catch (Exception e) { result = false; Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "EMailTypeId = " + EMail.EMailTypeId + " and emailto =" + EMail.ToEmail); } return(result); }
public static List <Menu> GetMenuItems(string PrincipalIdentity) { if (string.IsNullOrEmpty(PrincipalIdentity)) { throw new Exception("Debe especificar la Identidad del Usuario."); } using (var Dc = new TemplateEntities()) { var Usuario_Id = Convert.ToInt32(PrincipalIdentity); var RolesUsuario = GetRoles(PrincipalIdentity); if (RolesUsuario == null || RolesUsuario.Count <= 0) { return(null); } var Menu = new List <Menu>(); if (RolesUsuario.Count <= 0) { return(Menu); } Menu = Dc .Menu .Where(X => X.RolMenu.Any(Y => Y.Rol.Activo && Y.Rol.RolUsuario.Any(Z => Z.Usuario_Id == Usuario_Id)) ).ToList(); return(Menu); } }
public static string GetFullName(string PrincipalIdentity) { if (string.IsNullOrEmpty(PrincipalIdentity)) { throw new Exception("Debe especificar la Identidad del Usuario."); } using (var Dc = new TemplateEntities()) { var Usuario_Id = Convert.ToInt32(PrincipalIdentity); var Usuario_ = Dc .Usuario .FirstOrDefault(X => X.Id == Usuario_Id && X.Activo ); if (Usuario_ == null) { return(null); } var Nombre = string.Format("{0} {1} {2}", Usuario_.Nombre, Usuario_.Apellido_Paterno, Usuario_.Apellido_Materno); return(Nombre); } }
public static string GetProfilePicture(string PrincipalIdentity) { if (string.IsNullOrEmpty(PrincipalIdentity)) { throw new Exception("Debe especificar la Identidad del Usuario."); } using (var Dc = new TemplateEntities()) { var Usuario_Id = Convert.ToInt32(PrincipalIdentity); var Usuario_ = Dc .Usuario .FirstOrDefault(X => X.Id == Usuario_Id && X.Activo ); string Foto; if (Usuario_ == null || Usuario_.Foto == null) { Foto = Resources.NoProfilePicture; } else { Foto = string.Format("data:image/png;base64,{0}", Convert.ToBase64String(Usuario_.Foto)); } return(Foto); } }
public UserService() { var context = new TemplateEntities(); _userRepo = new GenericRepository <DataEntities.Model.User>(context); _aspNetUserRepo = new GenericRepository <AspNetUser>(context); }
public static void SetLastAccess(int Id) { using (var Dc = new TemplateEntities()) { var Usuario_ = Dc .Usuario .FirstOrDefault(X => X.Id == Id && X.Activo ); if (Usuario_ == null) { throw new Exception("No se pudo <strong>Encontrar</strong> el Usuario para establecer su <strong>Último Acceso</strong>."); } Usuario_.Ultimo_Acceso = DateTime.Now; Dc.Usuario.Attach(Usuario_); var Usuario2_ = Dc.Entry(Usuario_); Usuario2_.Property(X => X.Ultimo_Acceso).IsModified = true; Dc.SaveChanges(); } }
public static IEnumerable <Usuario> GetUsers(string Email, string Nombre, string APaterno, string AMaterno, bool?Estado) { using (var Dc = new TemplateEntities()) { var Usuarios = Dc.Usuario.AsQueryable(); if (Estado.HasValue) { Usuarios = Usuarios.Where(X => X.Activo == Estado.Value); } if (!string.IsNullOrEmpty(Email)) { Usuarios = Usuarios.Where(X => X.Email.Contains(Email)); } if (!string.IsNullOrEmpty(Nombre)) { Usuarios = Usuarios.Where(X => X.Nombre.Contains(Nombre)); } if (!string.IsNullOrEmpty(APaterno)) { Usuarios = Usuarios.Where(X => X.Apellido_Paterno.Contains(APaterno)); } if (!string.IsNullOrEmpty(AMaterno)) { Usuarios = Usuarios.Where(X => X.Apellido_Materno.Contains(AMaterno)); } var Usuarios_ = Usuarios.ToList(); return(Usuarios_); } }
public static bool ChangePassword(int Id, string NewPassword, bool DebeCambiarPassword = false) { using (var Dc = new TemplateEntities()) { var Usuario_ = Dc .Usuario .FirstOrDefault(X => X.Id == Id && X.Activo ); if (Usuario_ == null) { throw new Exception("No se pudo <strong>Encontrar</strong> el Usuario para cambiar su <strong>Contraseña</strong>."); } Usuario_.Password = NewPassword; Usuario_.Debe_Cambiar_Password = DebeCambiarPassword; Dc.Usuario.Attach(Usuario_); var Usuario2_ = Dc.Entry(Usuario_); Usuario2_.Property(X => X.Password).IsModified = true; Usuario2_.Property(X => X.Debe_Cambiar_Password).IsModified = true; var Result = Dc.SaveChanges(); return(Result > 0); } }
public static Usuario New(string Email, string Nombre, string APaterno, string AMaterno, string Password) { using (var Dc = new TemplateEntities()) { var User_ = Dc.Usuario.FirstOrDefault(X => X.Email.Trim().ToLower() == Email.Trim().ToLower()); if (User_ != null) { throw new Exception(string.Format("No se puede crear el Usuario con Correo Electrónico <strong>{0}</strong> porque ya existe.", Email)); } User_ = new Usuario { Email = Email.Trim().ToLower(), Nombre = Nombre.Trim(), Apellido_Paterno = APaterno.Trim(), Apellido_Materno = AMaterno.Trim(), Debe_Cambiar_Password = true, Password = Password, Activo = true }; Dc.Usuario.Add(User_); var Result = Dc.SaveChanges(); return(Result > 0 ? User_ : null); } }
public void DeleteUser(Users users) { #region UpdateUser without Entity //var SQLConnection_ = new SQLConnection(); //var listParam = new List<BaseParamSQL>(){ // new BaseParamSQL() // { // Key = "UserID", // Value = users.UserID, // Type = BaseParamSQL.AllType.Int // } // }; //var model = new BaseDataSQL() //{ // Cmd = "RmvUser", // CmdType = BaseDataSQL.AllCmdType.SP, // Param = listParam //}; //SQLConnection_.SendSQL(model); #endregion TemplateEntities_ = new TemplateEntities(); TemplateEntities_.RmvUser(users.UserID); TemplateEntities_.SaveChanges(); }
public List <Users> GetAllUsers() { #region GetAllUsers without Entity // var SQLConnection_ = new SQLConnection(); // var listParam = new List<BaseParamSQL>(); // var model = new BaseDataSQL() // { // Cmd = "[dbo].[GetAllUsers]", // CmdType = BaseDataSQL.AllCmdType.SP, // Param = listParam // }; // var User = ChangeToModel(SQLConnection_.SendSQL(model), ModelsName.Users); // return User; #endregion ListUsers_ = new List <Users>(); TemplateEntities_ = new TemplateEntities(); var users = TemplateEntities_.GetAllUsers(); foreach (var user in users) { ListUsers_.Add(new Users() { UserID = user.UserID, UserName = user.UserName, Email = user.Email, Password = user.Password, LastUpdated = user.LastUpdated, Available = user.Available }); } return(ListUsers_); }
public FileUploadService() { var context = new TemplateEntities(); _userRepo = new GenericRepository <User>(context); _productRepo = new GenericRepository <Product>(context); }
public UserRolesService() { var context = new TemplateEntities(); _aspNetRoleRepo = new GenericRepository <AspNetRole>(context); _aspNetUserRepo = new GenericRepository <AspNetUser>(context); _userRepo = new GenericRepository <User>(context); }
public WeatherService() { var context = new TemplateEntities(); _airportRepo = new GenericRepository <DataEntities.Model.Airport>(context); _historicWeatherRepo = new GenericRepository <DataEntities.Model.HistoricWeather>(context); _cityRepo = new GenericRepository <DataEntities.Model.City>(context); }
public NewsService() { _emailService = new EMailService(); var context = new TemplateEntities(); _userRepo = new GenericRepository <User>(context); _newsRepo = new GenericRepository <News>(context); }
public static Menu FindById(int Id) { using (var Dc = new TemplateEntities()) { var Menu_ = Dc.Menu.Find(Id); return(Menu_); } }
public static Usuario FindById(int Id) { using (var Dc = new TemplateEntities()) { var User_ = Dc.Usuario.Find(Id); return(User_); } }
public static List <Icono> GetAll() { using (var Dc = new TemplateEntities()) { var Iconos = Dc.Icono.ToList(); return(Iconos); } }
public EMailService() { var context = new TemplateEntities(); _userRepo = new GenericRepository <DataEntities.Model.User>(context); _validTopLevelDomainRepo = new GenericRepository <DataEntities.Model.ValidTopLevelDomain>(context); _emailTypeLanguageRepo = new GenericRepository <DataEntities.Model.EmailTypeLanguage>(context); _emailAuditRepo = new GenericRepository <DataEntities.Model.EmailAudit>(context); }
public static Rol FindById(int Id) { using (var Dc = new TemplateEntities()) { var Role = Dc.Rol.Find(Id); return(Role); } }
public static bool Edit(int Id, string Nombre, string APaterno, string AMaterno, byte[] ImageData, bool?Activo = null, string Email = null) { using (var Dc = new TemplateEntities()) { var Usuario_ = Dc .Usuario .FirstOrDefault(X => X.Id == Id && X.Activo ); if (Usuario_ == null) { throw new Exception("No se pudo <strong>Encontrar</strong> el Usuario para su <strong>Edición</strong>."); } Usuario_.Nombre = Nombre.Trim(); Usuario_.Apellido_Paterno = APaterno.Trim(); Usuario_.Apellido_Materno = AMaterno.Trim(); if (ImageData != null) { Usuario_.Foto = ImageData; } if (!string.IsNullOrEmpty(Email)) { Usuario_.Email = Email; } if (Activo.HasValue) { Usuario_.Activo = Activo.Value; } Dc.Usuario.Attach(Usuario_); var Usuario2_ = Dc.Entry(Usuario_); Usuario2_.Property(X => X.Nombre).IsModified = true; Usuario2_.Property(X => X.Apellido_Paterno).IsModified = true; Usuario2_.Property(X => X.Apellido_Materno).IsModified = true; if (ImageData != null) { Usuario2_.Property(X => X.Foto).IsModified = true; } if (!string.IsNullOrEmpty(Email)) { Usuario2_.Property(X => X.Email).IsModified = true; } if (Activo.HasValue) { Usuario2_.Property(X => X.Activo).IsModified = true; } var Result = Dc.SaveChanges(); return(Result > 0); } }
public void UpdateUser(Users users) { #region UpdateUser without Entity //var SQLConnection_ = new SQLConnection(); //var listParam = new List<BaseParamSQL>(){ // new BaseParamSQL() // { // Key = "UserID", // Value = users.UserID, // Type = BaseParamSQL.AllType.Int // }, // new BaseParamSQL() // { // Key = "UserName", // Value = users.UserName, // LenType = 50, // Type = BaseParamSQL.AllType.VarChar // }, // new BaseParamSQL() // { // Key = "Password", // Value = users.Password, // LenType = 50, // Type = BaseParamSQL.AllType.VarChar // }, // new BaseParamSQL() // { // Key = "Email", // Value = users.Email, // LenType = 150, // Type = BaseParamSQL.AllType.VarChar // }, // new BaseParamSQL() // { // Key = "Available", // Value = users.Available, // Type = BaseParamSQL.AllType.Bit // } // }; //var model = new BaseDataSQL() //{ // Cmd = "UpdUser", // CmdType = BaseDataSQL.AllCmdType.SP, // Param = listParam //}; //SQLConnection_.SendSQL(model); #endregion TemplateEntities_ = new TemplateEntities(); TemplateEntities_.UpdUser(users.UserID, users.UserName, users.Password, users.Email, users.Available); TemplateEntities_.SaveChanges(); }
public static List <Menu> GetMenuOthers(int?Id) { using (var Dc = new TemplateEntities()) { var Menu_ = Dc.Menu.AsQueryable(); if (Id.HasValue) { Menu_ = Menu_.Where(X => X.Id != Id.Value); } return(Menu_.ToList()); } }
public PageListInfo <TableSimpleOut> GetList(QTableIn Para, int Page, int PageCount) { using (var db = new TemplateEntities()) { var result = new PageListInfo <TableSimpleOut>(); var data = db.Table_1 .AsExpandable() .Where(PrmMeeingCondition(Para)); //實作 return(result); } }
public static bool AssignRole(int Id, string Roles) { var RolesIds = Roles.Split(','); using (var Dc = new TemplateEntities()) { var MenuRoles = Dc .RolMenu .Where(X => X.Menu_Id == Id ).ToList(); if (MenuRoles.Count > 0) { Dc.RolMenu.RemoveRange(MenuRoles); Dc.SaveChanges(); } if (!RolesIds.Any()) { return(true); } var MenuRoles_ = new List <RolMenu>(); foreach (var Role_ in RolesIds) { if (string.IsNullOrEmpty(Role_)) { continue; } var MenuRole = new RolMenu { Rol_Id = Convert.ToInt32(Role_), Menu_Id = Id }; MenuRoles_.Add(MenuRole); } if (MenuRoles_.Count > 0) { Dc.RolMenu.AddRange(MenuRoles_); var Result = Dc.SaveChanges(); return(Result > 0); } return(true); } }