Ejemplo n.º 1
0
 public static void PutDataToSession <T>(SessionKeys key, T data)
 {
     if (!ConfigurationManager.Instance.IsWebSessionDisabled)
     {
         SessionCore.PutDataToSession <T>(key, data);
     }
 }
Ejemplo n.º 2
0
 /// <summary> set value to ssesion </summary>
 public static void Set <T>(this ISession session, SessionKeys key, T value)
 {
     try
     {
         var sessionKey = key.GetAttribute <DisplayAttribute>().Name;
         // int value
         if (typeof(T) == typeof(int))
         {
             session.SetInt32(sessionKey, Convert.ToInt32(value));
         }
         // string value
         else if (typeof(T) == typeof(string))
         {
             session.SetString(sessionKey, value.ToString());
         }
         // object
         else
         {
             session.SetString(sessionKey, JsonConvert.SerializeObject(value));
         }
     }
     catch (Exception ex)
     {
         Log.Logger.ErrorEx(ex);
     }
 }
Ejemplo n.º 3
0
        public static bool GetCurrentUserData <T>(Guid userId, SessionKeys key, out T data)
        {
            Guid?nullable;
            bool flag;

            if (!ConfigurationManager.Instance.IsWebSessionDisabled && SessionManager.GetCurrentUserId(out nullable))
            {
                Guid?nullable1 = nullable;
                Guid guid      = userId;
                if (nullable1.HasValue)
                {
                    flag = (nullable1.HasValue ? nullable1.GetValueOrDefault() == guid : true);
                }
                else
                {
                    flag = false;
                }
                if (flag)
                {
                    return(SessionCore.GetDataFromSession <T>(key, out data));
                }
            }
            data = default(T);
            return(false);
        }
Ejemplo n.º 4
0
 internal static void PutDataToSession <T>(SessionKeys key, T data)
 {
     if (HttpContext.get_Current() != null && HttpContext.get_Current().get_Session() != null)
     {
         HttpContext.get_Current().get_Session().set_Item(key.ToString(), data);
     }
 }
Ejemplo n.º 5
0
 protected void SaveToSession <T>(SessionKeys key, T value)
 {
     if (value != null)
     {
         HttpContext.Session.Set(GetSessionKey(key), value);
     }
 }
Ejemplo n.º 6
0
        public ActionResult ConfigEquipIndex()
        {
            var vm = new ConfigViewModel();

            string actionName = "ConfigEquipIndex";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.ApplicableUnits, "", "");


                vm._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.ApplicableUnits]);

                vm.selectedData = "0";

                using (var db = new WebAppDbContext())
                {
                    vm.tbl_Parts_list = db.tbl_Parts.Where(x => x.Status == "Active" && (x.PartTypeID == "X" || x.PartTypeID == "A")).ToList();
                    vm._M_PMS         = db.M_PMS.ToList();
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: Ended.");

            return(View("ConfigEquipIndex", vm));
        }
