예제 #1
0
        private static List <DocumentMetadata> GetDocumentMetadata()
        {
            var list = new List <DocumentMetadata>();

            foreach (
                Type type in
                TypeHelper.GetAllConcreteMappedClassesAssignableFrom <Webpage>()
                .Where(type => !type.ContainsGenericParameters))
            {
                var types =
                    TypeHelper.GetAllConcreteTypesAssignableFrom(typeof(DocumentMetadataMap <>).MakeGenericType(type));
                if (types.Any())
                {
                    var definition = MrCMSApplication.Get(types.First()) as IGetDocumentMetadata;
                    list.Add(definition.Metadata);
                }
                else
                {
                    var definition =
                        MrCMSApplication.Get(typeof(DefaultDocumentMetadata <>).MakeGenericType(type)) as
                        IGetDocumentMetadata;
                    list.Add(definition.Metadata);
                }
            }
            return(list.OrderBy(x => x.DisplayOrder).ToList());
        }
예제 #2
0
        private void SetUpInitialData(InstallModel model, IDatabaseProvider provider)
        {
            var configurator = new NHibernateConfigurator(provider);

            ISessionFactory   sessionFactory   = configurator.CreateSessionFactory();
            ISession          session          = sessionFactory.OpenFilteredSession();
            IStatelessSession statelessSession = sessionFactory.OpenStatelessSession();
            var kernel = MrCMSApplication.Get <IKernel>();

            kernel.Rebind <ISession>().ToMethod(context => session);
            kernel.Rebind <IStatelessSession>().ToMethod(context => statelessSession);
            var site = new Site
            {
                Name      = model.SiteName,
                BaseUrl   = model.SiteUrl,
                CreatedOn = DateTime.UtcNow,
                UpdatedOn = DateTime.UtcNow
            };

            using (ITransaction transaction = statelessSession.BeginTransaction())
            {
                statelessSession.Insert(site);
                transaction.Commit();
            }
            CurrentRequestData.CurrentSite = site;

            kernel.Get <IInitializeDatabase>().Initialize(model);
            kernel.Get <ICreateInitialUser>().Create(model);
            kernel.GetAll <IOnInstallation>()
            .OrderBy(installation => installation.Priority)
            .ForEach(installation => installation.Install(model));
        }
        public static List <SelectListItem> GetShippingMethodPerOrder(this int orderId)
        {
            var order           = MrCMSApplication.Get <IOrderAdminService>().Get(orderId);
            var shippingMethods = MrCMSApplication.Get <IShippingMethodAdminService>().GetAll()
                                  .Where(info => info.Enabled);

            if (order == null)
            {
                return(shippingMethods.BuildSelectItemList(info => info.DisplayName, info => info.Name, emptyItem: null));
            }

            if (string.IsNullOrWhiteSpace(order.ShippingMethodName))
            {
                return(shippingMethods.BuildSelectItemList(info => info.DisplayName, info => info.Name, emptyItem: null));
            }

            var shippingMethodInfo = shippingMethods.SingleOrDefault(x => x.Name.ToLower() == order.ShippingMethodName.ToLower());

            if (shippingMethodInfo == null)
            {
                return(shippingMethods.BuildSelectItemList(info => info.DisplayName, info => info.Name, emptyItem: null));
            }

            return(shippingMethods
                   .BuildSelectItemList(info => info.DisplayName, info => info.Name, info => info.Name == order.ShippingMethodName, emptyItem: null));
        }
예제 #4
0
        public static MvcHtmlString RenderRecaptcha(this IHtmlHelper helper, string id = null, string errorClass = null,
                                                    string errorMessage = null)
        {
            var settings = MrCMSApplication.Get <GoogleRecaptchaSettings>();

            return(RenderDiv(id, errorClass, errorMessage, settings));
        }
예제 #5
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            User user = base.BindModel(controllerContext, bindingContext) as User;

            IEnumerable <string> roleValues = controllerContext.HttpContext.Request.Params.AllKeys.Where(s => s.StartsWith("Role-"));

            foreach (string value in roleValues)
            {
                string s            = controllerContext.HttpContext.Request[value];
                bool   roleSelected = s.Contains("true");
                int    id           = Convert.ToInt32(value.Split('-')[1]);

                UserRole role = Session.Get <UserRole>(id);
                if (MrCMSApplication.Get <IRoleService>().IsOnlyAdmin(user) && role.IsAdmin)
                {
                    continue;
                }

                if (roleSelected && !user.Roles.Contains(role))
                {
                    user.Roles.Add(role);
                    role.Users.Add(user);
                }
                else if (!roleSelected && user.Roles.Contains(role))
                {
                    user.Roles.Remove(role);
                    role.Users.Remove(user);
                }
            }
            return(user);
        }
