Commit 11f30626 authored by SergeevaAA's avatar SergeevaAA

Добавлена страница с контактной информацией

parent 074a6e78
......@@ -53,5 +53,10 @@
/// </summary>
[Required]
public virtual string Phone { get; set; }
public static string GetFullName(string firstName, string middleName, string lastName)
{
return $"{lastName} {firstName} {middleName ?? string.Empty}".TrimEnd();
}
}
}
\ No newline at end of file
namespace FileDesk.Domain.ViewModels
{
using System;
using System.ComponentModel.DataAnnotations;
using FileDesk.Domain.Models;
......@@ -27,6 +28,7 @@
/// <summary>
/// Дата и время
/// </summary>
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy HH:MM}")]
public virtual DateTime DateTime { get; set; }
/// <summary>
......
namespace FileDesk.Domain.ViewModels
{
using System.ComponentModel.DataAnnotations;
/// <summary>
/// Контактная информация
/// </summary>
public class ContactViewModel
{
/// <summary>
/// ФИО
/// </summary>
[Display(Name = "ФИО")]
public virtual string FullName { get; set; }
/// <summary>
/// Организация
/// </summary>
[Display(Name = "Организация")]
public virtual string Organization { get; set; }
/// <summary>
/// Отдел
/// </summary>
[Display(Name = "Отдел")]
public virtual string Department { get; set; }
/// <summary>
/// Должность
/// </summary>
[Display(Name = "Должность")]
public virtual string Post { get; set; }
/// <summary>
/// E-mail
/// </summary>
[Display(Name = "E-mail")]
public virtual string Email { get; set; }
/// <summary>
/// Телефон
/// </summary>
[Display(Name = "Телефон")]
public virtual string Phone { get; set; }
}
}
\ No newline at end of file
namespace FileDesk.Domain.ViewModels
{
using System;
using FileDesk.Domain.Enums;
using System.ComponentModel.DataAnnotations;
using FileDesk.Domain.Models;
/// <summary>
......@@ -22,6 +23,7 @@
/// <summary>
/// Дата и время добавления
/// </summary>
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy HH:MM}")]
public virtual DateTime UploadDateTime { get; set; }
/// <summary>
......
namespace FileDesk.Services.Interfaces
{
using System.Linq;
using FileDesk.DataAccess.Repository;
using FileDesk.Domain.Models;
using FileDesk.Domain.ViewModels;
/// <summary>
/// Сервис для работы с контакной информацией
/// </summary>
public class ContactService : IContactService
{
private readonly FileDeskContext _db;
/// <summary>
/// Создает новый экземпляр класса <see cref = "ContactService"/>
/// </summary>
/// <param name="db">Контекст для работы с БД</param>
public ContactService(FileDeskContext db)
{
_db = db;
}
/// <summary>
/// Получение контактной информации
/// </summary>
/// <returns>Контактная информация</returns>
public ContactViewModel Get()
{
var contact = _db.Contacts.FirstOrDefault();
return new ContactViewModel
{
FullName = Contact.GetFullName(contact.FirstName, contact.MiddleName, contact.LastName),
Organization = contact.Organization,
Department = contact.Department,
Post = contact.Post,
Email = contact.Email,
Phone = contact.Phone
};
}
}
}
\ No newline at end of file
namespace FileDesk.Services.Interfaces
{
using FileDesk.Domain.ViewModels;
/// <summary>
/// Интерфейс сервиса для работы с контактной информацией
/// </summary>
public interface IContactService
{
/// <summary>
/// Получение контактной информации
/// </summary>
/// <returns>Контактная информация</returns>
ContactViewModel Get();
}
}
\ No newline at end of file
......@@ -25,6 +25,7 @@
#endregion
#region Конструкторы и деструкторы
/// <summary>
/// Создает новый экземпляр класса <see cref = "FileController"/>
/// </summary>
......
using System.Diagnostics;
using FileDesk.Services.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FileDesk.Web.Controllers
{
/// <summary>
/// Контроллер для работы с общей информацией
/// </summary>
public class HomeController : Controller
{
#region Свойства
private readonly IContactService _contactService;
#endregion
#region Конструкторы и деструкторы
/// <summary>
/// Создает новый экземпляр класса <see cref = "HomeController"/>
/// </summary>
/// <param name="contactService">Сервис для работы с пользователями</param>
public HomeController(IContactService contactService)
{
_contactService = contactService;
}
#endregion
#region Методы
/// <summary>
/// Получение информации о сайте
/// </summary>
/// <returns>Информация о сайте</returns>
[HttpGet]
[Authorize(Roles = "admin, user")]
public IActionResult About()
{
return View();
}
/// <summary>
/// Получение контактной информации
/// </summary>
/// <returns>Контактная информация</returns>
[HttpGet]
[Authorize(Roles = "admin, user")]
public IActionResult Contacts()
{
return View();
var contacts = _contactService.Get();
return View(contacts);
}
/// <summary>
/// Страница с сообщением о запрете доступа
/// </summary>
/// <returns>Сообщение о том, что доступ запрещен</returns>
public IActionResult AccessDenied()
{
return View();
}
/// <summary>
/// Страница с информацией об ошибке
/// </summary>
/// <returns>Информация об ошибке</returns>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
}
#endregion
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@ namespace FileDesk.Web
services.AddTransient<IUserService, UserService>();
services.AddTransient<IFileService, FileService>();
services.AddTransient<IActionService, ActionService>();
services.AddTransient<IContactService, ContactService>();
services.AddTransient<Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor, Microsoft.AspNetCore.Mvc.Infrastructure.ActionContextAccessor>();
services.AddTransient<Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();
......
@{
@model FileDesk.Domain.ViewModels.ContactViewModel
@{
ViewData["Title"] = "О разработчике";
}
<h1>@ViewData["Title"]</h1>
Здесь будет контактная информация
\ No newline at end of file
<h1>@ViewData["Title"]</h1><br/>
<div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.FullName):</b>
@Html.DisplayFor(m => m.FullName)
</div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.Organization):</b>
@Html.DisplayFor(m => m.Organization)
</div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.Department):</b>
@Html.DisplayFor(m => m.Department)
</div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.Post):</b>
@Html.DisplayFor(m => m.Post)
</div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.Email):</b>
@Html.DisplayFor(m => m.Email)
</div>
<div class="form-group">
<b>@Html.DisplayNameFor(m => m.Phone):</b>
@Html.DisplayFor(m => m.Phone)
</div>
</div>
......@@ -18,6 +18,12 @@
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="About">О сайте</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Contacts">Контакты</a>
</li>
@if (User.Identity.IsAuthenticated)
{
<li class="nav-item">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment