Esempio n. 1
0
        public static IEnumerable<Shop> GetShopByCityID(int CityID)
        {
            List<Shop> shops;
            List<City> Cities;

            using (var Ctx = new RmsAuto.Store.Entities.dcCommonDataContext())
            {
                Cities = Ctx.Cities.Where(x => x.CityID == CityID).ToList();
            }

            using (var Ctx = new CmsDataContext())
            {
                shops = Ctx.Shops.Where(x => x.ShopVisible && x.CityID == CityID).OrderByDescending(X => X.isRMS).ThenBy(x => x.ShopPriority).ToList();
            }

            return shops;
        }
Esempio n. 2
0
        public static void FormsAuthentication_OnAuthenticate(
            object sender,
            FormsAuthenticationEventArgs args)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                HttpRequest request = HttpContext.Current.Request;
                if (request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
                       request.Cookies[FormsAuthentication.FormsCookieName].Value);

                    string[] parts = ticket.UserData.Split(';');

                    int userId = int.Parse(parts[0]);
                    string acctgId = parts[1];
                    byte bRole = byte.Parse(parts[2]);
                    string  internalFranchName = parts[3];

                    if (!Enum.IsDefined(typeof(SecurityRole), bRole))
                        throw new Exception("Incorrect Users.UserRole value");

                    //
                    if (HttpContext.Current.Request.Cookies["InternalFranchName"] == null || HttpContext.Current.Request.Cookies["InternalFranchName"].Value != internalFranchName)
                    {
                        //SiteContext._internalFranchName = internalFranchName;
                        HttpCookie coockie = new HttpCookie("InternalFranchName");
                        coockie.Domain = "rmsauto.ru";
                        coockie.Path = "/";
                        coockie.Value = HttpUtility.HtmlEncode(internalFranchName);
                        HttpContext.Current.Request.Cookies.Add(coockie);
                        HttpContext.Current.Response.Cookies.Add(coockie);

                        HttpCookie CityNamecoockie = new HttpCookie("cityName");
                        CityNamecoockie.Domain = "rmsauto.ru";
                        CityNamecoockie.Path = "/";
                        IEnumerable<City> cities;
                        using (var dcCommon = new RmsAuto.Store.Entities.dcCommonDataContext())
                        {
                                //Извлекаем наборы данных в списки, так как LINQ to SQL не дает выполнять запросы к различным контекстам
                                //TODO: сделать AcctgRefCatalog.Cities, вынести в справочник, чтобы не лезть в базу каждый раз
                                cities = dcCommon.Cities.Select(x => x).ToList();
                        }
                        //var regionId = AcctgRefCatalog.RmsFranches[(string)context.Request.QueryString[UrlKeys.Activation.FranchCode]].RegionID;
                        var regionId = AcctgRefCatalog.RmsFranches[internalFranchName].RegionID;
                        CityNamecoockie.Value = HttpUtility.UrlEncodeUnicode(cities.Where(x => x.CityID == regionId).Select(x => x.Name).FirstOrDefault());
                        HttpContext.Current.Request.Cookies.Add(CityNamecoockie);
                        HttpContext.Current.Response.Cookies.Add(CityNamecoockie);
                    }

                    SecurityRole role = (SecurityRole)bRole;
                    var user = new CustomPrincipal(
                          new FormsIdentity(ticket),
                          new string[] { role.ToString() },
                          userId,
                          acctgId,
                          role, internalFranchName);
                    args.User = user;
                }
            }
            else
            {
                //DO NOTHING
                //throw new HttpException( "Cookieless Forms Authentication is not " +
                //                        "supported for this application." );
            }
        }