114 lines
3.7 KiB
C#
114 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Chruch.Net.Models;
|
|
using Church.Net.DAL.EF;
|
|
using Church.Net.Entity;
|
|
|
|
namespace Chruch.Net.Controllers
|
|
{
|
|
public class NewVisitorController : _BaseController
|
|
{
|
|
private ChurchNetContext db = new ChurchNetContext();
|
|
// GET: NewVisitor
|
|
public ActionResult Index(Church.Net.Entity.NewVisitor model)
|
|
{
|
|
ViewBag.ReligionId = new SelectList(db.Religions, "ReligionId", "Name");
|
|
model.Gender = Enumeration.Gender.Male;
|
|
return View(model);
|
|
}
|
|
|
|
public ActionResult Registration(Church.Net.Entity.NewVisitor model)
|
|
{
|
|
|
|
if (model != null)
|
|
{
|
|
model.Id = Church.Net.Utility.Format.Get33BaseGuid();
|
|
model.VisitingDate=DateTime.Now;
|
|
ModelState.Clear();
|
|
TryValidateModel(model);
|
|
//ValidateModel(dNSServer);
|
|
}
|
|
if (ModelState.IsValid)
|
|
{
|
|
|
|
var file = HttpContext.Request.Files["AttachFile"];
|
|
bool hasFile = file != null && !string.IsNullOrEmpty(file.FileName);
|
|
|
|
|
|
string filePath = Server.MapPath("~/NewVisitorsPics/");
|
|
//string newFileName = hasFile ? $"{model.Id}{file.FileName.Substring(file.FileName.LastIndexOf("."))}" : "";
|
|
string newFileName = hasFile ? $"{model.Id}.jpg" : "";
|
|
Directory.CreateDirectory(filePath);
|
|
|
|
try
|
|
{
|
|
|
|
var logic = new Church.Net.BLL.NewVisitorBLL(this.ConnString);
|
|
logic.Add(model);
|
|
|
|
|
|
if (hasFile)
|
|
{
|
|
Church.Net.Utility.Image.SaveThumbnail(new Bitmap(file.InputStream),
|
|
filePath + "\\" + newFileName, 1920, 1080);
|
|
|
|
//file.SaveAs(filePath + "\\" + newFileName);
|
|
|
|
}
|
|
ShowScriptMsg("一次歡迎,永遠歡迎!",MessageType.Success);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
ShowMsgByEx(e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
// return View(model);
|
|
}
|
|
[HttpGet]
|
|
public ActionResult Slider()
|
|
{
|
|
NewVisitorViewClass model = new NewVisitorViewClass()
|
|
{
|
|
BeginDate = DateTime.Today,
|
|
EndDate = DateTime.Today
|
|
};
|
|
return View("ImageTextSliderChooseDate", model);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult Slider(NewVisitorViewClass model)
|
|
{
|
|
DateTime beginDate = DateTime.Today;
|
|
DateTime endDate = DateTime.Today.AddDays(1);
|
|
beginDate = model.BeginDate;
|
|
endDate = model.EndDate.AddDays(1);
|
|
var list = new Church.Net.BLL.NewVisitorBLL(this.ConnString).GetAll(visitor =>
|
|
visitor.VisitingDate >= beginDate && visitor.VisitingDate <= endDate);
|
|
return View(list);
|
|
}
|
|
public ActionResult Today()
|
|
{
|
|
DateTime beginDate = DateTime.Today;
|
|
DateTime endDate = DateTime.Today.AddDays(1);
|
|
var list = new Church.Net.BLL.NewVisitorBLL(this.ConnString).GetAll(visitor =>
|
|
visitor.VisitingDate >= beginDate && visitor.VisitingDate <= endDate);
|
|
return View("Slider", list);
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
} |