678 lines
25 KiB
C#
678 lines
25 KiB
C#
using EventVisitorClientApp.Models;
|
|
using EventVisitorLogic.BindingModels;
|
|
using EventVisitorLogic.Logic;
|
|
using EventVisitorLogic.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace EventVisitorClientApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
Random rnd = new Random();
|
|
private static readonly Random _random = new Random();
|
|
private void DisplayErrorMessage(string message)
|
|
{
|
|
ViewBag.ErrorMessage = message;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Enter()
|
|
{
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
public IActionResult Enter(string login, string password)
|
|
{
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Ââåäèòå ëîãèí è ïàðîëü.", returnUrl });
|
|
}
|
|
|
|
APIClient.Client = APIClient.GetRequest<OrganizerViewModel>($"api/Organizer/login?login={login}&password={password}");
|
|
|
|
if (APIClient.Client == null)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Íåâåðíûé ëîãèí/ïàðîëü.", returnUrl });
|
|
}
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~Home/Enter");
|
|
}
|
|
return View(APIClient.Client);
|
|
}
|
|
[HttpPost]
|
|
public void Privacy(string login, string password, string surname, string name, string lastname, string role, string organizationName, string phone)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
|
}
|
|
if (string.IsNullOrEmpty(login))
|
|
{
|
|
throw new Exception("Ââåäèòå e-mail");
|
|
}
|
|
if (string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Ââåäèòå ïàðîëü");
|
|
}
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
throw new Exception("Ââåäèòå èìÿ");
|
|
}
|
|
if (string.IsNullOrEmpty(surname))
|
|
{
|
|
throw new Exception("Ââåäèòå ôàìèëèþ");
|
|
}
|
|
if (string.IsNullOrEmpty(organizationName))
|
|
{
|
|
throw new Exception("Ââåäèòå íàçâàíèå îðãàíèçàöèè");
|
|
}
|
|
if (string.IsNullOrEmpty(role))
|
|
{
|
|
throw new Exception("Ââåäèòå ðîëü");
|
|
}
|
|
APIClient.PostRequest("api/client/updatedata", new OrganizerBindingModel
|
|
{
|
|
Id = APIClient.Client.Id,
|
|
Name = name,
|
|
Surname = surname,
|
|
LastName = lastname,
|
|
OrganizationName = organizationName,
|
|
Phone = phone,
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
|
|
APIClient.Client.Name = name;
|
|
APIClient.Client.Surname = surname;
|
|
APIClient.Client.LastName = lastname;
|
|
APIClient.Client.OrganizationName = organizationName;
|
|
APIClient.Client.Phone = phone;
|
|
APIClient.Client.Email = login;
|
|
APIClient.Client.Password = password;
|
|
Response.Redirect("Index");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ìåòîäû äëÿ îðãàíèçàòîðà
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
|
|
public IActionResult Logout()
|
|
{
|
|
APIClient.Client = null;
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Register(string login, string password, string surname, string name, string lastname, string organizationName, string phone, string code)
|
|
{
|
|
// Ïîëó÷àåì URL ñòðàíèöû, ñ êîòîðîé ïðèøëè
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
// Ïðîâåðÿåì, ñóùåñòâóåò ëè ïîëüçîâàòåëü ñ òàêèì ëîãèíîì
|
|
var existingUser = APIClient.GetRequest<OrganizerViewModel>($"api/Organizer/GetOrganizer?login={login}");
|
|
|
|
// Åñëè ïîëüçîâàòåëü ñóùåñòâóåò, ïåðåíàïðàâëÿåì íà ñòðàíèöó îøèáêè
|
|
if (existingUser != null)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Ïîëüçîâàòåëü ñ òàêèì email óæå ñóùåñòâóåò.", returnUrl });
|
|
}
|
|
|
|
// Åñëè ïîëüçîâàòåëÿ íåò, ïðîäîëæàåì ñ ðåãèñòðàöèåé
|
|
APIClient.PostRequest("api/Organizer/Register", new OrganizerBindingModel
|
|
{
|
|
Name = name,
|
|
Surname = surname,
|
|
LastName = lastname,
|
|
OrganizationName = organizationName,
|
|
Phone = phone,
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
|
|
return RedirectToAction("Enter"); // Ïåðåíàïðàâëåíèå íà ñòðàíèöó âõîäà
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Óïðàâëåíèå ìåðîïðèÿòèÿìè
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IActionResult MyEvents(string statusFilter, string typeFilter)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
|
|
var events = APIClient.GetRequest<List<EventViewModel>>($"api/main/GetEventList?OrganizerId={APIClient.Client.Id}");
|
|
|
|
var currentDateTime = DateTime.Now;
|
|
|
|
// Ôèëüòðàöèÿ ïî ñòàòóñó
|
|
if (!string.IsNullOrEmpty(statusFilter))
|
|
{
|
|
if (statusFilter == "past")
|
|
{
|
|
events = events.Where(e => e.TimeStart < currentDateTime).ToList();
|
|
}
|
|
else if (statusFilter == "future")
|
|
{
|
|
events = events.Where(e => e.TimeStart > currentDateTime).ToList();
|
|
}
|
|
}
|
|
|
|
// Ôèëüòðàöèÿ ïî òèïó
|
|
if (!string.IsNullOrEmpty(typeFilter))
|
|
{
|
|
events = events.Where(e => e.Type.Equals(typeFilter, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
}
|
|
|
|
return View(events);
|
|
}
|
|
|
|
public IActionResult CreateEvent()
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
public IActionResult ViewEvent(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
|
|
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
|
|
|
|
return View(eventDetails);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult CreateEvent(string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime timestart, DateTime timeend)
|
|
{
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
if (timestart < DateTime.UtcNow)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Äàòà íà÷àëà íå ìîæåò áûòü â ïðîøëîì.", returnUrl });
|
|
}
|
|
|
|
if (timestart >= timeend)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Äàòà íà÷àëà íå ìîæåò áûòü ïîçæå èëè ðàâíà äàòå îêîí÷àíèÿ.", returnUrl });
|
|
}
|
|
|
|
string eventId = Guid.NewGuid().ToString();
|
|
string registrationLink = $"https://localhost:7186/registrationonevent?EventId={eventId}";
|
|
|
|
|
|
APIClient.PostRequest("api/main/createevent", new EventBindingModel
|
|
{
|
|
Name = name,
|
|
Description = description,
|
|
Type = type,
|
|
ContactPhone = phone,
|
|
Address = address,
|
|
City = city,
|
|
Status = status,
|
|
ContactEmail = email,
|
|
TimeEnd = timeend.ToUniversalTime(),
|
|
TimeStart = timestart.ToUniversalTime(),
|
|
Date = DateTime.UtcNow, // Èñïîëüçóéòå UtcNow äëÿ òåêóùåé äàòû
|
|
CountVisitors = count,
|
|
FreePlaces = count,
|
|
OrganizerId = APIClient.Client.Id,
|
|
Link = registrationLink
|
|
});
|
|
|
|
return RedirectToAction("MyEvents");
|
|
}
|
|
|
|
public IActionResult DeleteEvent(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
APIClient.PostRequest($"api/main/DeleteEvent", new EventBindingModel { Id = id });
|
|
return RedirectToAction("MyEvents");
|
|
}
|
|
|
|
public IActionResult UpdateEvent(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
|
|
|
|
return View(eventDetails);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult UpdateEvent(int id, string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime? timestart, DateTime? timeend)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Íåîáõîäèìà àâòîðèçàöèÿ");
|
|
}
|
|
var existingEvent = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
|
|
DateTime start = (timestart.HasValue) ? DateTime.SpecifyKind(timestart.Value, DateTimeKind.Utc) : existingEvent.TimeStart.ToUniversalTime();
|
|
DateTime end = (timeend.HasValue) ? DateTime.SpecifyKind(timeend.Value, DateTimeKind.Utc) : existingEvent.TimeEnd.ToUniversalTime();
|
|
int countRegisterPlace = existingEvent.CountVisitors - existingEvent.FreePlaces;
|
|
var visitorList = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
|
|
string msg = "";
|
|
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
if (timestart < DateTime.UtcNow)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Äàòà íà÷àëà íå ìîæåò áûòü â ïðîøëîì.", returnUrl });
|
|
}
|
|
|
|
if (timestart >= timeend)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Äàòà íà÷àëà íå ìîæåò áûòü ïîçæå èëè ðàâíà äàòå îêîí÷àíèÿ.", returnUrl });
|
|
}
|
|
|
|
if (existingEvent.TimeStart != timestart && existingEvent.Address != address)
|
|
{
|
|
msg = $"Âíèìàíèå! Èçìåíèëàñü äàòà íà÷àëà è àäðåññ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå íà÷íåòñÿ: {timestart} è ïðîéäåò ïî àäðåññó {address}";
|
|
|
|
}
|
|
else if(existingEvent.TimeStart == timestart && existingEvent.Address != address)
|
|
{
|
|
msg = $"Âíèìàíèå! Èçìåíèëñÿ àäðåññ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå ïðîéäåò ïî àäðåññó {address}";
|
|
}
|
|
else if(existingEvent.TimeStart != timestart && existingEvent.Address == address)
|
|
{
|
|
msg = $"Âíèìàíèå! Èçìåíèëîñü âðåìÿ íà÷àëà ìåðîïðèÿòèÿ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå íà÷íåòñÿ: {timestart}";
|
|
}
|
|
if (msg != "")
|
|
{
|
|
if (visitorList.Count != 0)
|
|
{
|
|
foreach (var visitor in visitorList)
|
|
{
|
|
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
|
|
{
|
|
MailAddress = visitor.Email,
|
|
Subject = "Èçìåíåíèÿ â ìåðîïðèÿòèè",
|
|
Text = msg
|
|
});
|
|
}
|
|
}
|
|
}
|
|
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
|
|
{
|
|
Id = id,
|
|
Name = existingEvent.Name,
|
|
Description = description,
|
|
Type = type,
|
|
ContactPhone = phone,
|
|
Address = address,
|
|
City = city,
|
|
Status = status,
|
|
ContactEmail = email,
|
|
TimeEnd = end,
|
|
TimeStart = start,
|
|
Date = DateTime.Now.ToUniversalTime(),
|
|
CountVisitors = count,
|
|
FreePlaces = count - countRegisterPlace,
|
|
OrganizerId = APIClient.Client.Id
|
|
});
|
|
return RedirectToAction("MyEvents");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Óïðàâëåíèå ïîñåòèòåëÿìè
|
|
/// </summary>
|
|
/// <param></param>
|
|
/// <returns></returns>
|
|
///
|
|
public IActionResult Visitors(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
// Ïîëó÷èòå âñåõ ïîñåòèòåëåé
|
|
var visitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
|
|
return View(visitors);
|
|
}
|
|
[HttpPost]
|
|
public IActionResult Visitors(int id, string action, string searchTerm, [FromForm] List<int> presentIds)
|
|
{
|
|
// Ïîëó÷èòå âñåõ ïîñåòèòåëåé
|
|
var visitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
|
|
var visitorsFiltered = new List<VisitorViewModel>();
|
|
|
|
// Îáðàáîòêà ïîèñêà
|
|
if (action == "search" && !string.IsNullOrEmpty(searchTerm))
|
|
{
|
|
visitorsFiltered = visitors.Where(v => v.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) ||
|
|
v.Email.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
}
|
|
|
|
// Îáðàáîòêà ñîõðàíåíèÿ ñòàòóñîâ
|
|
if (action == "save")
|
|
{
|
|
foreach (var visitor in visitors)
|
|
{
|
|
var status = presentIds.Contains(visitor.Id) ? "Ïðèøåë" : "Çàðåãèñòðèðîâàí";
|
|
APIClient.PostRequest("api/main/updatevisitor", new VisitorBindingModel
|
|
{
|
|
Id = visitor.Id,
|
|
Status = status
|
|
});
|
|
}
|
|
|
|
// Âûñâå÷èâàíèå ñòàòóñà ñîõðàíåíèÿ
|
|
TempData["SuccessMessage"] = "Ñòàòóñû ïîñåòèòåëåé óñïåøíî îáíîâëåíû.";
|
|
|
|
// Ïîñëå ñîõðàíåíèÿ ïåðåíàïðàâëÿåì îáðàòíî íà ýòîò æå ìåòîä ñ id
|
|
return RedirectToAction("Visitors", new { id });
|
|
}
|
|
|
|
// Åñëè íè÷åãî íå íàéäåíî, âåðíåì âñ¸
|
|
if (visitorsFiltered.Any())
|
|
{
|
|
return View(visitorsFiltered);
|
|
}
|
|
|
|
return View(visitors);
|
|
}
|
|
|
|
|
|
public IActionResult DeleteVisitor(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
var existingVisitor = APIClient.GetRequest<VisitorViewModel>($"api/main/GetVisitor?VisitorId={id}");
|
|
var existingEvent = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={existingVisitor.EventId}");
|
|
int eventId = existingEvent.Id;
|
|
APIClient.PostRequest($"api/main/DeleteVisitor", new VisitorBindingModel { Id = id });
|
|
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
|
|
{
|
|
Id = existingVisitor.EventId,
|
|
Name = existingEvent.Name,
|
|
Description = existingEvent.Description,
|
|
Type = existingEvent.Type,
|
|
ContactPhone = existingEvent.ContactPhone,
|
|
Address = existingEvent.Address,
|
|
City = existingEvent.City,
|
|
Status = existingEvent.Status,
|
|
ContactEmail = existingEvent.ContactEmail,
|
|
TimeEnd = existingEvent.TimeEnd,
|
|
TimeStart = existingEvent.TimeStart,
|
|
Date = existingEvent.Date.ToUniversalTime(),
|
|
CountVisitors = existingEvent.CountVisitors,
|
|
FreePlaces = existingEvent.FreePlaces + 1,
|
|
OrganizerId = APIClient.Client.Id
|
|
});
|
|
return Redirect($"~/Home/Visitors/{eventId}");
|
|
}
|
|
|
|
public IActionResult ResultRegistration()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
|
|
public IActionResult RegistrationOnEvent(int id)
|
|
{
|
|
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
|
|
|
|
return View(eventDetails);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> RegistrationOnEventAsync(int id, string name, string phone, string email, DateTime dayBirth)
|
|
{
|
|
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
if (dayBirth >= DateTime.Now)
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Íåâåðíàÿ äàòà ðîæäåíèÿ.", returnUrl });
|
|
}
|
|
if (eventDetails != null && eventDetails.FreePlaces > 0)
|
|
{
|
|
int updatedFreePlaces = eventDetails.FreePlaces - 1;
|
|
var visitorId = await APIClient.PostRequestAsync("api/main/registrationonevent", new VisitorBindingModel
|
|
{
|
|
Name = name,
|
|
Phone = phone,
|
|
Email = email,
|
|
DayBirth = dayBirth.ToUniversalTime(),
|
|
EventId = id,
|
|
Status = "Çàðåãèñòèðîâàí"
|
|
});
|
|
|
|
// 4. Îáíîâèòå êîëè÷åñòâî ñâîáîäíûõ ìåñò
|
|
APIClient.PostRequest("api/main/updateevent", new EventBindingModel
|
|
{
|
|
Id = id,
|
|
Name = eventDetails.Name,
|
|
Description = eventDetails.Description,
|
|
Type = eventDetails.Type,
|
|
ContactPhone = eventDetails.ContactPhone,
|
|
Address = eventDetails.Address,
|
|
City = eventDetails.City,
|
|
Status = eventDetails.Status,
|
|
ContactEmail = eventDetails.ContactEmail,
|
|
TimeEnd = eventDetails.TimeEnd.ToUniversalTime(),
|
|
TimeStart = eventDetails.TimeStart.ToUniversalTime(),
|
|
Date = eventDetails.Date.ToUniversalTime(),
|
|
CountVisitors = eventDetails.CountVisitors,
|
|
OrganizerId = eventDetails.OrganizerId,
|
|
Link = eventDetails.Link,
|
|
FreePlaces = updatedFreePlaces
|
|
});
|
|
|
|
string cancelLink = Url.Action("CancelRegistration", "Home", new { id = visitorId }, Request.Scheme);
|
|
|
|
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
|
|
{
|
|
MailAddress = email,
|
|
Subject = "Ðåãèñòðàöèÿ íà ìåðîïðèÿòèå",
|
|
Text = "Âû çàðåãåñòðèðîâàíû íà ìåðîïðèÿòèå " + eventDetails.Name + ", êîòîðîå ïðîéäåò " + eventDetails.TimeStart + ". Ïî àäðåñó: " + eventDetails.Address + " ã. " + eventDetails.City + ".\n" + "×òîáû îòìåíèòü ðåãèñòðàöèþ, íàæìèòå íà ñëåäóþùóþ ññûëêó:" + cancelLink + ".\n" + "Ïî âñåì âîïðîñàì ìîæíî îáðàùàòüñÿ ïî òåëåôîíó: " + eventDetails.ContactPhone + " èëè ïî ïî÷òå: " + eventDetails.ContactEmail + ".\n" + "Áóäåì æäàòü Âàñ íà íàøèõ ìåðîïðèÿòèÿõ!"
|
|
});
|
|
return Redirect("/Home/ResultRegistration");
|
|
}
|
|
else
|
|
{
|
|
return Redirect("MyEvents");
|
|
}
|
|
}
|
|
|
|
public IActionResult CancelRegistration(int id)
|
|
{
|
|
var registration = APIClient.GetRequest<VisitorBindingModel>($"api/main/GetVisitor?VisitorId={id}");
|
|
|
|
if (registration != null)
|
|
{
|
|
// Çäåñü âû íå âûïîëíÿåòå óäàëåíèå, ïîêà ïîëüçîâàòåëü íå ïîäòâåðäèò.
|
|
return View(registration);
|
|
}
|
|
return NotFound();
|
|
}
|
|
|
|
public IActionResult DeleteRegistration(int id)
|
|
{
|
|
var registration = APIClient.GetRequest<VisitorBindingModel>($"api/main/GetVisitor?VisitorId={id}");
|
|
|
|
if (registration != null)
|
|
{
|
|
APIClient.PostRequest("api/main/deleteVisitor", new VisitorBindingModel { Id = id });
|
|
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={registration.EventId}");
|
|
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
|
|
{
|
|
Id = eventDetails.Id,
|
|
Name = eventDetails.Name,
|
|
Description = eventDetails.Description,
|
|
Type = eventDetails.Type,
|
|
ContactPhone = eventDetails.ContactPhone,
|
|
Address = eventDetails.Address,
|
|
City = eventDetails.City,
|
|
Status = eventDetails.Status,
|
|
ContactEmail = eventDetails.ContactEmail,
|
|
TimeEnd = eventDetails.TimeEnd,
|
|
TimeStart = eventDetails.TimeStart,
|
|
Date = eventDetails.Date.ToUniversalTime(),
|
|
CountVisitors = eventDetails.CountVisitors,
|
|
FreePlaces = eventDetails.FreePlaces + 1,
|
|
OrganizerId = eventDetails.OrganizerId
|
|
});
|
|
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
|
|
{
|
|
MailAddress = registration.Email,
|
|
Subject = "Îòìåíà ðåãèñòðàöèè",
|
|
Text = "Âû óñïåøíî îòìåíèëè ðåãèñòðàöèþ íà ìåðîïðèÿòèå " + eventDetails.Name + "."
|
|
});
|
|
return RedirectToAction("CancellationSuccess"); // Ïåðåõîä íà ñòðàíèöó óñïåõà
|
|
}
|
|
|
|
return NotFound();
|
|
}
|
|
|
|
public IActionResult CancellationSuccess()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult ViewEvent(int id, string subject, string message)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Íåîáõîäèìà àâòîðèçàöèÿ");
|
|
}
|
|
var visitorList = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
if (visitorList.Count != 0)
|
|
{
|
|
foreach (var visitor in visitorList)
|
|
{
|
|
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
|
|
{
|
|
MailAddress = visitor.Email,
|
|
Subject = subject,
|
|
Text = message
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Error", new { errorMessage = "Åùå íåò çàðåãèñòðèðîâàííûõ ïîëüçîâàòåëåé", returnUrl });
|
|
}
|
|
APIClient.PostRequest("api/main/CreateMessage", new SentMessageBindingModel
|
|
{
|
|
Subject = subject,
|
|
Body = message,
|
|
EventId = id,
|
|
OrganizerId = APIClient.Client.Id,
|
|
SentDate = DateTime.Now.ToUniversalTime()
|
|
});
|
|
return Redirect($"/Home/ViewEvent/{id}");
|
|
}
|
|
|
|
public IActionResult MessageHistory(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
var allMessages = APIClient.GetRequest<List<SentMessageViewModel>>($"api/main/GetSentMessageList?EventId={id}");
|
|
return View(allMessages);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Îò÷åòû
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
///
|
|
[HttpPost]
|
|
public IActionResult ReportExcel(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
|
|
}
|
|
var reportFilePath = $"F:\\EventVisitor\\Report_{id}_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx";
|
|
APIClient.PostRequest("api/main/createreporttoexcelfile", new ReportVisitorsBindingModel
|
|
{
|
|
EventId = id,
|
|
FileName = reportFilePath
|
|
});
|
|
|
|
return PhysicalFile(reportFilePath, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
$"Report_{id}.xlsx");
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult ReportWord(int id)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
|
|
}
|
|
|
|
// Ñîçäàéòå îò÷åò
|
|
var reportFilePath = $"F:\\EventVisitor\\Report_{id}_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.docx";
|
|
APIClient.PostRequest("api/main/createreporttowordfile", new ReportVisitorsBindingModel
|
|
{
|
|
EventId = id,
|
|
FileName = reportFilePath
|
|
});
|
|
|
|
// Âîçâðàùàåì ôàéë è óñòàíàâëèâàåì èìÿ ôàéëà äëÿ ñîõðàíåíèÿ
|
|
return PhysicalFile(reportFilePath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
$"Report_{id}.docx");
|
|
}
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error(string errorMessage, string returnUrl)
|
|
{
|
|
ViewBag.ErrorMessage = errorMessage ?? "Ïðîèçîøëà íåèçâåñòíàÿ îøèáêà."; // Äåôîëòíîå ñîîáùåíèå
|
|
ViewBag.ReturnUrl = returnUrl; // Ñîõðàíÿåì returnUrl
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
|
|
}
|
|
}
|