Программирование Баз данных

Автор работы: Пользователь скрыл имя, 09 Июня 2014 в 02:25, курсовая работа

Описание работы

Разработать систему публикации постов. Посты загружают зарегистрированные пользователи. При добавлении поста, пользователь может добавить к нему теги, возможность добавлять комментарии, есть только у зарегистрированных пользователей, также есть личный кабинет пользователя, в котором он может сменить пароль и загрузить аватар. Также пользователь может просмотреть последние добавленные посты других пользователей. Реализован поиск постов по тегам.

Содержание работы

ВВЕДЕНИЕ………………………………………………………………..…………………4
1. ОПИСАНИЕ ИСПОЛЬЗОВАННЫХ ТЕХНОЛОГИЙ ПРИ ПРОЕКТИРОВАНИИ……………………………………………………………...…….5
1.1 Архитектура модель-представление-контроллер……………………………..…….5
1.2 ASP.NET MVC Framework……………………………..…………………………….6
2. АНАЛИЗ ЗАДАЧИ……………………………………………………………………....9
3. ПРОЕКТИРОВАНИЕ БАЗЫ ДАННЫХ……………………………………….……..10
3.1 Структура таблиц…………………………………………………………………….10
3.2 Диаграмма отношений базы данных……………………………………………….12
4. АНАЛИЗ ЗАДАЧИ…………………………………………………………………......13
4.1 Структура сайта………………………………………………………………………13
4.2 Главная страница……………………………………………………………………13
4.3 Регистрация…………………………………………………………………….……..14
4.4 Авторизация…………………………………………………………………………..14
4.5 Страница добавления поста…………………………………………………………15
4.6 Страница просмотра поста…………………………………………………………..16
4.7 Страница просмотра постов по определенному тегу……………………………..16
5. ОСОБЕННОСТИ РЕАЛИЗАЦИИ……………………………………….…………….17
6. РЕАЛИЗАЦИЯ ФУНКЦИОНАЛЬНЫХ ВОЗМОЖНОСТЕЙ…………………….…18
6.1 Модели………………………………………………………………………………..18
6.2 Контроллеры…………………………………………………………………………20
ЗАКЛЮЧЕНИЕ………………………………………………………………………………21
БИБЛИОГРАФИЧЕСКИЙ СПИСОК….…………………………………………………...22
ПРИЛОЖЕНИЕ………………………………………………………………………………23
1. PostController.cs………………………………………………………………………23
2. UsetController.cs………………………………………………….......................……29
3. CustomMembershipProvider.cs………………………………....................................31
4. Классы для связи с базой данных………………………............................………...37

Файлы: 1 файл

kursovik_pvbd.docx

