Пример #1
0
        public ActionResult DeleteSharePointItem(EntityReference regarding, string id)
        {
            int itemId;

            int.TryParse(id, out itemId);
            string portalName          = null;
            var    portalContext       = PortalCrmConfigurationManager.CreatePortalContext();
            var    languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code");

            if (!string.IsNullOrWhiteSpace(languageCodeSetting))
            {
                int languageCode;
                if (int.TryParse(languageCodeSetting, out languageCode))
                {
                    portalName = languageCode.ToString(CultureInfo.InvariantCulture);
                }
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName);
            var dataAdapter             = new SharePointDataAdapter(dataAdapterDependencies);

            var result = dataAdapter.DeleteItem(regarding, itemId);

            if (!result.PermissionsExist)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Entity Permissions have not been defined. Your request could not be completed."));
            }

            if (!result.CanDelete)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to delete this record."));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }
Пример #2
0
        public ActionResult GetSharePointData(EntityReference regarding, string sortExpression, int page, int pageSize = DefaultPageSize, string pagingInfo = null, string folderPath = null)
        {
            string portalName          = null;
            var    portalContext       = PortalCrmConfigurationManager.CreatePortalContext();
            var    languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code");

            if (!string.IsNullOrWhiteSpace(languageCodeSetting))
            {
                int languageCode;
                if (int.TryParse(languageCodeSetting, out languageCode))
                {
                    portalName = languageCode.ToString(CultureInfo.InvariantCulture);
                }
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName);
            var dataAdapter             = new SharePointDataAdapter(dataAdapterDependencies);
            var data = dataAdapter.GetFoldersAndFiles(regarding, sortExpression, page, pageSize, pagingInfo, folderPath);

            var json = Json(new
            {
                data.SharePointItems,
                PageSize   = pageSize,
                PageNumber = page,
                data.PagingInfo,
                data.TotalCount,
                data.AccessDenied
            });

            return(json);
        }
Пример #3
0
        public ActionResult DeleteSharePointItem(EntityReference regarding, string id)
        {
            int itemId;

            int.TryParse(id, out itemId);
            string portalName          = null;
            var    portalContext       = PortalCrmConfigurationManager.CreatePortalContext();
            var    languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code");

            if (!string.IsNullOrWhiteSpace(languageCodeSetting))
            {
                int languageCode;
                if (int.TryParse(languageCodeSetting, out languageCode))
                {
                    portalName = languageCode.ToString(CultureInfo.InvariantCulture);
                }
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName);
            var dataAdapter             = new SharePointDataAdapter(dataAdapterDependencies);

            var result = dataAdapter.DeleteItem(regarding, itemId);

            if (!result.PermissionsExist)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("Entity_Permissions_Have_Not_Been_Defined_Message")));
            }

            if (!result.CanDelete)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, string.Format(ResourceManager.GetString("No_Entity_Permissions"), "delete this record")));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }
        private void FormViewInserted(object sender, CrmEntityFormViewInsertedEventArgs args)
        {
            if (FileUpload == null || !FileUpload.HasFiles || !args.EntityId.HasValue)
            {
                return;
            }

            var regarding = new EntityReference(Metadata.TargetEntityName, args.EntityId.Value);

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies();
            var dataAdapter             = new SharePointDataAdapter(dataAdapterDependencies);

            dataAdapter.AddFiles(regarding, FileUpload.PostedFiles.Select(file => new HttpPostedFileWrapper(file) as HttpPostedFileBase).ToList());
        }
Пример #5
0
        public ActionResult AddSharePointFiles(string regardingEntityLogicalName, string regardingEntityId, IList <HttpPostedFileBase> files, bool overwrite, string folderPath = null)
        {
            Guid regardingId;

            Guid.TryParse(regardingEntityId, out regardingId);
            var    regarding           = new EntityReference(regardingEntityLogicalName, regardingId);
            string portalName          = null;
            var    portalContext       = PortalCrmConfigurationManager.CreatePortalContext();
            var    languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code");

            if (!string.IsNullOrWhiteSpace(languageCodeSetting))
            {
                int languageCode;
                if (int.TryParse(languageCodeSetting, out languageCode))
                {
                    portalName = languageCode.ToString(CultureInfo.InvariantCulture);
                }
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName);
            var dataAdapter             = new SharePointDataAdapter(dataAdapterDependencies);
            var result = dataAdapter.AddFiles(regarding, files, overwrite, folderPath);

            if (!result.PermissionsExist)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Entity Permissions have not been defined. Your request could not be completed."));
            }

            if (!result.CanCreate)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to create SharePoint files."));
            }

            if (!result.CanAppendTo)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to append to record."));
            }

            if (!result.CanAppend)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to append SharePoint files."));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }