160 lines
5.4 KiB
C#
160 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Church.Net.DAL.EF;
|
|
using Church.Net.Entity;
|
|
|
|
namespace Chruch.Net.Areas.dashboard.Controllers
|
|
{
|
|
public class HappinessGroupsController : Controller
|
|
{
|
|
private ChurchNetContext db = new ChurchNetContext();
|
|
|
|
// GET: dashboard/HappinessGroups
|
|
public ActionResult Index()
|
|
{
|
|
return View(db.HappinessGroups.ToList());
|
|
}
|
|
|
|
// GET: dashboard/HappinessGroups/Details/5
|
|
public ActionResult Details(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
HappinessGroup happinessGroup = db.HappinessGroups.Find(id);
|
|
if (happinessGroup == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// GET: dashboard/HappinessGroups/Create
|
|
public ActionResult Create()
|
|
{
|
|
HappinessGroup happinessGroup = new HappinessGroup();
|
|
happinessGroup.GroupId = Church.Net.Utility.Format.Get33BaseGuid();
|
|
happinessGroup.BeginTime = new DateTime(2019, 11, 01, 16, 00, 0);
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// POST: dashboard/HappinessGroups/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Create([Bind(Include = "GroupId,Name,BeginTime,Address,CityAndZipCode,InvitationText")] HappinessGroup happinessGroup)
|
|
{
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.HappinessGroups.Add(happinessGroup);
|
|
for (int i = 1; i <= 8; i++)
|
|
{
|
|
|
|
HappinessWeek week = new HappinessWeek();
|
|
week.SEQ = i;
|
|
week.Address = happinessGroup.Address;
|
|
week.Date = happinessGroup.BeginTime.AddDays((i - 1) * 7);
|
|
week.InvitationText = happinessGroup.InvitationText;
|
|
week.GroupId = happinessGroup.GroupId;
|
|
week.WeekId = Church.Net.Utility.Format.Get33BaseGuid();
|
|
db.HappinessWeeks.Add(week);
|
|
}
|
|
|
|
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// GET: dashboard/HappinessGroups/Edit/5
|
|
public ActionResult Edit(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
HappinessGroup happinessGroup = db.HappinessGroups.Find(id);
|
|
if (happinessGroup == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// POST: dashboard/HappinessGroups/Edit/5
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Edit([Bind(Include = "GroupId,Name,BeginTime,Address,CityAndZipCode,InvitationText")] HappinessGroup happinessGroup)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
|
|
db.Entry(happinessGroup).State = EntityState.Modified;
|
|
|
|
List<HappinessWeek> weeks = db.HappinessWeeks.Where(h => h.GroupId == happinessGroup.GroupId).ToList();
|
|
foreach (var item in weeks)
|
|
{
|
|
item.Address = happinessGroup.Address;
|
|
item.CityAndZipCode = happinessGroup.CityAndZipCode;
|
|
item.InvitationText = happinessGroup.InvitationText;
|
|
|
|
item.Date = happinessGroup.BeginTime.AddDays((item.SEQ - 1) * 7);
|
|
db.Entry(item).State = EntityState.Modified;
|
|
}
|
|
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// GET: dashboard/HappinessGroups/Delete/5
|
|
public ActionResult Delete(string id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
HappinessGroup happinessGroup = db.HappinessGroups.Find(id);
|
|
if (happinessGroup == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(happinessGroup);
|
|
}
|
|
|
|
// POST: dashboard/HappinessGroups/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(string id)
|
|
{
|
|
HappinessGroup happinessGroup = db.HappinessGroups.Find(id);
|
|
db.HappinessGroups.Remove(happinessGroup);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|