Skip to content

Commit 5a60c89

Browse files
committed
Registration By admin
1 parent 0fdf0c0 commit 5a60c89

39 files changed

+351
-11
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,48 @@ public bool AddAvatar(Entities.Avatar avatar)
724724
}
725725

726726
}
727+
728+
public IEnumerable<Entities.PresentPost> GetResultOfSearchTag(string p)
729+
{
730+
using (SqlConnection con = new SqlConnection(ConnectionString))
731+
{
732+
SqlCommand command = new SqlCommand("SELECT dbo.Posts.Post_Id, dbo.Posts.Post_Title FROM dbo.Posts INNER JOIN dbo.Tags ON dbo.Tags.Post_Id = dbo.Posts.Post_Id WHERE CONTAINS(Tag, @Tag)", con);
733+
command.Parameters.Add("@Tag", p);
734+
con.Open();
735+
var reader = command.ExecuteReader();
736+
737+
while (reader.Read())
738+
{
739+
yield return new Entities.PresentPost()
740+
{
741+
Id = new Guid((string)reader["Post_Id"]),
742+
Title = (string)reader["Post_Title"]
743+
};
744+
745+
}
746+
}
747+
}
748+
749+
750+
public IEnumerable<Entities.PresentPost> GetResultOfSearch(string p)
751+
{
752+
using (SqlConnection con = new SqlConnection(ConnectionString))
753+
{
754+
SqlCommand command = new SqlCommand("SELECT dbo.Posts.Post_Id, dbo.Posts.Post_Title FROM dbo.Posts INNER JOIN dbo.Tags ON dbo.Tags.Post_Id = dbo.Posts.Post_Id WHERE CONTAINS(Post_Text, @Text)", con);
755+
command.Parameters.Add("@Text", p);
756+
con.Open();
757+
var reader = command.ExecuteReader();
758+
759+
while (reader.Read())
760+
{
761+
yield return new Entities.PresentPost()
762+
{
763+
Id = new Guid((string)reader["Post_Id"]),
764+
Title = (string)reader["Post_Title"]
765+
};
766+
767+
}
768+
}
769+
}
727770
}
728771
}
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
-2 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.UI.Web/Controllers/AdminController.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,42 @@ public ActionResult DeleteComment(Guid id, ConfirmModel model, string ReturnUrl)
138138
return View();
139139
}
140140

141+
142+
[Authorize(Roles = "Admin")]
143+
public ActionResult Create()
144+
{
145+
return View();
146+
}
147+
148+
[Authorize(Roles = "Admin")]
149+
[ValidateAntiForgeryToken]
150+
[HttpPost]
151+
public ActionResult Create(RegModel model, string ReturnUrl)
152+
{
153+
if (ModelState.IsValid)
154+
{
155+
string Result;
156+
if (model.RegByAdmin(out Result))
157+
{
158+
159+
if (!string.IsNullOrWhiteSpace(ReturnUrl))
160+
{
161+
return Redirect(ReturnUrl);
162+
}
163+
else
164+
{
165+
return RedirectToAction("Users", "Admin");
166+
}
167+
}
168+
else
169+
{
170+
ViewData["Result"] = Result;
171+
}
172+
}
173+
return View();
174+
175+
}
176+
141177
//[HttpPost]
142178
//public ActionResult ChangeUser()
143179
//{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using EPAM.MyBlog.UI.Web.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
using System.Web.Mvc;
7+
8+
namespace EPAM.MyBlog.UI.Web.Controllers
9+
{
10+
public class SearchController : Controller
11+
{
12+
//
13+
// GET: /Search/
14+
15+
public ActionResult Index()
16+
{
17+
return View();
18+
}
19+
20+
[HttpPost]
21+
public ActionResult Index(SearchModel model)
22+
{
23+
if (!String.IsNullOrEmpty(model.SearchText))
24+
{
25+
return RedirectToAction("Result", new { search = model.SearchText });
26+
}
27+
else
28+
{
29+
return PartialView();
30+
}
31+
32+
}
33+
34+
[HttpPost]
35+
public ActionResult Result(string search)
36+
{
37+
SearchModel model = new SearchModel();
38+
var result = model.GetResult();
39+
return View(result);
40+
}
41+
}
42+
}

EPAM.MyBlog.UI.Web/EPAM.MyBlog.UI.Web.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@
116116
<Compile Include="Controllers\FilesController.cs" />
117117
<Compile Include="Controllers\HomeController.cs" />
118118
<Compile Include="Controllers\PostController.cs" />
119+
<Compile Include="Controllers\SearchController.cs" />
119120
<Compile Include="GetDAL.cs" />
120121
<Compile Include="Global.asax.cs">
121122
<DependentUpon>Global.asax</DependentUpon>
122123
</Compile>
123124
<Compile Include="Models\AvatarModel.cs" />
125+
<Compile Include="Models\SearchModel.cs" />
124126
<Compile Include="Models\UserAboutModel.cs" />
125127
<Compile Include="Models\CommentModel.cs" />
126128
<Compile Include="Models\ConfirmModel.cs" />
@@ -291,6 +293,9 @@
291293
<Content Include="Views\Account\UserInfo.cshtml" />
292294
<Content Include="Views\Account\UserAvatar.cshtml" />
293295
<Content Include="Views\Post\News.cshtml" />
296+
<Content Include="Views\Search\Index.cshtml" />
297+
<Content Include="Views\Search\Result.cshtml" />
298+
<Content Include="Views\Admin\Create.cshtml" />
294299
</ItemGroup>
295300
<ItemGroup>
296301
<Folder Include="App_Data\" />

EPAM.MyBlog.UI.Web/Logs/Debug/2015.01.11.log

Whitespace-only changes.

EPAM.MyBlog.UI.Web/Logs/Errors/2015.01.11.log

Whitespace-only changes.

EPAM.MyBlog.UI.Web/Models/RegModel.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,41 @@ internal bool Reg(out string Result)
143143
}
144144

145145

146+
internal bool RegByAdmin(out string Result)
147+
{
148+
var user = (Entities.User)this;
149+
byte[] Pass = GetDAL.dal.CheckLogPas(this.Name);
150+
if (Pass != null)
151+
{
152+
Result = "Пользователь с таким логином уже существует!";
153+
logger.Info("Попытка регистрации существующего логина" + this.Name);
154+
return false;
155+
}
156+
else
157+
{
158+
if (GetDAL.dal.CheckMail(this.Email))
159+
{
160+
Result = "Данный E-mail уже зарегистрирован!";
161+
return false;
162+
}
163+
else
164+
{
165+
166+
bool answer = GetDAL.dal.Registration(user);
167+
if (answer)
168+
{
169+
Result = "Вы зарегистрированы!";
170+
return true;
171+
}
172+
else
173+
{
174+
Result = "Упс, что-то пошло не так! Попробуйте, пажалуйста, еще раз.";
175+
return false;
176+
}
177+
}
178+
}
179+
}
180+
181+
146182
}
147183
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace EPAM.MyBlog.UI.Web.Models
7+
{
8+
public class SearchModel
9+
{
10+
public string SearchText { get { return search; } set { search = value; } }
11+
12+
private string search;
13+
14+
public static explicit operator SearchModel(Entities.Search search)
15+
{
16+
return new SearchModel() { SearchText = search.SearchText };
17+
}
18+
19+
public static explicit operator Entities.Search(SearchModel search)
20+
{
21+
return new Entities.Search() { SearchText = search.SearchText };
22+
}
23+
24+
internal IEnumerable<PresentPostModel> GetResult()
25+
{
26+
string query = SearchText.Trim();
27+
if(query.Substring(0,1) == "#")
28+
{
29+
var result = GetDAL.dal.GetResultOfSearchTag(this.SearchText).ToList();
30+
List<PresentPostModel> TitleList = new List<PresentPostModel>();
31+
foreach (var item in result)
32+
{
33+
TitleList.Add((PresentPostModel)item);
34+
}
35+
return TitleList;
36+
}
37+
else
38+
{
39+
var result = GetDAL.dal.GetResultOfSearch(this.SearchText).ToList();
40+
List<PresentPostModel> TitleList = new List<PresentPostModel>();
41+
foreach (var item in result)
42+
{
43+
TitleList.Add((PresentPostModel)item);
44+
}
45+
return TitleList;
46+
}
47+
}
48+
}
49+
}

EPAM.MyBlog.UI.Web/Views/Account/MenuState.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</ul>
1818
</li>
1919
<li><a href="@Url.Action("Help", "Home")">Помощь</a></li>
20+
<li><a href="@Url.Action("Index", "Search")">Поиск</a></li>
2021
@if (User.IsInRole("Moder"))
2122
{
2223
@Html.Partial("~/Views/Admin/ModerMenu.cshtml")
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
@model EPAM.MyBlog.UI.Web.Models.RegModel
2+
3+
@{
4+
ViewBag.Title = "Reg";
5+
}
6+
7+
8+
@using (Html.BeginForm()) {
9+
@Html.ValidationSummary(true)
10+
@Html.AntiForgeryToken()
11+
@Html.Hidden("ReturnUrl",ViewData["ReturnUrl"])
12+
13+
<fieldset>
14+
<legend>Регистрация</legend>
15+
16+
<div class="col-sm-10 col-md-10 col-lg-10 col-sx-10 col-sm-offset-4 col-md-offset-4 col-sx-offset-4 col-lg-offset-4">
17+
<div class ="validation-error col-sm-8 col-md-8 col-lg-8 col-sx-8">
18+
@ViewData["Result"]
19+
</div>
20+
<div class="form-group col-sm-8 col-md-8 col-lg-8 col-sx-8">
21+
<label>
22+
@Html.LabelFor(model => model.Email)
23+
</label>
24+
<div class="editor-field">
25+
@Html.EditorFor(model => model.Email)
26+
<div>
27+
@Html.ValidationMessageFor(model => model.Email, null, new { @class = "validation-error" })
28+
</div>
29+
</div>
30+
</div>
31+
<div class="form-group col-sm-8 col-md-8 col-lg-8 col-sx-8">
32+
<label>
33+
@Html.LabelFor(model => model.Name)
34+
</label>
35+
36+
<div class="editor-field">
37+
@Html.EditorFor(model => model.Name)
38+
<div>
39+
@Html.ValidationMessageFor(model => model.Name, null, new { @class = "validation-error" })
40+
</div>
41+
</div>
42+
</div>
43+
<div class="form-group col-sm-8 col-md-8 col-lg-8 col-sx-8">
44+
<label>
45+
@Html.LabelFor(model => model.Password)
46+
</label>
47+
48+
<div class="editor-field">
49+
@Html.EditorFor(model => model.Password)
50+
<div>
51+
@Html.ValidationMessageFor(model => model.Password, null, new { @class = "validation-error" })
52+
</div>
53+
</div>
54+
</div>
55+
<div class="form-group col-sm-8 col-md-8 col-lg-8 col-sx-8">
56+
<label>
57+
@Html.LabelFor(model => model.Confirm)
58+
</label>
59+
<div class="editor-field">
60+
@Html.EditorFor(model => model.Confirm)
61+
<div>
62+
@Html.ValidationMessageFor(model => model.Confirm, null, new { @class = "validation-error" })
63+
</div>
64+
</div>
65+
</div>
66+
<div class="form-group">
67+
<div class="col-sm-5 col-md-5 col-lg-5 col-sx-5">
68+
<button type="submit" class="btn btn-default" id="reg">Регистрация</button>
69+
</div>
70+
</div>
71+
</div>
72+
73+
</fieldset>
74+
}
75+
76+
77+
@section script {
78+
<script src="~/Scripts/jquery.validate.js"></script>
79+
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
80+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@model EPAM.MyBlog.UI.Web.Models.SearchModel
2+
3+
@using (Html.BeginForm("Index", "Search")) {
4+
@Html.ValidationSummary(true)
5+
@Html.AntiForgeryToken()
6+
7+
<form class="navbar-form" role="search">
8+
<div class="input-group">
9+
@Html.TextBoxFor(model => model.SearchText, new { type="text", @class="form-control", placeholder="Search", name="srch-term", id="srch-term"})
10+
@*<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">*@
11+
<div class="input-group-btn">
12+
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
13+
</div>
14+
</div>
15+
</form>
16+
}
17+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@model IEnumerable<EPAM.MyBlog.UI.Web.Models.PresentPostModel>
2+
@{
3+
WebGrid grid = new WebGrid(Model);
4+
}
5+
6+
<h2> Результаты поиска </h2>
7+
8+
@if(Model != null)
9+
{
10+
@grid.GetHtml(columns: new [] {
11+
grid.Column("Title",header: " "),
12+
grid.Column("",
13+
header: "",
14+
format: @<text>
15+
@Html.ActionLink("Читать", "Posts", new { id=item.Id })
16+
</text>
17+
)
18+
})
19+
20+
}
21+
else
22+
{
23+
<p>Поиск не дал результатов</p>
24+
}

0 commit comments

Comments
 (0)