Example #1
0
        private Site CreateSite(out ValidationStateDictionary validationState)
        {
            Site site = this.siteService.GetSite();

            if (site != null)
            {
                //throw new InvalidOperationException("A site has already been set up.  Please contact the administrator to make changes.");
            }

            Language language = new Language {
                Name = "en", DisplayName = "English"
            };

            languageService.AddLanguage(language);

            Site siteInput = new Site
            {
                Name                = "Oxite Site",
                DisplayName         = "My Oxite Site",
                Description         = "An Oxite based web site.",
                FavIconUrl          = "/Content/icons/flame.ico",
                LanguageDefault     = "en",
                PageTitleSeparator  = "-",
                GravatarDefault     = "http://mschnlnine.vo.llnwd.net/d1/oxite/gravatar.jpg",
                SkinsPath           = "/Skins",
                SkinsScriptsPath    = "/Scripts",
                SkinsStylesPath     = "/Styles",
                Skin                = "Default",
                AdminSkin           = "Admin",
                RouteUrlPrefix      = string.Empty,
                PluginsPath         = "/Plugins",
                CommentStateDefault = "PendingApproval",
                Host                = new Uri("http://localhost:30913"),
                TimeZoneOffset      = -8,
                PostEditTimeout     = 24,
                IncludeOpenSearch   = true,
                AuthorAutoSubscribe = true
            };

            siteService.AddSite(siteInput, out validationState, out site);

            userService.EnsureAnonymousUser();

            return(site);
        }
Example #2
0
        public IHttpActionResult Post([FromBody] SiteDTO siteDTO)
        {
            try
            {
                if (siteDTO == null)
                {
                    return(BadRequest("Argument Null"));
                }

                _siteService.AddSite(siteDTO);

                return(Ok());
            }
            catch (PlatformModuleException ex)
            {
                //Write Log Here
                return(BadRequest(ex.Message));
            }
        }
Example #3
0
        public ActionResult <GenericValidator> AddSite([FromBody] SiteModel site)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(site.SiteId))
                {
                    gVal.Code    = -1;
                    gVal.Message = "Please provide Site's enrolmentId.";
                    return(gVal);
                }
                if (string.IsNullOrEmpty(site.Name))
                {
                    gVal.Code    = -1;
                    gVal.Message = "Please provide Site's Name.";
                    return(gVal);
                }
                var status = _siteService.AddSite(site);
                if (status < 1)
                {
                    gVal.Code    = -1;
                    gVal.Message = status == -3? "Site record already exists" : "An unknown error was encountered. Please try again.";
                    return(gVal);
                }

                gVal.Code    = status;
                gVal.Message = "Site information was successfully Added";
                return(gVal);
            }
            catch (Exception ex)
            {
                gVal.Code    = -1;
                gVal.Message = ex.Message != null? ex.Message : ex.InnerException != null? ex.InnerException.Message : "An unknown error was encountered. Please try again.";
                return(gVal);
            }
        }
Example #4
0
        public virtual object SaveItem(Site siteInput, User userInput, FormCollection form)
        {
            ValidationStateDictionary validationState;

            if (siteInput.ID == Guid.Empty && userInput != null)
            {
                //TODO: (erikpo) This seems lame, but I need to do validation ahead of time.  Fix this.
                IUnityContainer   container     = (IUnityContainer)HttpContext.Application["container"];
                IValidator <Site> siteValidator = container.Resolve <IValidator <Site> >();
                IValidator <User> userValidator = container.Resolve <IValidator <User> >();

                validationState = new ValidationStateDictionary();

                validationState.Add(typeof(Site), siteValidator.Validate(siteInput));
                validationState.Add(typeof(User), userValidator.Validate(userInput));

                if (string.IsNullOrEmpty(form["userEmail"]))
                {
                    validationState[typeof(User)].Errors.Add("Email", form["userEmail"], "You must specify an Admin email address.");
                }

                if (string.IsNullOrEmpty(form["userPassword"]))
                {
                    validationState[typeof(User)].Errors.Add("Password", form["userPassword"], "You must specify an Admin password.");
                }

                if (string.IsNullOrEmpty(form["userPasswordConfirm"]))
                {
                    validationState[typeof(User)].Errors.Add("PasswordConfirm", form["userPasswordConfirm"], "You must confirm the Admin password.");
                }

                if (validationState.IsValid && form["userPassword"] != form["userPasswordConfirm"])
                {
                    validationState[typeof(User)].Errors.Add("PasswordMismatch", form["userPasswordConfirm"], "Admin passwords do not match.");
                }

                if (validationState.IsValid)
                {
                    Site site;

                    siteService.AddSite(siteInput, out validationState, out site);

                    Language language = new Language {
                        Name = "en", DisplayName = "English"
                    };
                    languageService.AddLanguage(language);

                    userService.EnsureAnonymousUser(language);

                    User user;

                    userInput.Status          = (byte)EntityState.Normal;
                    userInput.LanguageDefault = language;

                    userService.AddUser(userInput, out validationState, out user);

                    Area area = new Area
                    {
                        CommentingDisabled = false,
                        Name        = "Blog",
                        DisplayName = site.DisplayName,
                        Description = site.Description
                    };

                    areaService.AddArea(area, site, out validationState, out area);
                }
            }
            else
            {
                siteService.EditSite(siteInput, out validationState);
            }

            if (!validationState.IsValid)
            {
                ModelState.AddModelErrors(validationState);

                return(Item());
            }

            OxiteApplication.Load(ControllerContext.HttpContext);

            return(Redirect(Url.AppPath(Url.ManageSite())));
        }
Example #5
0
        public virtual object SaveItem(Site siteInput, UserInputAdd userInput)
        {
            ValidationStateDictionary validationState;

            if (siteInput.ID == Guid.Empty && userInput != null)
            {
                //TODO: (erikpo) This is lame.  Add a SiteInput class and a SiteInputValidator class and move the following validation code into it.
                IUnityContainer   container     = (IUnityContainer)HttpContext.Application["container"];
                IValidator <Site> siteValidator = container.Resolve <IValidator <Site> >();

                validationState = new ValidationStateDictionary();

                validationState.Add(typeof(Site), siteValidator.Validate(siteInput));

                if (validationState.IsValid)
                {
                    Site site;

                    siteService.AddSite(siteInput, out validationState, out site);

                    Language language = new Language {
                        Name = "en", DisplayName = "English"
                    };
                    languageService.AddLanguage(language);

                    userService.EnsureAnonymousUser();

                    //UserAuthenticated user;

                    //userInput.Status = (byte)EntityState.Normal;
                    //userInput.LanguageDefault = language;

                    //userService.AddUser(userInput, out validationState, out user);

                    if (validationState.IsValid)
                    {
                        //Blog blog = new Blog
                        //{
                        //    CommentingDisabled = false,
                        //    Name = "Blog",
                        //    DisplayName = site.DisplayName,
                        //    Description = site.Description
                        //};

                        //blogService.AddBlog(blog, site, out validationState, out blog);
                    }
                }
            }
            else
            {
                siteService.EditSite(siteInput, out validationState);
            }

            if (!validationState.IsValid)
            {
                ModelState.AddModelErrors(validationState);

                return(Item());
            }

            OxiteApplication.Load(ControllerContext.HttpContext);

            return(Redirect(Url.AppPath(Url.ManageSite())));
        }
Example #6
0
 public ActionResult Add(SiteViewModel newSite)
 {
     _siteService.AddSite(_mapper.Map <SiteViewModel, SiteDTO>(newSite));
     return(RedirectToAction("Index"));
 }
Example #7
0
 public async Task <IActionResult> AddSite(AddSiteDto site)
 {
     return(SetResponse(await _siteService.AddSite(site.SiteName, site.LocationId)));
 }