Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbModel"></param>
        /// <returns></returns>
        public int RecordRemove(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    var record = db.SEC_USER.Where(x => x.ID == dbModel.Id).FirstOrDefault();
                    if (record == null)
                    {
                        return(3);
                    }
                    //db.SEC_ROLE.Remove(record);

                    record.REMOVED        = true;
                    record.REMOVE_DATE    = dbModel.CurrentDate;
                    record.REMOVE_USER_ID = dbModel.UserInSessionId;

                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            };
        }
Beispiel #2
0
        public UserDbModel Login(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                var login = (from user in db.SEC_USER
                             where user.EMAIL.ToUpper().Equals(dbModel.Email.ToUpper()) && user.USER_PASSWORD.Equals(dbModel.Password)
                             select user).FirstOrDefault();

                if (login == null)
                {
                    return(null);
                }

                var         date    = dbModel.CurrentDate;
                SEC_SESSION session = new SEC_SESSION()
                {
                    USERID       = login.ID,
                    LOGIN_DATE   = date,
                    TOKEN_STATUS = true,
                    TOKEN        = this.GetToken(String.Concat(login.ID, date)),
                    IP_ADDRESS   = this.GetIpAddress()
                };

                db.SEC_SESSION.Add(session);
                db.SaveChanges();
                UserModelMapper mapper = new UserModelMapper();
                return(mapper.MapperT1T2(login));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Actualización de un registro
        /// </summary>
        /// <param name="dbModel"></param>
        /// <returns></returns>
        public int RecordUpdate(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    var record = db.SEC_USER.Where(x => x.ID == dbModel.Id).FirstOrDefault();
                    if (record == null)
                    {
                        return(3);
                    }

                    record.NAME           = dbModel.Name;
                    record.LASTNAME       = dbModel.Lastname;
                    record.CELLPHONE      = dbModel.Cellphone;
                    record.EMAIL          = dbModel.Email;
                    record.USER_PASSWORD  = dbModel.Password;
                    record.UPDATE_USER_ID = dbModel.UserInSessionId;
                    record.UPDATE_DATE    = dbModel.CurrentDate;

                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Se agrega un nuevo registro a los roles
        /// </summary>
        /// <param name="dbModel">Representa un objeto con la información del rol</param>
        /// <returns>entero con la respuesta: 1. OK, 2. KO, 3. Ya existe</returns>
        public int RecordCreation(RoleDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    // Verifica si existe un role con el nombre que se quiere crear el nuevo
                    if (db.SEC_ROLE.Where(x => x.NAME.ToUpper().Equals(dbModel.Name.ToUpper())).Count() > 0)
                    {
                        return(3);
                    }

                    RoleModelMapper mapper = new RoleModelMapper();
                    SEC_ROLE        record = mapper.MapperT2T1(dbModel);

                    db.SEC_ROLE.Add(record);
                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable <UserDbModel> RecordList(string filter)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                var lista = from role in db.SEC_USER
                            where !role.REMOVED && role.NAME.ToUpper().Contains(filter.ToUpper())
                            select role;

                UserModelMapper mapper     = new UserModelMapper();
                var             listaFinal = mapper.MapperT1T2(lista);

                return(listaFinal);
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable <RoleDbModel> RecordList(string filter)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                //var listaLambda = db.SEC_ROLE.Where(x => !x.REMOVED && x.NAME.ToUpper().Contains(filter.ToUpper())).ToList();

                var listaLinq = from role in db.SEC_ROLE
                                where !role.REMOVED && role.NAME.ToUpper().Contains(filter.ToUpper())
                                select role;

                RoleModelMapper mapper     = new RoleModelMapper();
                var             listaFinal = mapper.MapperT1T2(listaLinq);

                return(listaFinal);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Se agrega un nuevo registro a los roles
        /// </summary>
        /// <param name="dbModel">Representa un objeto con la información del rol</param>
        /// <returns>entero con la respuesta: 1. OK, 2. KO, 3. Ya existe</returns>
        public int RecordCreation(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    UserModelMapper mapper = new UserModelMapper();
                    SEC_USER        record = mapper.MapperT2T1(dbModel);
                    record.CREATE_DATE    = dbModel.CurrentDate;
                    record.CREATE_USER_ID = dbModel.UserInSessionId;

                    db.SEC_USER.Add(record);
                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbModel"></param>
        /// <returns></returns>
        public int RecordRemove(RoleDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    var record = db.SEC_ROLE.Where(x => x.ID == dbModel.Id).FirstOrDefault();
                    if (record == null)
                    {
                        return(3);
                    }
                    //db.SEC_ROLE.Remove(record);

                    record.REMOVED = true;

                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            };
        }