— 724.48 Кб (Скачать файл)

                {

                    return null;

                }

            }

            return null;

        }

 

        public MembershipUser UpdatePassword(string userName, string oldPassword, string newPassword)

        {

            MembershipUser membershipUser = GetUser(userName, false);

 

            if (membershipUser != null)

            {

                try

                {

                    using (DbProvider _db = new DbProvider())

                    {

                        User user = _db.Users.FirstOrDefault(u => u.UserName == userName);

 

                        if (Crypto.VerifyHashedPassword(user.UserPassword, oldPassword))

                        {

                            user.UserPassword = Crypto.HashPassword(newPassword);

                            user.UserRegDate = DateTime.Now;

 

 

                            _db.SaveChanges();

                        }

                        membershipUser = GetUser(userName, false);

 

                        return membershipUser;

                    }

                }

                catch

                {

                    return null;

                }

            }

            return null;

        }

 

 

        public MembershipUser UpdateAvatar(string userName, string userAvatarPath)

        {

            MembershipUser membershipUser = GetUser(userName, false);

 

            if (membershipUser != null)

            {

                try

                {

                    using (DbProvider _db = new DbProvider())

                    {

                        User user = _db.Users.FirstOrDefault(u => u.UserName == userName);

 

                        user.UserAvatarPath = userAvatarPath;

 

                        _db.SaveChanges();

                      

                        membershipUser = GetUser(userName, false);

 

                        return membershipUser;

                    }

                }

                catch

                {

                    return null;

                }

            }

            return null;

        }

 

 

        public int GetUserIdByName(string userName)

        {

            MembershipUser membershipUser = GetUser(userName, false);

 

            if (membershipUser != null)

            {

                try

                {

                    using (DbProvider _db = new DbProvider())

                    {

                        User user = _db.Users.FirstOrDefault(u => u.UserName == userName);

 

                        int UserID = user.UserID;

                        membershipUser = GetUser(userName, false);

 

                        return UserID;

                    }

                }

                catch

                {

                    return -1;

                }

            }

            return -1;

        }

 

        public override string ApplicationName

        {

            get

            {

                throw new NotImplementedException();

            }

            set

            {

                throw new NotImplementedException();

            }

        }

 

        public override bool ChangePassword(string username, string oldPassword, string newPassword)

        {

            throw new NotImplementedException();

        }

 

        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)

        {

            throw new NotImplementedException();

        }

 

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)

        {

            throw new NotImplementedException();

        }

 

        public override bool DeleteUser(string username, bool deleteAllRelatedData)

        {

            throw new NotImplementedException();

        }

 

        public override bool EnablePasswordReset

        {

            get { throw new NotImplementedException(); }

        }

        public override bool EnablePasswordRetrieval

        {

            get { throw new NotImplementedException(); }

        }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)

        {

            throw new NotImplementedException();

        }

        public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)

        {

            throw new NotImplementedException();

        }

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)

        {

            throw new NotImplementedException();

        }

        public override int GetNumberOfUsersOnline()

        {

            throw new NotImplementedException();

        }

        public override string GetPassword(string username, string answer)

        {

            throw new NotImplementedException();

        }

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)

        {

            throw new NotImplementedException();

        }

        public override string GetUserNameByEmail(string email)

        {

            throw new NotImplementedException();

        }

        public override int MaxInvalidPasswordAttempts

        {

            get { throw new NotImplementedException(); }

        }

        public override int MinRequiredNonAlphanumericCharacters

        {

            get { throw new NotImplementedException(); }

        }

        public override int MinRequiredPasswordLength

        {

            get { throw new NotImplementedException(); }

        }

        public override int PasswordAttemptWindow

        {

            get { throw new NotImplementedException(); }

        }

        public override MembershipPasswordFormat PasswordFormat

        {

            get { throw new NotImplementedException(); }

        }

        public override string PasswordStrengthRegularExpression

        {

            get { throw new NotImplementedException(); }

        }

        public override bool RequiresQuestionAndAnswer

        {

            get { throw new NotImplementedException(); }

        }

        public override bool RequiresUniqueEmail

        {

            get { throw new NotImplementedException(); }

        }

        public override string ResetPassword(string username, string answer)

        {

            throw new NotImplementedException();

        }

        public override bool UnlockUser(string userName)

        {

            throw new NotImplementedException();

        }

        public override void UpdateUser(MembershipUser user)

        {

            throw new NotImplementedException();

        }

    }

}

  1. Классы для связи с базой данных

DbProvider.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.ComponentModel.DataAnnotations;

using System.Data.Entity;

using Twitt.Models;

 

namespace Twitt.Providers

{

    public class DbProvider : DbContext

    {

        public DbSet<User> Users { get; set; }

 

        public DbSet<Role> Roles { get; set; }

 

        public DbSet<Post> Posts { get; set; }

 

        public DbSet<PostTag> PostTags { get; set; }

 

        public DbSet<Tag> Tags { get; set; }

 

        public DbSet<Comment> Comments { get; set; }

    }

}

 

Comment.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace Twitt.Models