Ejemplo n.º 7
0
        public ActionResult Create(tbl_Cage tbl_Cage)
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new WebAppDbContext())
                    {
                        if (!db.tbl_Cage.Any(x => x.CageCode == tbl_Cage.CageCode))
                        {
                            // Get Current user Id
                            var userId = Session[SessionKeys.UserId]?.ToString();
                            tbl_Cage.CreatedByUser  = userId;
                            tbl_Cage.ModifiedByUser = userId;

                            //Get Current Date & Time.
                            tbl_Cage.CreatedOnDate  = DateTime.Now;
                            tbl_Cage.ModifiedOnDate = DateTime.Now;
                            tbl_Cage.Status         = "Active";

                            db.tbl_Cage.Add(tbl_Cage);
                            db.SaveChanges();


                            Alert("Record Added Successfully !! ", NotificationType.success);
                        }
                        else
                        {
                            _logger.Log(LogLevel.Trace, actionName + " :: Cage code : " + tbl_Cage.CageCode + " already exist.");
                            Alert("Cage code already exist.", NotificationType.error);
                        }
                    }
                }
                else
                {
                    CageViewModels vm = new CageViewModels();

                    SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                    vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);

                    _logger.Log(LogLevel.Trace, actionName + " :: Model state not valid.");
                    return(PartialView("_Create", vm));
                }
            }
            catch (Exception ex)
            {
                Alert("Their is something went wrong!!!", NotificationType.error);
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
                Exception(ex);
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        private bool LoadRole(string roleId)
        {
            string actionName = "LoadRole";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            bool response = false;

            try
            {
                if (!String.IsNullOrWhiteSpace(roleId))
                {
                    List <PermissionViewModel> ListPermissionViewModel = new List <PermissionViewModel>();

                    using (Entities _context = new Entities())
                    {
                        var loginId     = Session[SessionKeys.UserId].ToString();
                        var currentRole = _context.tbl_UserRole.Where(x => x.UserId == loginId && x.RoleId == roleId && x.IsDeleted != 1 && x.IsActive != 0)?.FirstOrDefault().RoleId;

                        if (!string.IsNullOrWhiteSpace(currentRole))
                        {
                            SessionKeys.LoadTablesInSession(SessionKeys.ReloadRolePermissions, "", currentRole);
                            var permissions = ((List <tbl_Permission>)Session[SessionKeys.RolePermissions]);

                            foreach (var item in permissions)
                            {
                                PermissionViewModel permissionViewModel = new PermissionViewModel()
                                {
                                    PermissionId = item.PermissionId,
                                    DisplayName  = item.DisplayName,
                                    Level        = item.PermissionLevel.ToString(),
                                    ParentId     = item.ParentId,
                                    URL          = item.URL
                                };

                                ListPermissionViewModel.Add(permissionViewModel);
                            }

                            Session[SessionKeys.SessionHelperInstance] = ((SessionHelper)Session[SessionKeys.SessionHelperInstance]).UpdateFields(roleId, ListPermissionViewModel);

                            response = true;
                        }
                        else
                        {
                            // Show some error
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " :: Exception : " + ex.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");
            return(response);
        }
Ejemplo n.º 9
0
        public static T GetDataFromSession <T>(SessionKeys key)
        {
            T t;

            if (!ConfigurationManager.Instance.IsWebSessionDisabled && SessionCore.GetDataFromSession <T>(key, out t))
            {
                return(t);
            }
            return(default(T));
        }
        public static string Get(HttpContext context, SessionKeys key)
        {
            string sessionName = keys[key];

            if (context.Session == null)
            {
                return(null);
            }

            return(context.Session.GetString(sessionName));
        }
Ejemplo n.º 11
0
 internal static void RemoveDataFromSession(params SessionKeys[] keys)
 {
     if (HttpContext.get_Current() != null && HttpContext.get_Current().get_Session() != null)
     {
         SessionKeys[] sessionKeysArray = keys;
         for (int i = 0; i < (int)sessionKeysArray.Length; i++)
         {
             SessionKeys sessionKey = sessionKeysArray[i];
             HttpContext.get_Current().get_Session().Remove(sessionKey.ToString());
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary> set value to ssesion </summary>
 public static void Set(this ISession session, SessionKeys key, string value)
 {
     try
     {
         var keyName = key.GetAttribute <DisplayAttribute>().Name;
         session.SetString(keyName, value);
     }
     catch (Exception ex)
     {
         Log.Logger.ErrorEx(ex);
     }
 }
Ejemplo n.º 13
0
 private CageViewModels GetCage(int id)
 {
     SessionKeys.LoadTablesInSession(SessionKeys.Countries);
     using (var db = new WebAppDbContext())
     {
         var viewModel = new CageViewModels()
         {
             tbl_Cage     = db.tbl_Cage.FirstOrDefault(x => x.CageId == id),
             _tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]),
         };
         return(viewModel);
     }
 }
Ejemplo n.º 14
0
        private Guid GenerateSessionKeys()
        {
            SessionKeys keys = new SessionKeys();

            keys.P = GetBigPrime();
            keys.G = FindPrimitiveRoot(keys.P);
            keys.X = GenerateRandom();
            keys.Y = BinPow(keys.G, keys.X, keys.P);
            Guid guid = Guid.NewGuid();

            keyStorage.Add(guid, keys);
            return(guid);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// セッション情報の保存
        /// </summary>
        /// <param name="uniqueSessionKey">ユニークセッションキー</param>
        /// <param name="sessionKey">セッションキー</param>
        /// <param name="tempDataModel">一時データ</param>
        protected void SaveSession(string uniqueSessionKey, SessionKeys sessionKey, object tempDataModel)
        {
            string sessionKeyText = sessionKey.ToString();

            if (!(Session[sessionKeyText] is Dictionary <string, object> sessionMap))
            {
                sessionMap = new Dictionary <string, object>();
            }

            sessionMap[uniqueSessionKey] = tempDataModel;

            Session[sessionKeyText] = sessionMap;
        }
Ejemplo n.º 16
0
 internal static bool GetDataFromSession <T>(SessionKeys key, out T data)
 {
     if (HttpContext.get_Current() != null && HttpContext.get_Current().get_Session() != null)
     {
         object item = HttpContext.get_Current().get_Session().get_Item(key.ToString());
         if (item is T)
         {
             data = (T)item;
             return(true);
         }
     }
     data = default(T);
     return(false);
 }
Ejemplo n.º 17
0
        /// <summary> get value from ssesion </summary>
        public static string Get(this ISession session, SessionKeys key)
        {
            try
            {
                var sessionKey = key.GetAttribute <DisplayAttribute>().Name;
                var value      = session.GetString(sessionKey);
                return(value);
            }
            catch (Exception ex)
            {
                Log.Logger.ErrorEx(ex);
            }

            return(string.Empty);
        }
Ejemplo n.º 18
0
        public Signature GenerateSignature(String message)
        {
            Guid        key  = GenerateSessionKeys();
            SessionKeys keys = keyStorage[key];

            byte[]     hash      = GetHash(message);
            BigInteger digest    = (new BigInteger(hash) + keys.P - 1) % (keys.P - 1);
            BigInteger k         = FindMutuallyPrimeNumber(keys.P - 1);
            BigInteger r         = BinPow(keys.G, k, keys.P);
            BigInteger kOpposite = FindOpposite(k, keys.P - 1);
            BigInteger s         = (((((digest % (keys.P - 1)) - (keys.X * r) % (keys.P - 1))) % (keys.P - 1) * kOpposite % (keys.P - 1)) % (keys.P - 1) + keys.P - 1) % (keys.P - 1);
            Signature  result    = new Signature {
                SignatureId = key, R = Convert.ToBase64String(r.ToByteArray()), S = Convert.ToBase64String(s.ToByteArray())
            };

            return(result);
        }
Ejemplo n.º 19
0
        //string baseUrl;
        //RedirectUrls redirectUrls;

        public IActionResult BeginPayment(Controller controller, string invoiceNumber, Amount amount, ItemList itemList, string intent = "sale")
        {
            string paymentGuid = Convert.ToString((new Random()).Next(100000));
            Payer  payer       = new Payer()
            {
                payment_method = "paypal",
            };
            string       baseUrl      = controller.Request.Scheme + "://" + controller.Request.Host + controller.Request.Path + "?" + QueryKeys.PaymentGuid + "=" + paymentGuid;
            RedirectUrls redirectUrls = new RedirectUrls()
            {
                cancel_url = baseUrl + "&" + QueryKeys.PaymentState + "=" + QueryValues.States.Canceled,
                return_url = baseUrl + "&" + QueryKeys.PaymentState + "=" + QueryValues.States.Created
            };
            List <Transaction> transactions = new List <Transaction> {
                new Transaction()
                {
                    description    = "Transaction description.",
                    invoice_number = invoiceNumber,
                    amount         = amount,
                    item_list      = itemList,
                }
            };
            Payment payment = new Payment()
            {
                intent        = intent,
                payer         = payer,
                transactions  = transactions,
                redirect_urls = redirectUrls
            };
            //try
            //{
            Payment createdPayment = payment.Create(apiContext);
            string  redirectUrl    = createdPayment.links.Where(x => x.rel.ToLower().Trim().Equals("approval_url")).Select(x => x.href).FirstOrDefault();

            //}
            //catch(PayPal.PaymentsException e)
            //{
            //    e.Details
            //}
            if (redirectUrl == null)
            {
                throw new Exception("No approval_url found in the response.");
            }
            controller.HttpContext.Session.SetString(SessionKeys.PaymentId(paymentGuid), createdPayment.id);
            return(controller.Redirect(redirectUrl));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// セッション情報の保存
        /// </summary>
        /// <param name="vm">ビューモデル</param>
        /// <param name="sessionKey">セッションキー</param>
        /// <param name="tempDataModel">一時データ</param>
        protected void SaveSession(ViewModelBase vm, SessionKeys sessionKey, object tempDataModel)
        {
            if (string.IsNullOrEmpty(vm.UniqueSessionKey))
            {
                vm.UniqueSessionKey = Guid.NewGuid().ToString("N");
            }

            string sessionKeyText = sessionKey.ToString();

            if (!(Session[sessionKeyText] is Dictionary <string, object> sessionMap))
            {
                sessionMap = new Dictionary <string, object>();
            }

            sessionMap[vm.UniqueSessionKey] = tempDataModel;

            Session[sessionKeyText] = sessionMap;
        }
Ejemplo n.º 21
0
        public bool Check(string text, Signature signature)
        {
            SessionKeys keys = keyStorage[signature.SignatureId];
            BigInteger  R    = new BigInteger(Convert.FromBase64String(signature.R));
            BigInteger  S    = new BigInteger(Convert.FromBase64String(signature.S));

            if (R <= 0 || R >= keys.P)
            {
                return(false);
            }
            if (S <= 0 || S >= keys.P - 1)
            {
                return(false);
            }
            byte[]     hash   = GetHash(text);
            BigInteger digest = (new BigInteger(hash) + keys.P - 1) % (keys.P - 1);

            return((BinPow(keys.Y, R, keys.P) * BinPow(R, S, keys.P)) % keys.P == BinPow(keys.G, digest, keys.P));
        }
Ejemplo n.º 22
0
        public ActionResult Create()
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");
            CageViewModels vm = new CageViewModels();

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");
            return(PartialView("_Create", vm));
        }
Ejemplo n.º 23
0
        public ActionResult Index()
        {
            string actionName = "Index";

            _logger.Log(LogLevel.Error, actionName + " :: started.");

            var vm = new ConfigViewModel();

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.AllUnits, "", "");
                vm._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.AllUnits]);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Error, actionName + " :: Ended.");

            return(View("Index", vm));
        }
Ejemplo n.º 24
0
        public static void PutCurrentUserData <T>(Guid userId, SessionKeys key, T data)
        {
            Guid?nullable;
            bool flag;

            if (!ConfigurationManager.Instance.IsWebSessionDisabled && SessionManager.GetCurrentUserId(out nullable))
            {
                Guid?nullable1 = nullable;
                Guid guid      = userId;
                if (nullable1.HasValue)
                {
                    flag = (nullable1.HasValue ? nullable1.GetValueOrDefault() == guid : true);
                }
                else
                {
                    flag = false;
                }
                if (flag)
                {
                    SessionCore.PutDataToSession <T>(key, data);
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary> get value from session </summary>
        public static T Get <T>(this ISession session, SessionKeys key)
        {
            var result = default(T);

            try
            {
                var sessionKey = key.GetAttribute <DisplayAttribute>().Name;

                if (!session.Keys.Contains(sessionKey))
                {
                    Log.Logger.ErrorCall($"Get session key {sessionKey}: not exist in session!");
                    return(result);
                }

                // int value
                if (typeof(T) == typeof(int))
                {
                    result = (T)Convert.ChangeType(session.GetInt32(sessionKey), typeof(T));
                }
                // string value
                else if (typeof(T) == typeof(string))
                {
                    result = (T)Convert.ChangeType(session.GetString(sessionKey), typeof(T));
                }
                // object
                else
                {
                    result = JsonConvert.DeserializeObject <T>(session.GetString(sessionKey));
                }
            }
            catch (Exception ex)
            {
                Log.Logger.ErrorEx(ex);
            }

            return(result);
        }
Ejemplo n.º 26
0
 public string GetSessionKey(SessionKeys sessionKey)
 {
     return(sharedPreference.GetString(Enum.GetName(typeof(SessionKeys), sessionKey), null));
 }
Ejemplo n.º 27
0
 public static string ToSessionKey(this string controllerName, SessionKeys key)
 {
     return($"{controllerName.ToControllerName()}.{Enum.GetName(typeof(SessionKeys), key)}");
 }
Ejemplo n.º 28
0
        public static object Get(SessionKeys chave)
        {
            String chaveString = Enum.GetName(typeof(SessionKeys), chave);

            return(HttpContext.Current.Session[chaveString]);
        }
Ejemplo n.º 29
0
        private bool PopulateSessions()
        {
            bool   response   = false;
            string actionName = "PopulateSessions";

            try
            {
                _logger.Log(LogLevel.Trace, actionName + " :: started.");

                SessionKeys.LoadTablesInSession(SessionKeys.AllUnits);
                SessionKeys.LoadTablesInSession(SessionKeys.UnitTypes);

                if (Session[SessionKeys.UserId] != null)
                {
                    var userId = Session[SessionKeys.UserId]?.ToString();

                    using (Entities _context = new Entities())
                    {
                        var data = _context.tbl_User.Where(x => x.UserId == userId && x.IsActive != 0 && x.IsDeleted != 1).FirstOrDefault();

                        if (data != null)
                        {
                            Session[SessionKeys.UserUnitId] = data.UnitId;

                            var allUnits = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.AllUnits]);
                            var unit     = allUnits.Where(x => x.Id == data.UnitId).FirstOrDefault();

                            if (unit != null && unit.UnitTypeId != null)
                            {
                                var unitLevel = ((List <ClassLibrary.Models.tbl_UnitType>)Session[SessionKeys.UnitTypes]).Where(x => x.UnitTypeId == unit.UnitTypeId).Select(x => x.UnitTypeLevel).FirstOrDefault();

                                IEnumerable <ClassLibrary.Models.tbl_Unit> UnitList;

                                if (unitLevel == 0)
                                {
                                    UnitList = allUnits;
                                }
                                else if (unitLevel == 1)
                                {
                                    var lookup = allUnits.ToLookup(x => x.ParentUnitId);
                                    var res    = lookup[data.UnitId].SelectRecursive(x => lookup[x.Id]).ToList();
                                    res.Add(unit);
                                    UnitList = res;
                                }
                                else
                                {
                                    UnitList = allUnits.Where(x => x.Id == data.UnitId).ToList();
                                }

                                Session[SessionKeys.ApplicableUnits] = UnitList;

                                response = true;
                            }
                            else
                            {
                                _logger.Log(LogLevel.Error, actionName + " :: Ended.. Unit Id : " + data.UnitId + " not found.");
                                RedirectToAction("Login", "Account");
                            }
                        }
                        else
                        {
                            _logger.Log(LogLevel.Error, actionName + " ::  Ended.. User not found.");
                            RedirectToAction("Login", "Account");
                        }
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Error, actionName + " :: Ended.. session user is null or empty.");
                    RedirectToAction("Login", "Account");
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }
            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(response);
        }
Ejemplo n.º 30
0
 public void SaveSessionKey(SessionKeys sessionKey, string value)
 {
     sharedPreferenceEditor.PutString(Enum.GetName(typeof(SessionKeys), sessionKey), value);
     sharedPreferenceEditor.Commit();
 }