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());
 }
        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));
        }
Example #3
0
        /// <summary>
        /// Apply business logic here
        /// </summary>
        /// <param name="productsToImport"></param>
        /// <returns></returns>
        public Dictionary <string, List <string> > ValidateBusinessLogic(IEnumerable <ProductImportDataTransferObject> productsToImport)
        {
            var errors              = new Dictionary <string, List <string> >();
            var productRules        = MrCMSApplication.GetAll <IProductImportValidationRule>();
            var productVariantRules = MrCMSApplication.GetAll <IProductVariantImportValidationRule>();

            foreach (var product in productsToImport)
            {
                var productErrors = productRules.SelectMany(rule => rule.GetErrors(product)).ToList();
                if (productErrors.Any())
                {
                    errors.Add(product.UrlSegment, productErrors);
                }

                foreach (var variant in product.ProductVariants)
                {
                    var productVariantErrors = productVariantRules.SelectMany(rule => rule.GetErrors(variant)).ToList();
                    if (productVariantErrors.Any())
                    {
                        if (errors.All(x => x.Key != product.UrlSegment))
                        {
                            errors.Add(product.UrlSegment, productVariantErrors);
                        }
                        else
                        {
                            errors[product.UrlSegment].AddRange(productVariantErrors);
                        }
                    }
                }
            }

            return(errors);
        }
Example #4
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));
        }
Example #5
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());
        }
Example #6
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);
        }
Example #7
0
 public static void AddAppUIScripts(this HtmlHelper html)
 {
     foreach (var script in MrCMSApplication.GetAll <IAppScriptList>().SelectMany(appScriptList => appScriptList.UIScripts))
     {
         html.IncludeScript(script);
     }
 }
Example #8
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));
        }
Example #9
0
 public static void AddAppAdminStylesheets(this HtmlHelper html)
 {
     foreach (var script in MrCMSApplication.GetAll <IAppStylesheetList>().SelectMany(appScriptList => appScriptList.AdminStylesheets))
     {
         html.IncludeCss(script);
     }
 }
Example #10
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);
        }
Example #11
0
 public MrCMSErrorLog(IDictionary config)
 {
     if (CurrentRequestData.DatabaseIsInstalled)
     {
         _session = MrCMSApplication.Get <ISessionFactory>().OpenFilteredSession(CurrentRequestData.CurrentContext);
     }
 }
Example #12
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());
 }
Example #13
0
        public static MvcHtmlString Honeypot(this HtmlHelper html)
        {
            var siteSettings = MrCMSApplication.Get <SiteSettings>();

            return(siteSettings.HasHoneyPot
                       ? MvcHtmlString.Create(siteSettings.GetHoneypot().ToString())
                       : MvcHtmlString.Empty);
        }
Example #14
0
 public override string FormatErrorMessage(string name)
 {
     if (string.IsNullOrWhiteSpace(this.ErrorMessage))
     {
         return(null);
     }
     return(MrCMSApplication.Get <IStringResourceProvider>().GetValue(name + "is required", this.ErrorMessage));
 }
Example #15
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));
        }
Example #16
0
 public static BasicAmountType GetAmountType(this decimal value)
 {
     return(new BasicAmountType
     {
         value = value.ToString("0.00"),
         currencyID = MrCMSApplication.Get <PayPalExpressCheckoutSettings>().Currency
     });
 }
Example #17
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());
 }
        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());
        }
        public static IHtmlString ParseShortcodes(this HtmlHelper htmlHelper, string content)
        {
            var shortcodeParsers = MrCMSApplication.GetAll <IShortcodeParser>();

            content = shortcodeParsers.Aggregate(content, (current, shortcodeParser) => shortcodeParser.Parse(htmlHelper, current));

            return(new HtmlString(content));
        }
Example #20
0
 public static decimal GetTaxRatePercentage(this TaxRate taxRate)
 {
     return(MrCMSApplication.Get <TaxSettings>().TaxesEnabled
         ? taxRate == null
             ? Decimal.Zero
             : taxRate.Percentage
         : Decimal.Zero);
 }
Example #21
0
 public ProductSearchQuery()
 {
     Options           = new List <string>();
     Specifications    = new List <int>();
     Page              = 1;
     PageSize          = 10;
     ProductSearchView = MrCMSApplication.Get <IGetProductSearchView>().Get();
 }
Example #22
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));
        }
Example #23
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());
 }
Example #24
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());
 }
Example #25
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);
        }
Example #26
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);
        }
Example #27
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));
        }
Example #28
0
        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));
        }
Example #29
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));
        }
Example #30
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);
            }
        }