예제 #6
0
 public MrCMSErrorLog(IDictionary config)
 {
     if (CurrentRequestData.DatabaseIsInstalled)
     {
         _session = MrCMSApplication.Get <ISessionFactory>().OpenFilteredSession(CurrentRequestData.CurrentContext);
     }
 }
 public static int GetCommentsCount(this Webpage webpage)
 {
     return(MrCMSApplication.Get <ISession>().QueryOver <Comment>()
            .Where(comment =>
                   comment.Webpage == webpage && comment.Approved == true &&
                   comment.InReplyTo == null).Cacheable().RowCount());
 }
예제 #8
0
        public static void IncludeCss(this HtmlHelper helper, string url)
        {
            var webPage     = helper.ViewDataContainer as WebPageBase;
            var virtualPath = webPage == null ? string.Empty : webPage.VirtualPath;

            MrCMSApplication.Get <IResourceBundler>().AddCss(virtualPath, url);
        }
예제 #9
0
 public override string FormatErrorMessage(string name)
 {
     if (string.IsNullOrWhiteSpace(this.ErrorMessage))
     {
         return(null);
     }
     return(MrCMSApplication.Get <IStringResourceProvider>().GetValue(name + "is required", this.ErrorMessage));
 }
예제 #10
0
 public static bool AnyChildren(this Document document)
 {
     return(MrCMSApplication.Get <ISession>()
            .QueryOver <Document>()
            .Where(doc => doc.Parent != null && doc.Parent.Id == document.Id)
            .Cacheable()
            .Any());
 }
예제 #11
0
        public static MvcHtmlString Honeypot(this HtmlHelper html)
        {
            var siteSettings = MrCMSApplication.Get <SiteSettings>();

            return(siteSettings.HasHoneyPot
                       ? MvcHtmlString.Create(siteSettings.GetHoneypot().ToString())
                       : MvcHtmlString.Empty);
        }
예제 #12
0
 public static decimal GetTaxRatePercentage(this TaxRate taxRate)
 {
     return(MrCMSApplication.Get <TaxSettings>().TaxesEnabled
         ? taxRate == null
             ? Decimal.Zero
             : taxRate.Percentage
         : Decimal.Zero);
 }
예제 #13
0
 public ProductSearchQuery()
 {
     Options           = new List <string>();
     Specifications    = new List <int>();
     Page              = 1;
     PageSize          = 10;
     ProductSearchView = MrCMSApplication.Get <IGetProductSearchView>().Get();
 }
예제 #14
0
        public ActionResult ProductReviews(ProductVariant productVariant, int reviewPage = 1, string q = "")
        {
            var reviewsPageSize = MrCMSApplication.Get <ProductReviewSettings>().PageSize;

            ViewData["reviews"] = _productReviewUIService.GetReviewsForVariant(productVariant, reviewPage, reviewsPageSize);

            return(PartialView(productVariant));
        }
        public static Currency Currency(this EcommerceSettings settings)
        {
            var session = MrCMSApplication.Get <ISession>();

            return(settings.CurrencyId > 0
                ? session.Get <Currency>(settings.CurrencyId)
                : session.QueryOver <Currency>().Take(1).Cacheable().SingleOrDefault());
        }
예제 #16
0
 public static int FormPostingsCount(this Webpage webpage)
 {
     return(MrCMSApplication.Get <ISession>()
            .QueryOver <FormPosting>()
            .Where(posting => posting.Webpage != null && posting.Webpage.Id == webpage.Id)
            .Cacheable()
            .RowCount());
 }
예제 #17
0
 public static BasicAmountType GetAmountType(this decimal value)
 {
     return(new BasicAmountType
     {
         value = value.ToString("0.00"),
         currencyID = MrCMSApplication.Get <PayPalExpressCheckoutSettings>().Currency
     });
 }
예제 #18
0
 public static int Downvotes(this ProductReview productReview)
 {
     return(productReview == null
         ? 0
         : MrCMSApplication.Get <ISession>()
            .QueryOver <HelpfulnessVote>()
            .Where(vote => vote.ProductReview.Id == productReview.Id && !vote.IsHelpful)
            .Cacheable()
            .RowCount());
 }
예제 #19
0
        public static IPagedList <TResult> Paged <TResult>(this IQueryable <TResult> queryable, int pageNumber,
                                                           int?pageSize = null)
            where TResult : SystemEntity
        {
            int size = pageSize ?? MrCMSApplication.Get <SiteSettings>().DefaultPageSize;

            IQueryable <TResult> cacheable = queryable.Cacheable();

            return(new PagedList <TResult>(cacheable, pageNumber, size));
        }
