Esempio n. 1
0
        protected override void OnLoad(EventArgs e)
        {
            Micajah.Common.Pages.MasterPage.InitializeSetupPage(this.Page);

            if (WebsiteProvider.GetWebsites().Count == 0)
            {
                List.EmptyDataText = string.Format(CultureInfo.CurrentCulture
                                                   , Resources.DatabaseServersControl_ErrorMessage_NoWebsite
                                                   , CustomUrlProvider.CreateApplicationAbsoluteUrl(ResourceProvider.WebsitesPageVirtualPath));
                List.ShowAddLink = EditForm.Visible = false;
            }

            base.OnLoad(e);
        }
Esempio n. 2
0
        public CreateFuneralHomeResponse CreateFuneralHome(FuneralHome fh, string UserName, WebsiteProvider wp, string password = null)
        {
            CreateFuneralHomeResponse cfhr    = new CreateFuneralHomeResponse();
            ApplicationUser           newUser = new ApplicationUser();

            newUser.UserName = fh.UserName;
            newUser.Name     = fh.Name;
            newUser.Email    = fh.Email;
            var result = UserManager.Create(newUser);

            if (result.Succeeded)
            {
                cfhr.CreateUserSuccess = true;
                var userManager   = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var currentUserId = db.Users.Where(u => u.UserName == fh.UserName).FirstOrDefault().Id;
                userManager.AddToRole(currentUserId, "FuneralHome");
                fh.UserId = currentUserId;
                if (password != null)
                {
                    userManager.AddPassword(currentUserId, password);
                }
                db.FuneralHomes.Add(fh);
                db.SaveChanges();
                Setting settings = new Setting()
                {
                    FuneralHomeId   = fh.Id,
                    WebsiteProvider = wp,
                    DisplayTutorial = true,
                    AzureVMSize     = "Standard_D4_v2"
                };
                fh.Setting         = settings;
                db.Entry(fh).State = EntityState.Modified;
                db.SaveChanges();
                cfhr.CreateFuneralHomeSuccess = true;
                Service service = new Service
                {
                    ServiceDate = DateTime.Now,
                    FuneralHome = fh,
                    IsSecured   = false,
                    Birthday    = DateTime.Now,
                    DeathDay    = DateTime.Now,
                    FirstName   = "Thomas",
                    LastName    = "Jefferson"
                };
                db.Entry(service).State = EntityState.Added;
                db.SaveChanges();
                cfhr.Success     = true;
                cfhr.FuneralHome = fh;
                return(cfhr);
            }
            else
            {
                cfhr.CreateUserSuccess = false;
                StringBuilder errors = new StringBuilder();
                foreach (var error in result.Errors)
                {
                    errors.Append(error);
                }
                cfhr.UserErrors = cfhr.UserErrors;
                cfhr.Success    = false;
                return(cfhr);
            }
        }
Esempio n. 3
0
        public override ApplicationPath GetApplicationPath(OrganizationServiceContext context, Entity entity)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (entity == null)
            {
                return(null);
            }

            if (entity.LogicalName == "adx_communityforumpost")
            {
                var thread = entity.GetRelatedEntity(context, "adx_communityforumthread_communityforumpost".ToRelationship());

                if (thread != null)
                {
                    return(GetForumPostApplicationPath(context, entity, thread));
                }
            }

            if (entity.LogicalName == "adx_blogpostcomment")
            {
                var post = entity.GetRelatedEntity(context, "adx_blogpost_blogpostcomment".ToRelationship());

                if (post != null)
                {
                    return(GetBlogPostCommentApplicationPath(context, entity, post));
                }
            }

            if (entity.LogicalName == "adx_shortcut")
            {
                return(GetShortcutApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_ideaforum")
            {
                return(GetIdeaForumApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_idea")
            {
                return(GetIdeaApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_issue")
            {
                return(GetIssueApplicationPath(context, entity));
            }

            if (entity.LogicalName == "incident")
            {
                return(GetIncidentApplicationPath(context, entity));
            }

            if (entity.LogicalName == "kbarticle")
            {
                return(GetKbArticleApplicationPath(context, entity));
            }

            if (entity.LogicalName == "knowledgearticle")
            {
                return(GetKnowledgeArticleApplicationPath(context, entity));
            }

            if (entity.LogicalName == "category")
            {
                return(GetCategoryApplicationPath(context, entity));
            }

            // We want new behaviour for adx_webpages -- paths for this entity will now have a trailing slash ('/').
            if (entity.LogicalName == "adx_webpage")
            {
                var path = base.GetApplicationPath(context, entity);

                // If the path is an external URL (it shouldn't be, but just in case), return the original path untouched.
                if (path.ExternalUrl != null)
                {
                    return(path);
                }

                // If the path does not already have a trailing slash (it shouldn't), append one.
                return(path.AppRelativePath.EndsWith("/")
                                        ? path
                                        : ApplicationPath.FromAppRelativePath("{0}/".FormatWith(path.AppRelativePath)));
            }

            // Support adx_webfiles with a parent adx_blogpost, instead of adx_webpage.
            if (entity.LogicalName == "adx_webfile" && entity.GetAttributeValue <EntityReference>("adx_blogpostid") != null)
            {
                var post = entity.GetRelatedEntity(context, "adx_blogpost_webfile".ToRelationship());

                if (post != null)
                {
                    var postPath       = GetApplicationPath(context, post);
                    var filePartialUrl = entity.GetAttributeValue <string>("adx_partialurl");

                    if (postPath != null && filePartialUrl != null)
                    {
                        return(ApplicationPath.FromAppRelativePath("{0}/{1}".FormatWith(postPath.AppRelativePath.TrimEnd('/'), filePartialUrl)));
                    }
                }
            }

            var lookup = new Dictionary <string, Tuple <string[], Relationship, string, string, bool> >
            {
                {
                    "adx_communityforumthread",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_communityforumthreadid" },
                        "adx_communityforum_communityforumthread".ToRelationship(),
                        "adx_communityforum",
                        null,
                        false)
                },
                {
                    "adx_communityforum",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_communityforum".ToRelationship(),
                        "adx_webpage",
                        "Forums",
                        false)
                },
                {
                    "adx_event",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_event".ToRelationship(),
                        "adx_webpage",
                        "Events",
                        false)
                },
                {
                    "adx_survey",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_survey".ToRelationship(),
                        "adx_webpage",
                        "Surveys",
                        false)
                },
                {
                    "adx_blog",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_blog".ToRelationship(),
                        "adx_webpage",
                        null,
                        true)
                },
                {
                    "adx_blogpost",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl", "adx_blogpostid" },
                        "adx_blog_blogpost".ToRelationship(),
                        "adx_blog",
                        null,
                        true)
                },
            };

            Tuple <string[], Relationship, string, string, bool> urlData;

            if (lookup.TryGetValue(entity.LogicalName, out urlData))
            {
                var partialUrlLogicalName = urlData.Item1.FirstOrDefault(logicalName =>
                {
                    var partialUrlValue = entity.GetAttributeValue(logicalName);

                    return(partialUrlValue != null && !string.IsNullOrWhiteSpace(partialUrlValue.ToString()));
                });

                if (partialUrlLogicalName == null)
                {
                    return(null);
                }

                var relationship     = urlData.Item2;
                var siteMarker       = urlData.Item4;
                var addTrailingSlash = urlData.Item5;

                var websiteRelativeUrl = GetApplicationPath(context, entity, partialUrlLogicalName, relationship, GetApplicationPath, siteMarker);

                if (websiteRelativeUrl != null)
                {
                    if (addTrailingSlash && websiteRelativeUrl.PartialPath != null && !websiteRelativeUrl.PartialPath.EndsWith("/"))
                    {
                        websiteRelativeUrl = ApplicationPath.FromPartialPath("{0}/".FormatWith(websiteRelativeUrl.PartialPath));
                    }

                    var website = WebsiteProvider.GetWebsite(context, entity);

                    var path = WebsitePathUtility.ToAbsolute(website, websiteRelativeUrl.PartialPath);

                    return(ApplicationPath.FromPartialPath(path));
                }
            }

            return(base.GetApplicationPath(context, entity));
        }