示例#1
0
        protected void PrepareViewModel(ViewModelBase model,
                                        string pageTitle, int currentItemId = 0, int objectFlags = 0)
        {
            model.PageTitle = pageTitle;

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.AddProperty("id", currentItemId);

            UserModel user = MembershipManagementService.User;

            if (user != null)
            {
                model.DisplayDateFormat = user.DateFormat;
                model.JQDateFormat      = user.DateFormat.ToLower().Replace("yyyy", "yy");
                dict.AddProperty("USERNAME", user.Name.Replace(".", " ").WordCapitalise());
            }
            else
            {
                dict.AddProperty("USERNAME", "");
            }

            var tempAreaName   = this.ControllerContext.RouteData.DataTokens["area"];
            var areaName       = (tempAreaName == null ? "" : tempAreaName.ToString() + ":");
            var controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

            // Object flags are:
            //      1   Requires Customer
            //      2   Requires Purchase
            //      4
            //      8
            //      16  Requires Product
            //      32  Requires no product
            model.Menu = MenuService.GetMenu(0,
                                             MembershipManagementService.IsLoggedIn,
                                             MembershipManagementService.FindUserRoles(),
                                             objectFlags,
                                             areaName + controllerName,
                                             dict);

            // Get the company list
            model.AvailableCompanies = CompanyService.FindCompaniesListItemModel();

            int selectedCompanyId = MembershipManagementService.GetProperty(MMSProperty.CurrentCompany, -1);

            if (selectedCompanyId == -1)
            {
                // No company selected, so use the first in the list
                if (model.AvailableCompanies.Count() > 0)
                {
                    selectedCompanyId = Convert.ToInt32(model.AvailableCompanies.First().Id);
                }
            }
            if (selectedCompanyId > 0)
            {
                model.CurrentCompany = CompanyService.FindCompanyModel(selectedCompanyId);
                model.MarginLogo     = model.CurrentCompany.MarginLogo;
            }
        }