Esempio n. 1
0
        protected void OnItemSaved(object sender, EntityFormSavedEventArgs e)
        {
            SalesHub hub      = new SalesHub();
            string   url      = Request.Url.OriginalString;
            string   userId   = Portal.User.Id.ToString();
            string   fullName = Portal.User.Attributes["fullname"].ToString();

            hub.UserHasSaved(url, userId, fullName);
        }
Esempio n. 2
0
 public IHttpActionResult DeletePage(string connId)
 {
     try
     {
         _repoWebPage.DeletePage(connId);
         SalesHub hub = new SalesHub();
         return(Ok());
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Esempio n. 3
0
 public IHttpActionResult StoreNewPages(CurrentlyUsedWebPage data)
 {
     try
     {
         _repoWebPage.InsertPage(data);
         SalesHub hub = new SalesHub();
         hub.Update(data, 1);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Esempio n. 4
0
 public IHttpActionResult UpdatePage(int id, string connId, string url)
 {
     try
     {
         _repoWebPage.UpdatePage(id, connId);
         SalesHub hub = new SalesHub();
         hub.Update(new CurrentlyUsedWebPage
         {
             Id           = id,
             ConnectionId = new Guid(connId),
             Url          = url
         }, 2);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Esempio n. 5
0
        public ActionResult Delete(EntityReference entityReference)
        {
            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 serviceContext           = dataAdapterDependencies.GetServiceContext();
            var entityPermissionProvider = new CrmEntityPermissionProvider();

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

            var entityMetadata = serviceContext.GetEntityMetadata(entityReference.LogicalName, EntityFilters.All);
            var primaryKeyName = entityMetadata.PrimaryIdAttribute;
            var entity         =
                serviceContext.CreateQuery(entityReference.LogicalName)
                .First(e => e.GetAttributeValue <Guid>(primaryKeyName) == entityReference.Id);
            var test = entityPermissionProvider.TryAssert(serviceContext, CrmEntityPermissionRight.Delete, entity);

            if (test)
            {
                try
                {
                    serviceContext.DeleteObject(entity);
                    serviceContext.SaveChanges();

                    SalesHub hub = new SalesHub();
                    string   url = Request.Url.OriginalString;
                }

                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("The object you tried to delete is associated with another object and cannot be deleted."))
                    {
                        throw new InvalidOperationException("Record cannot be deleted. It is already used in transactions.");
                    }
                    else
                    {
                        throw new InvalidOperationException(ex.InnerException.Message.ToString());
                    }
                }
                //string userId = Portal.User.Id.ToString();
                //string fullName = Portal.User.Attributes["fullname"].ToString();
                //hub.UserHasSaved(url, userId, fullName);
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to delete this record."));
            }


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