예제 #20
0
 public static int Upvotes(this Comment comment)
 {
     return(comment == null
         ? 0
         : MrCMSApplication.Get <ISession>()
            .QueryOver <Vote>()
            .Where(vote => vote.Comment.Id == comment.Id && vote.IsUpvote)
            .Cacheable()
            .RowCount());
 }
예제 #21
0
        public Query GetQuery()
        {
            if (String.IsNullOrWhiteSpace(SearchText) && String.IsNullOrWhiteSpace(OrderId) && PaymentStatus == null &&
                ShippingStatus == null && !DateFrom.HasValue && !DateTo.HasValue &&
                string.IsNullOrWhiteSpace(SalesChannel) && !OrderTotalFrom.HasValue && !OrderTotalTo.HasValue)
            {
                return(new MatchAllDocsQuery());
            }

            var booleanQuery = new BooleanQuery();

            if (!String.IsNullOrWhiteSpace(SearchText))
            {
                string fuzzySearchTerm = MakeFuzzy(SearchText);
                var    q = new MultiFieldQueryParser(Version.LUCENE_30,
                                                     new[]
                {
                    FieldDefinition.GetFieldName <OrderSearchOrderDateDefinition>(),
                    FieldDefinition.GetFieldName <OrderSearchEmaillDefinition>(),
                    FieldDefinition.GetFieldName <OrderSearchLastnamelDefinition>(),
                    FieldDefinition.GetFieldName <OrderSearchPaymentStatusDefinition>(),
                    FieldDefinition.GetFieldName <OrderSearchShippingStatusDefinition>(),
                    FieldDefinition.GetFieldName <OrderSearchTotalDefinition>()
                },
                                                     MrCMSApplication.Get <OrderSearchIndex>().GetAnalyser());
                Query query = q.Parse(fuzzySearchTerm);
                booleanQuery.Add(query, Occur.SHOULD);
            }
            if (DateFrom.HasValue || DateTo.HasValue)
            {
                booleanQuery.Add(GetDateQuery(), Occur.MUST);
            }
            if (!String.IsNullOrWhiteSpace(OrderId))
            {
                booleanQuery.Add(GetOrderIdQuery(), Occur.MUST);
            }
            if (PaymentStatus != null)
            {
                booleanQuery.Add(GetPaymentStatusQuery(), Occur.MUST);
            }
            if (ShippingStatus != null)
            {
                booleanQuery.Add(GetShippingStatusQuery(), Occur.MUST);
            }
            if (!string.IsNullOrWhiteSpace(SalesChannel))
            {
                booleanQuery.Add(GetSalesChannelQuery(), Occur.MUST);
            }
            if (OrderTotalFrom > 0 || OrderTotalTo.HasValue)
            {
                booleanQuery.Add(GetPriceRangeQuery(), Occur.MUST);
            }

            return(booleanQuery);
        }
예제 #22
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (CurrentRequestData.DatabaseIsInstalled)
     {
         if (!string.IsNullOrWhiteSpace(
                 filterContext.HttpContext.Request[MrCMSApplication.Get <SiteSettings>().HoneypotFieldName]))
         {
             filterContext.Result = new EmptyResult();
         }
     }
 }
예제 #23
0
        public static IPagedList <T> PagedChildren <T>(this Webpage webpage, QueryOver <T> query = null, int pageNum = 1,
                                                       int pageSize = 10) where T : Webpage
        {
            query = query ??
                    QueryOver.Of <T>()
                    .Where(a => a.Parent == webpage && a.Published)
                    .OrderBy(arg => arg.PublishOn)
                    .Desc;

            return(MrCMSApplication.Get <ISession>().Paged(query, pageNum, pageSize));
        }
