Click here to Skip to main content
15,892,697 members
Articles / Web Development / HTML

sBlog.Net - A Minimalistic Blog Engine - Using ASP.NET MVC 3

Rate me:
Please Sign up or sign in to vote.
4.94/5 (55 votes)
16 Aug 2013CPOL51 min read 197.8K   6.4K   182  
sBlog.Net is a minimalistic blog engine created using the ASP.NET MVC 3 framework.
#region Disclaimer/License Info

/* *********************************************** */

// sBlog.Net

// sBlog.Net is a minimalistic blog engine software.

// Homepage: http://sblogproject.net
// Github: http://github.com/karthik25/sBlog.Net

// This project is licensed under the BSD license.  
// See the License.txt file for more information.

/* *********************************************** */

#endregion
using System.Web.Mvc;
using sBlog.Net.Domain.Interfaces;
using sBlog.Net.Domain.Concrete;
using sBlog.Net.Areas.Setup.Models;
using sBlog.Net.Areas.Setup.Services;

namespace sBlog.Net.Areas.Setup.Controllers
{
    public class InitController : Controller
    {
        private readonly IPathMapper _pathMapper;
        private readonly DbContext _dbContext;

        public InitController(IPathMapper pathMapper)
        {
            _pathMapper = pathMapper;
            _dbContext = new DbContext();
        }

        public ActionResult Index()
        {
            var setupStatusViewModel = GetSetupStatusViewModel();

            if (setupStatusViewModel == null)
            {
                return RedirectToRoute("InitializeDatabase");
            }

            if (setupStatusViewModel.InstallationComplete)
            {
                return RedirectToAction("Index", "Home", new { area = "" });
            }
            return View(setupStatusViewModel);
        }

        [HttpPost]
        public ActionResult Index(SetupStatusViewModel setupStatusViewModel)
        {
            if (ModelState.IsValid && _dbContext.IsCredentialsValid(setupStatusViewModel.ConnectionString))
            {
                return RedirectToRoute("SetupPage2");
            }

            var setupModel = GetSetupStatusViewModel();
            ModelState.AddModelError("ConnectionString", "Connection string entered does not match");

            return View(setupModel);
        }

        private SetupStatusViewModel GetSetupStatusViewModel()
        {
            SetupStatusViewModel model = null;
            try
            {
                var status = _dbContext.IsConnectionStringValid();
                var uploadStatus = UploadFolderVerifier.CanSaveOrDeleteFiles(_pathMapper);
                model = new SetupStatusViewModel
                    {
                        IsConnectionStringValid = status.SetupValid,
                        ConnectionStatusClass = status.CssClass,
                        Message = status.Message,
                        IsUploadsFolderValid = uploadStatus,
                        UploadsFolderStatusClass = uploadStatus ? "confirm" : "error",
                        InstallationComplete = _dbContext.IsInstallationComplete(),
                        UploadsMessage = uploadStatus
                                             ? "The uploads directory is writeable."
                                             : "The uploads directory is not writeable."
                    };
            }
            catch
            {
                
            }
            return model;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Just another passionate software developer!

Some of the contributions to the open source world - a blog engine written in MVC 4 - sBlog.Net. Check it out here. For the codeproject article regarding sBlog.Net click here!

(Figuring out this section!)

Comments and Discussions