{

    public class Comment

    {

        public virtual int CommentID { get; set; }

 

        public virtual string CommentText { get; set; }

 

        public virtual int UserID { get; set; }

 

        public virtual int PostID { get; set; }

 

        public virtual DateTime CommentDate { get; set; }

 

        public virtual int CommentDeleted { get; set; }

    }

}

 

User.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.ComponentModel.DataAnnotations;

using System.Data.Entity;

using System.Web.Mvc;

 

namespace Twitt.Models

{

    public class User

    {

        public virtual int UserID { get; set; }

 

        public virtual string UserName { get; set; }

 

        public virtual string UserPassword { get; set; }

 

        public virtual string UserAvatarPath { get; set; }

 

        public virtual int UserDeleted { get; set; }

 

        public virtual DateTime UserRegDate { get; set; }

 

        public int UserRoleID { get; set; }

    }

}

 

Post.cs

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace Twitt.Models

{

    public class Post

    {

        public virtual int PostID { get; set; }

 

        public virtual int UserID { get; set; }

 

        public virtual string PostText { get; set; }

 

        public virtual DateTime PostDate { get; set; }

 

        public virtual int? CommentID { get; set; }

 

        public virtual int PostDeleted { get; set; }

    }

}

 

PostPage.cshtml

@using Twitt.Models

@using Twitt.HtmlHelpers

 

@model User

 

@{

    ViewBag.Title = "PostPage";

}

 

 

<div class="container-fluid">

    <div class="row-fluid">

        <div class="span3">

            <p class="text-info">@User.Identity.Name</p>

            @Html.Image(@Model.UserAvatarPath, new { @class = "img-polaroid" })

        </div>

        <div class="span9">

            <ul class="nav nav-pills">

                <li class="active">

                    @Html.ActionLink("Home", "PostPage", "Post")

                </li>

                <li>

                    @Html.ActionLink("New Post", "AddNewPost", "Post")

                </li>

                <li>

                    @Html.ActionLink("Profile", "EditProfile", "User")

                </li>

                <li>

                    @Html.ActionLink("Last Post", "ShowLastPosts", "LastPost")

                </li>

                <li>

                    @Html.ActionLink("Log out", "LogOut", "Account")

                </li>

            </ul>

 

            <div class="post">

                @Html.Action("ShowUserPost", "Post")

            </div>

        </div>

    </div>

</div>

 

ShowUserPost.cs

 

@using Twitt.Models

@model List<PostModel>

 

@foreach (var p in Model)

{

    <div class="post-text">@Html.ActionLink(p.Post.PostText, "ShowPostInfo", "Post", new { postID = p.Post.PostID}, null)</div>

   

    using (Html.BeginForm("DeleteUserPost", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))

    {

    <input type="hidden" value="@p.Post.PostID" name="PostID" />

   

    <div class="post-date">

        Posted at <strong>@p.Post.PostDate</strong> by <strong>@User.Identity.Name</strong>

        <button type="submit" class="btn" style="margin-left: 50px;">Delete</button>

       

        @Html.Label("Tags: ")

        @foreach (var tag in p.Tags)

        {

            <p>@Html.ActionLink(tag, "GetAllPostByTagName", "Post", new { tagName = tag }, null)</p>

        }

    </div>

    }

}

 

ImageHtmlHelper.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;

 

namespace Twitt.HtmlHelpers

{

    public static class ImageHtmlHelper

    {

        public static IHtmlString Image(this HtmlHelper HtmlHelper, string src, object htmlAttributes)

        {

            TagBuilder tb = new TagBuilder("img");

            if (src != "")

            {

                tb.Attributes.Add("src", VirtualPathUtility.ToAbsolute(src));

                tb.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            }

 

            return new MvcHtmlString(tb.ToString(TagRenderMode.SelfClosing));

        }

    }

}

 

Post.js

var numberTag = 0;

 

function addNewTag() {

    var tags = $("#tags")[0];

    numberTag++;

    tags.innerHTML += '<input type="text" name="Tags[' + numberTag + ']" />';

}

 

 


Информация о работе Программирование Баз данных