Click here to Skip to main content
12,243,173 members (22,110 online)
Click here to Skip to main content

Stats

43.7K views
2.5K downloads
23 bookmarked
Posted

Forums application using MVC4 and Entity Framework

, 15 Feb 2013 CPOL
I would like to share the application which is done in MVC4 using Entity Framework.
mvcForumapp
App_Start
bin
Content
css
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
minified
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
Models
mvcForumapp.csproj.user
mvcforums.edmx
obj
Debug
edmxResourcesToEmbed
mvcforums.csdl
mvcforums.msl
mvcforums.ssdl
Properties
Scripts
Views
Login
Logout
Question
Question_Answer
Register
Reply
Shared
Technology
Antlr3.Runtime.dll
EntityFramework.dll
Microsoft.Web.Infrastructure.dll
mvcForumapp.dll
Newtonsoft.Json.dll
System.Net.Http.dll
System.Net.Http.Formatting.dll
System.Net.Http.WebRequest.dll
System.Web.Http.dll
System.Web.Http.WebHost.dll
System.Web.Mvc.dll
System.Web.Optimization.dll
System.Web.Providers.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
WebGrease.dll
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Global.asax
mvcForumapp.csproj.user
mvcforums.edmx
mvcforums.csdl
mvcforums.msl
mvcforums.ssdl
mvcForumapp.dll
TempPE
mvcforums.Designer.cs.dll
video2.avi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace mvcForumapp.Controllers
{
    public class RegisterController : Controller
    {
        //
        // GET: /User/

        newForumDBEntities db = new newForumDBEntities();

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Register()
        {
            return View();
        }

        public ActionResult IsUserNameAvailable(string UserName)
        {
            var usrAvailable = db.tblUsers.Where(p => p.UserName == UserName).Select(img => img.UserName).FirstOrDefault();

            if (usrAvailable == null)
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            //string html = "<span style='color:Red;'> Username in use</span>";
            return Json("<span style='color:Red;'> Username in already in use</span>", JsonRequestBehavior.AllowGet);

        }

        [OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
        public JsonResult IsDisplayAvailable(string Displayname)
        {
            var usrAvailable = db.tblUsers.Where(p => p.DisplayName == Displayname).Select(img => img.DisplayName).FirstOrDefault();

            if (usrAvailable == null)
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            //string html = "<span style='color:Red;'> Username in use</span>";
            return Json("<span style='color:Red;'> Display name in already use</span>", JsonRequestBehavior.AllowGet);

        }

        [OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
        public JsonResult IsEmailAvailable(string Email)
        {
            var usrAvailable = db.tblUsers.Where(p => p.EmailID == Email).Select(img => img.EmailID).FirstOrDefault();

            if (usrAvailable == null)
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            //string html = "<span style='color:Red;'> Username in use</span>";
            return Json("<span style='color:Red;'> Emai in already in use</span>", JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public ActionResult Register(mvcForumapp.Models.Register user, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file == null)
                {
                    ModelState.AddModelError("File", "Please Upload Your file");
                }
                else if (file.ContentLength > 0)
                {
                    int MaxContentLength = 1024 * 1024 * 3; //3 MB
                    string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" };

                    if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                    {
                        ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));
                    }

                    else if (file.ContentLength > MaxContentLength)
                    {
                        ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
                    }
                    else
                    {
                        using (var db = new newForumDBEntities())
                        {
                            Byte[] imgByte = null;
                            HttpPostedFileBase File = file;
                            //Create byte Array with file len
                            imgByte = new Byte[File.ContentLength];
                            //force the control to load data in array
                            File.InputStream.Read(imgByte, 0, File.ContentLength);
                            var userdets = db.tblUsers.CreateObject();
                            userdets.UserName = user.Username;
                            userdets.DateJoined = DateTime.Now;
                            userdets.DisplayName = user.Displayname;
                            userdets.EmailID = user.Email;
                            userdets.Password = user.password;
                            userdets.Photo = imgByte;
                            //var encrppass = Encrypt(user.password, true);
                            //var userdets = db.tblUsers.CreateObject();
                            //userdets.EmailID = user.Email;
                            //userdets.password = encrppass;

                            db.tblUsers.AddObject(userdets);
                            db.SaveChanges();
                            return RedirectToAction("Index", "Technology");
                        }
                    }
                }

            }
            return View(user);
        }
    }
}

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)

Share

About the Author

demouser743
Software Developer
India India
I am Dorababu, working as a Software engineer. Web development in Asp.Net with C#, WinForms and MS sql server are the experience tools that I have had for the past 3 years. Yet to work on WCF, WPF, Silverlight and other latest ones.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 15 Feb 2013
Article Copyright 2013 by demouser743
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid