Skip to content

Commit 9c87540

Browse files
committed
Info about user
1 parent 3795c4f commit 9c87540

24 files changed

+336
-13
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,79 @@ public void SaveReason(string reason)
498498
}
499499

500500

501-
public bool SaveInfoText(Entities.UserInfo info)
501+
public bool SaveSex(Entities.UserInfo info)
502502
{
503503
using (SqlConnection con = new SqlConnection(ConnectionString))
504504
{
505-
SqlCommand command = new SqlCommand("UPDATE dbo.UserAbout SET Sex = @Sex, Birthday = CAST(@Birthday AS Date), True_Name = @True_Name, About = @About WHERE Login = @Login", con);
505+
SqlCommand command = new SqlCommand("UPDATE dbo.UserAbout SET Sex = @Sex WHERE Login = @Login", con);
506506
command.Parameters.Add(new SqlParameter("@Sex", info.Sex));
507-
command.Parameters.Add(new SqlParameter("@Birthday", info.Birthday));
508-
command.Parameters.Add(new SqlParameter("@True_Name", info.Name));
507+
command.Parameters.Add(new SqlParameter("@Login", info.Login));
508+
con.Open();
509+
int count = command.ExecuteNonQuery();
510+
if (count > 0)
511+
{
512+
return true;
513+
}
514+
else
515+
{
516+
return false;
517+
}
518+
}
519+
}
520+
521+
public bool SaveDate(Entities.UserInfo info)
522+
{
523+
using (SqlConnection con = new SqlConnection(ConnectionString))
524+
{
525+
526+
SqlCommand command = new SqlCommand("UPDATE dbo.UserAbout SET Birthday = @Birthday WHERE Login = @Login", con);
527+
if (info.Birthday == null)
528+
{
529+
command.Parameters.Add(new SqlParameter("@Birthday", DBNull.Value));
530+
}
531+
else
532+
{
533+
command.Parameters.Add(new SqlParameter("@Birthday", info.Birthday));
534+
}
535+
command.Parameters.Add(new SqlParameter("@Login", info.Login));
536+
con.Open();
537+
int count = command.ExecuteNonQuery();
538+
if (count > 0)
539+
{
540+
return true;
541+
}
542+
else
543+
{
544+
return false;
545+
}
546+
}
547+
}
548+
549+
public bool SaveName(Entities.UserInfo info)
550+
{
551+
using (SqlConnection con = new SqlConnection(ConnectionString))
552+
{
553+
SqlCommand command = new SqlCommand("UPDATE dbo.UserAbout SET True_Name = @Name WHERE Login = @Login", con);
554+
command.Parameters.Add(new SqlParameter("@Name", info.Name));
555+
command.Parameters.Add(new SqlParameter("@Login", info.Login));
556+
con.Open();
557+
int count = command.ExecuteNonQuery();
558+
if (count > 0)
559+
{
560+
return true;
561+
}
562+
else
563+
{
564+
return false;
565+
}
566+
}
567+
}
568+
569+
public bool SaveAbout(Entities.UserInfo info)
570+
{
571+
using (SqlConnection con = new SqlConnection(ConnectionString))
572+
{
573+
SqlCommand command = new SqlCommand("UPDATE dbo.UserAbout SET About = @About WHERE Login = @Login", con);
509574
command.Parameters.Add(new SqlParameter("@About", info.AboutMe));
510575
command.Parameters.Add(new SqlParameter("@Login", info.Login));
511576
con.Open();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public ActionResult AboutMe()
173173
return View(info);
174174
}
175175

176-
public ActionResult EditInfoText()
176+
public ActionResult EditSex()
177177
{
178178
var info = UserAboutModel.GetInfo(User.Identity.Name);
179179
return View(info);
@@ -182,11 +182,114 @@ public ActionResult EditInfoText()
182182

183183
[HttpPost]
184184
[ValidateAntiForgeryToken]
185-
public ActionResult EditInfoText(UserAboutModel model)
185+
public ActionResult EditSex(UserAboutModel model)
186186
{
187+
if(string.IsNullOrEmpty(model.Sex))
188+
{
189+
model.Sex = " ";
190+
}
191+
model.Login = User.Identity.Name;
192+
if (ModelState.IsValid)
193+
{
194+
if (model.SetSex())
195+
{
196+
return RedirectToAction("AboutMe", "Account");
197+
}
198+
else
199+
{
200+
return View(model);
201+
}
202+
}
203+
else
204+
{
205+
return View(model);
206+
}
207+
}
208+
209+
210+
211+
public ActionResult EditDate()
212+
{
213+
var info = UserAboutModel.GetInfo(User.Identity.Name);
214+
return View(info);
215+
}
216+
217+
218+
[HttpPost]
219+
[ValidateAntiForgeryToken]
220+
public ActionResult EditDate(UserAboutModel model)
221+
{
222+
model.Login = User.Identity.Name;
223+
if (ModelState.IsValid)
224+
{
225+
if (model.SetDate())
226+
{
227+
return RedirectToAction("AboutMe", "Account");
228+
}
229+
else
230+
{
231+
return View(model);
232+
}
233+
}
234+
else
235+
{
236+
return View(model);
237+
}
238+
}
239+
240+
public ActionResult EditName()
241+
{
242+
var info = UserAboutModel.GetInfo(User.Identity.Name);
243+
return View(info);
244+
}
245+
246+
247+
[HttpPost]
248+
[ValidateAntiForgeryToken]
249+
public ActionResult EditName(UserAboutModel model)
250+
{
251+
model.Login = User.Identity.Name;
252+
if (string.IsNullOrEmpty(model.Name))
253+
{
254+
model.Name = " ";
255+
}
256+
if (ModelState.IsValid)
257+
{
258+
if (model.SetName())
259+
{
260+
return RedirectToAction("AboutMe", "Account");
261+
}
262+
else
263+
{
264+
return View(model);
265+
}
266+
}
267+
else
268+
{
269+
return View(model);
270+
}
271+
}
272+
273+
274+
public ActionResult EditAbout()
275+
{
276+
var info = UserAboutModel.GetInfo(User.Identity.Name);
277+
return View(info);
278+
}
279+
280+
281+
[HttpPost]
282+
[ValidateAntiForgeryToken]
283+
public ActionResult EditAbout(UserAboutModel model)
284+
{
285+
if (string.IsNullOrEmpty(model.AboutMe))
286+
{
287+
model.AboutMe = " ";
288+
}
289+
model.Login = User.Identity.Name;
187290
if (ModelState.IsValid)
188291
{
189-
if (model.SetInfo())
292+
if (model.SetAbout())
190293
{
191294
return RedirectToAction("AboutMe", "Account");
192295
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@
280280
<Content Include="Scripts\tinymce\tinymce\skins\lightgray\fonts\tinymce.woff" />
281281
<Content Include="Views\Home\Help.cshtml" />
282282
<Content Include="Views\Account\AboutMe.cshtml" />
283-
<Content Include="Views\Account\EditInfoText.cshtml" />
283+
<Content Include="Views\Account\EditSex.cshtml" />
284+
<Content Include="Views\Account\EditDate.cshtml" />
285+
<Content Include="Views\Account\EditName.cshtml" />
286+
<Content Include="Views\Account\EditAbout.cshtml" />
284287
</ItemGroup>
285288
<ItemGroup>
286289
<Folder Include="App_Data\" />

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

Whitespace-only changes.

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

Whitespace-only changes.

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,28 @@ public static UserAboutModel GetInfo(string name)
7575
//MimeType = image.ContentType;
7676
//Data = new byte[image.ContentLength];
7777

78-
internal bool SetInfo()
78+
internal bool SetSex()
7979
{
8080
var info = (Entities.UserInfo)this;
81-
return GetDAL.dal.SaveInfoText(info);
81+
return GetDAL.dal.SaveSex(info);
82+
}
83+
84+
internal bool SetDate()
85+
{
86+
var info = (Entities.UserInfo)this;
87+
return GetDAL.dal.SaveDate(info);
88+
}
89+
90+
internal bool SetName()
91+
{
92+
var info = (Entities.UserInfo)this;
93+
return GetDAL.dal.SaveName(info);
94+
}
95+
96+
internal bool SetAbout()
97+
{
98+
var info = (Entities.UserInfo)this;
99+
return GetDAL.dal.SaveAbout(info);
82100
}
83101
}
84102
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99

1010
<div class="display-label">
1111
@Html.DisplayNameFor(model => model.Sex)
12+
1213
</div>
1314
@if(Model.Sex != null){
1415
<div class="display-field">
1516
@Html.DisplayFor(model => model.Sex)
17+
1618
</div>
1719
}
20+
@Html.ActionLink("Изменить", "EditSex", null, new { @class="btn btn-default"})
1821
<div class="display-label">
1922
@Html.DisplayNameFor(model => model.Birthday)
23+
2024
</div>
2125
@if(Model.Birthday != null){
2226
<div class="display-field">
23-
@Html.DisplayFor(model => model.Birthday)
27+
@Html.DisplayFor(model => model.Birthday)
2428
</div>
2529
}
30+
@Html.ActionLink("Изменить", "EditDate", null, new { @class="btn btn-default"})
2631
<div class="display-label">
2732
@Html.DisplayNameFor(model => model.Name)
2833
</div>
@@ -31,7 +36,7 @@
3136
@Html.DisplayFor(model => model.Name)
3237
</div>
3338
}
34-
39+
@Html.ActionLink("Изменить", "EditName", null, new { @class="btn btn-default"})
3540
<div class="display-label">
3641
@Html.DisplayNameFor(model => model.AboutMe)
3742
</div>
@@ -40,8 +45,8 @@
4045
@Html.DisplayFor(model => model.AboutMe)
4146
</div>
4247
}
48+
@Html.ActionLink("Изменить", "EditAbout", null, new { @class="btn btn-default"})
4349
</fieldset>
4450
<div>
45-
@Html.ActionLink("Изменить инфу", "EditInfoText", null, new { @class="btn btn-default"})
4651
@Html.ActionLink("Изменить аватар", "EditInfoAvatar", null, new { @class="btn btn-default"})
4752
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@model EPAM.MyBlog.UI.Web.Models.UserAboutModel
2+
3+
@{
4+
ViewBag.Title = "EditAbout";
5+
}
6+
7+
<h2></h2>
8+
9+
@using (Html.BeginForm()) {
10+
@Html.ValidationSummary(true)
11+
@Html.AntiForgeryToken()
12+
13+
<fieldset>
14+
<legend>О себе</legend>
15+
16+
<div class="editor-label">
17+
@Html.LabelFor(model => model.AboutMe)
18+
</div>
19+
<div class="editor-field">
20+
@Html.EditorFor(model => model.AboutMe)
21+
@Html.ValidationMessageFor(model => model.AboutMe)
22+
</div>
23+
24+
<p>
25+
<input type="submit" value="Сохранить" />
26+
</p>
27+
</fieldset>
28+
}
29+
30+
<div>
31+
@Html.ActionLink("Вернуться", "AboutMe")
32+
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@model EPAM.MyBlog.UI.Web.Models.UserAboutModel
2+
3+
@{
4+
ViewBag.Title = "EditDate";
5+
}
6+
7+
<h2>EditInfoText</h2>
8+
9+
@using (Html.BeginForm()) {
10+
@Html.ValidationSummary(true)
11+
@Html.AntiForgeryToken()
12+
13+
<fieldset>
14+
<legend>День Рождения</legend>
15+
16+
<div class="editor-label">
17+
@Html.LabelFor(model => model.Birthday)
18+
</div>
19+
<div class="editor-field">
20+
@Html.EditorFor(model => model.Birthday)
21+
@Html.ValidationMessageFor(model => model.Birthday)
22+
</div>
23+
24+
<p>
25+
<input type="submit" value="Сохранить" />
26+
</p>
27+
</fieldset>
28+
}
29+
30+
<div>
31+
@Html.ActionLink("Вернуться", "AboutMe")
32+
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@model EPAM.MyBlog.UI.Web.Models.UserAboutModel
2+
3+
@{
4+
ViewBag.Title = "EditName";
5+
}
6+
7+
<h2>EditInfoText</h2>
8+
9+
@using (Html.BeginForm()) {
10+
@Html.ValidationSummary(true)
11+
@Html.AntiForgeryToken()
12+
13+
<fieldset>
14+
<legend>Имя</legend>
15+
16+
<div class="editor-label">
17+
@Html.LabelFor(model => model.Name)
18+
</div>
19+
<div class="editor-field">
20+
@Html.EditorFor(model => model.Name)
21+
@Html.ValidationMessageFor(model => model.Name)
22+
</div>
23+
24+
<p>
25+
<input type="submit" value="Сохранить" />
26+
</p>
27+
</fieldset>
28+
}
29+
30+
<div>
31+
@Html.ActionLink("Вернуться", "AboutMe")
32+
</div>

0 commit comments

Comments
 (0)