예제 #24
0
파일: ACLRule.cs 프로젝트: yxb1987/MrCMS
        private bool CanAccessLogic(UserRole userRole, string operation, string typeName = null)
        {
            if (!MrCMSApplication.Get <ACLSettings>().ACLEnabled)
            {
                return(false);
            }
            var aclRoles = userRole.ACLRoles;
            var b        = GetKey(operation, typeName);

            return(aclRoles.Any(role => role.Name == b));
        }
        public MarketplaceWebServiceClient GetFeedsApiService()
        {
            var config = new MarketplaceWebServiceConfig()
            {
                ServiceURL = _amazonAppSettings.ApiEndpoint
            };

            return(new MarketplaceWebServiceClient(MrCMSApplication.Get <AmazonAppSettings>().AWSAccessKeyId,
                                                   MrCMSApplication.Get <AmazonAppSettings>().SecretKey, "MrCMS", MrCMSApplication.AssemblyVersion,
                                                   config));
        }
        private MarketplaceWebServiceOrdersClient GetOrdersApiService()
        {
            var config = new MarketplaceWebServiceOrdersConfig()
            {
                ServiceURL = _amazonAppSettings.OrdersApiEndpoint
            };

            return(new MarketplaceWebServiceOrdersClient("MrCMS", MrCMSApplication.AssemblyVersion, MrCMSApplication.Get <AmazonAppSettings>().AWSAccessKeyId,
                                                         MrCMSApplication.Get <AmazonAppSettings>().SecretKey,
                                                         config));
        }
예제 #27
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (controllerContext.IsChildAction)
            {
                return(base.BindModel(controllerContext, bindingContext));
            }
            var model = new ProductSearchQuery
            {
                Specifications =
                    (controllerContext.HttpContext.Request["Specifications"] ??
                     string.Empty).Split(new[] { '|' },
                                         StringSplitOptions.RemoveEmptyEntries)
                    .Select(s => Convert.ToInt32((string)s))
                    .ToList(),
                Options =
                    (controllerContext.HttpContext.Request["Options"] ?? string.Empty)
                    .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
                    .ToList(),
                PageSize = !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["PageSize"])
                    ? Convert.ToInt32(controllerContext.HttpContext.Request["PageSize"])
                    : MrCMSApplication.Get <EcommerceSettings>()
                           .ProductPerPageOptions.FirstOrDefault(),
                Page = !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["Page"])
                    ? Convert.ToInt32(controllerContext.HttpContext.Request["Page"])
                    : 1,
                CategoryId =
                    !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["CategoryId"])
                        ? Convert.ToInt32(controllerContext.HttpContext.Request["CategoryId"])
                        : (int?)null,
                PriceFrom =
                    !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["PriceFrom"])
                        ? Convert.ToDouble(controllerContext.HttpContext.Request["PriceFrom"])
                        : 0,
                PriceTo = !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["PriceTo"])
                    ? Convert.ToDouble(controllerContext.HttpContext.Request["PriceTo"])
                    : (double?)null,
                BrandId =
                    !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["BrandId"])
                        ? Convert.ToInt32(controllerContext.HttpContext.Request["BrandId"])
                        : (int?)null,
                SearchTerm = controllerContext.HttpContext.Request["SearchTerm"]
            };

            model.SortBy = !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["SortBy"])
                ? (ProductSearchSort)Convert.ToInt32(controllerContext.HttpContext.Request["SortBy"])
                : model.SortBy;

            model.ProductSearchView =
                !string.IsNullOrWhiteSpace(controllerContext.HttpContext.Request["ProductSearchView"])
                    ? (ProductSearchView)Convert.ToInt32(controllerContext.HttpContext.Request["ProductSearchView"])
                    : model.ProductSearchView;

            return(model);
        }
예제 #28
0
        public static void ConfigureAuth(this IAppBuilder app)
        {
            IStandardAuthConfigurationService standardAuthConfigurationService = MrCMSApplication.Get <IStandardAuthConfigurationService>();

            standardAuthConfigurationService.ConfigureAuth(app);
            if (CurrentRequestData.DatabaseIsInstalled)
            {
                IAuthConfigurationService authConfigurationService = MrCMSApplication.Get <IAuthConfigurationService>();
                authConfigurationService.ConfigureAuth(app);
            }
        }
 public static IEnumerable <GoogleBaseCategory> GetCategories()
 {
     SetTaxonomyData(MrCMSApplication.Get <GoogleBaseSettings>().GoogleBaseTaxonomyFeedUrl);
     return
         (RawCategories.Select(
              googleBaseCategory =>
              new GoogleBaseCategory()
     {
         Name = googleBaseCategory, Id = googleBaseCategory
     }).ToList());
 }
예제 #30
0
        public static IPagedList <TResult> Paged <TResult>(this IQueryOver <TResult, TResult> queryBase, int pageNumber,
                                                           int?pageSize = null)
            where TResult : SystemEntity
        {
            int size = pageSize ?? MrCMSApplication.Get <SiteSettings>().DefaultPageSize;
            IEnumerable <TResult> results = queryBase.Skip((pageNumber - 1) * size).Take(size).Cacheable().List();

            int rowCount = queryBase.Cacheable().RowCount();

            return(new StaticPagedList <TResult>(results, pageNumber, size, rowCount));
        }