Ejemplo n.º 1
0
        private int InitCatalogAdmin(TreeNode parentNode, string parent)
        {
            DataSet ds  = new DataSet();
            int     ret = CatalogAdmin.GetCatalogNodes(ref ds, parent);

            if (0 == ret)
            {
                return(0);
            }

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TreeNode node = new TreeNode();
                node.Text = dr["ctlname"].ToString();
                node.Name = dr["ctlID"].ToString();
                string strChildID = dr["ctlID"].ToString();
                if (null == parentNode || null == parent)
                {
                    InitCatalogAdmin(node, strChildID);
                    treeView1.Nodes.Add(node);
                }
                else
                {
                    InitCatalogAdmin(node, strChildID);
                    parentNode.Nodes.Add(node);
                }
            }
            return(1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the catalog dto, checks permissions and caches results.
        /// </summary>
        /// <param name="siteGuid">The site GUID.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        public static CatalogDto GetCatalogDto(Guid siteGuid, CatalogResponseGroup responseGroup)
        {
            /*
             * // Checks roles first
             * if (!SecurityManager.CheckPermission(new string[] { CatalogRoles.CatalogAdminRole, CatalogRoles.CatalogManagerRole, CatalogRoles.CatalogViewerRole }))
             *  return new CatalogDto();
             * */

            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalogs", responseGroup != null ? responseGroup.CacheKey : "", siteGuid.ToString());

            CatalogDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CatalogDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                CatalogAdmin catalog = new CatalogAdmin();
                catalog.Load(siteGuid);
                dto = catalog.CurrentDto;

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout);
            }

            // Continue with security checks and other operations

            /*
             * foreach (CatalogDto.CatalogRow row in dto.Catalog.Rows)
             * {
             *
             * // Check Security
             * IDataReader reader = DataHelper.CreateDataReader(dto.CatalogSecurity, String.Format("CatalogId = -1 or CatalogId = {0}", row.CatalogId));
             * PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader));
             * if (!PermissionManager.CheckPermission(SecurityScope.Catalog.ToString(), Permission.Read, recordSet))
             * {
             * row.Delete();
             * continue;
             * }
             *
             * }
             * */

            //dto.AcceptChanges();

            return(dto);
        }
Ejemplo n.º 3
0
        private int LoadCatalogAdmin()
        {
            List <CatalogAdmin> lstCatalogAdmins = new List <CatalogAdmin>();
            int ret = CatalogAdmin.GetFamilyNodes(ref lstCatalogAdmins);

            treeView1.Nodes.Clear();

            foreach (CatalogAdmin catalogAdmin in lstCatalogAdmins)
            {
                TreeNode a = treeView1.Nodes.Add(catalogAdmin.CatalogParent);

                AddChildTreeNode(ref a, catalogAdmin.GetListChildNode());
            }
            return(1);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the catalog.
        /// </summary>
        /// <param name="dto">The dto.</param>
        public static void SaveCatalog(CatalogDto dto)
        {
            /*
             * // Checks roles first
             * if (!ProfileConfiguration.Instance.EnablePermissions)
             * {
             *  if (!SecurityManager.CheckPermission(new string[] { CatalogRoles.CatalogAdminRole, CatalogRoles.CatalogAdminRole }))
             *      return;
             * }
             * */

            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("CatalogDto can not be null"));
            }

            //TODO: check concurrency when updating the records

            //TODO: need to check security roles here,
            // The procedure will be following:
            // 1. Retrieve the record from the database for each category that is about to be updated
            // 2. Check Write permissions (if failed generate the error and exit)
            // 3. Otherwise proceed to update
            // Continue with security checks and other operations

            /*
             * foreach (CatalogDto.CatalogRow row in dto.Catalog.Rows)
             * {
             *  // Check Security
             *  IDataReader reader = DataHelper.CreateDataReader(dto.CatalogSecurity, String.Format("CatalogId = -1 or CatalogId = {0}", row.CatalogId));
             *  PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader));
             *  if (!PermissionManager.CheckPermission(CatalogScope.Catalog, Permission.Read, recordSet))
             *  {
             *      row.Delete();
             *      continue;
             *  }
             * }
             * */

            CatalogAdmin admin = new CatalogAdmin(dto);

            EventContext.Instance.RaiseCatalogUpdatingEvent(dto, new CatalogEventArgs("updating"));
            admin.Save();
            EventContext.Instance.RaiseCatalogUpdatedEvent(dto, new CatalogEventArgs("updated"));
        }
        public ActionResult Create(CatalogAdmin catalogAdmin)
        {
            if (Session["userId"] != null)
            {
                try
                {
                    if (db.Users.Find(Session["userId"]).Status == Status.admin)
                    {
                        Catalog catalog     = new Catalog();
                        string  sliceOfPath = "/Content/Images/ImageCategory/";
                        if (catalogAdmin.File.ContentLength > 0)
                        {
                            string filename = Path.GetFileName(catalogAdmin.File.FileName);
                            string filepath = Path.Combine(Server.MapPath("~/Content/Images/ImageCategory"), filename);
                            catalogAdmin.File.SaveAs(filepath);
                        }
                        catalog.Name      = catalogAdmin.Name;
                        catalog.ImagePath = sliceOfPath + catalogAdmin.File.FileName;

                        db.Catalogs.Add(catalog);
                        db.SaveChanges();

                        ViewBag.Products       = db.Products;
                        ViewBag.Catalogs       = db.Catalogs;
                        ViewBag.SubCatalogs    = db.SubCatalogs;
                        ViewBag.SubSubCatalogs = db.SubSubCatalogs;
                        return(View("~/Areas/Admin/Views/Home/Admin.cshtml"));
                    }
                    return(HttpNotFound());
                }
                catch (Exception e)
                {
                    ViewBag.Products       = db.Products;
                    ViewBag.Catalogs       = db.Catalogs;
                    ViewBag.SubCatalogs    = db.SubCatalogs;
                    ViewBag.SubSubCatalogs = db.SubSubCatalogs;
                    return(View("~/Areas/Admin/Views/Home/Admin.cshtml"));
                }
            }
            return(HttpNotFound());
        }