Esempio n. 1
0
        /// <summary>
        /// Save user login session in database
        /// </summary>
        /// <param name="loginName">Login Name</param>
        /// <param name="sid">Session ID</param>
        public void SaveLogin(string loginName, string sid)
        {
            _context.Configuration.AutoDetectChangesEnabled = false;

            try
            {
                var query = from x in _context.TB_L_LOGIN
                            where x.LOGGED_IN == 1 && x.LOGIN_NAME == loginName && x.SESSION_ID == sid
                            // Need to filter by login name
                            select x;

                if (query.Any())
                {
                    TB_L_LOGIN entity = query.FirstOrDefault();
                    entity.LOGGED_IN = 0;
                    _context.Entry(entity).Property("LOGGED_IN").IsModified = true;
                }

                TB_L_LOGIN newLogin = new TB_L_LOGIN();
                newLogin.LOGGED_IN   = 1;
                newLogin.LOGIN_NAME  = loginName;
                newLogin.SESSION_ID  = sid;
                newLogin.CREATE_DATE = DateTime.Now;
                _context.TB_L_LOGIN.Add(newLogin);
                this.Save();
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
            }
            finally
            {
                _context.Configuration.AutoDetectChangesEnabled = false;
            }
        }
Esempio n. 2
0
        public bool SaveExportDate(bool isUpdate)
        {
            _context.Configuration.AutoDetectChangesEnabled = false;

            try
            {
                var today = DateTime.Now;
                IQueryable <TB_R_USER_PHONE> phoneOwners = _context.TB_R_USER_PHONE;
                if (isUpdate)
                {
                    phoneOwners = phoneOwners.Where(p => EntityFunctions.TruncateTime(p.CREATE_DATE) != EntityFunctions.TruncateTime(p.UPDATE_DATE));
                }
                else
                {
                    phoneOwners = phoneOwners.Where(p => EntityFunctions.TruncateTime(p.CREATE_DATE) == EntityFunctions.TruncateTime(p.UPDATE_DATE));
                }


                var UserIds = phoneOwners.Select(o => o.USER_ID).Distinct();

                var users = from u in _context.TB_R_USER
                            where (u.MARKETING_FLAG == true) &&
                            u.EXPORT_DATE == null &&
                            UserIds.Contains(u.USER_ID)
                            select u;

                foreach (var u in users)
                {
                    u.EXPORT_DATE = today;
                    _context.Entry(u).Property("EXPORT_DATE").IsModified = true;
                }

                return(Save() > 0);
            }
            catch (Exception ex) {
                Logger.Error("Exception occur:\n", ex);
            }
            finally
            {
                _context.Configuration.AutoDetectChangesEnabled = true;
            }

            return(false);
        }
Esempio n. 3
0
 private void SetEntryCurrentValues(object entityTo, object entityFrom)
 {
     _context.Entry(entityTo).CurrentValues.SetValues(entityFrom);
     // Set state to Modified
     _context.Entry(entityTo).State = System.Data.Entity.EntityState.Modified;
 }