Files
ayanova7/source/ri/ri/Controllers/ScheduleMarkerController.cs
2018-06-29 19:47:36 +00:00

173 lines
5.7 KiB
C#

using System;
using System.Web.Mvc;
using GZTW.AyaNova.BLL;
using ri.util;
namespace ri.Controllers
{
public class ScheduleMarkerController : Controller
{
#region Edit
//
// GET: /ScheduleMarker/Create
public ActionResult Create()
{
return RedirectToAction("Edit", new { id = AyaBizUtils.NewObjectGuid });
}
//
// GET: /ScheduleMarker/Edit/5
public ActionResult Edit(Guid id)
{
ScheduleMarker c = null;
if (id == AyaBizUtils.NewObjectGuid)
{
c = ScheduleMarker.NewItem();
//set some default values. Should be done in api but
//that would be a breaking change at this point and might have consequences
c.Name = DBUtil.CurrentWorkingDateTime.ToString();
c.dtStartDate = DateTime.Now;
c.dtStopDate = DateTime.Now.AddHours(2);
}
else
c = ScheduleMarker.GetItem(id);
if (c == null) return HttpNotFound();
formInit(c);
if(c.IsFollowUp)
ViewBag.titleName = NameFetcher.GetItem(c.FollowType, c.FollowID, true).RecordName;
return View(c);
}
public ActionResult Duplicate(Guid id)
{
ScheduleMarker c = ScheduleMarker.GetItem(id);
ScheduleMarker b = c.Duplicate();
b = (ScheduleMarker)b.Save();
return RedirectToAction("Edit", "ScheduleMarker", new { id = b.ID });
}
#endregion edit
#region Update
//
// POST: /ScheduleMarker/Edit/5
[HttpPost]
public ActionResult Edit(Guid id, FormCollection f)
{
ScheduleMarker c = null;
try
{
if (id == AyaBizUtils.NewObjectGuid)
c = ScheduleMarker.NewItem();
else
c = ScheduleMarker.GetItem(id);
if (c == null) return HttpNotFound();
//update all the fields from collection
c.Name = f["Name"];
ay.ParseScheduleMarkerSourceType("plSourceID", f, c);
c.Notes = ay.ParseMultiLineText("Notes", f);
c.ARGB = ay.ParseColor("ARGB", f);
c.StartDate = ay.ParseDateToDbValue("StartDate", f);
c.StopDate = ay.ParseDateToDbValue("StopDate", f);
//case 1968
c.Completed = ay.parseBool("Completed", f);
//handle update
if (!c.IsDirty) return RedirectToAction("Index");
if (c.IsSavable)
{
//all ok
c.Save();
formInit(c);
return View(c);
}
else
{
//Broken rules
ayBrokenRules rulesError = new ayBrokenRules(c);
ViewBag.err = rulesError;
formInit(c);
return View(c);
}
}
catch (Exception ex)
{
ay.setGeneralError(TempData, ex);
formInit(c);
return View(c);
}
}
#endregion update
#region Delete
//
// GET: /ScheduleMarker/Delete/5
public ActionResult Delete(Guid id, string ayf)
{
try
{
ScheduleMarker.DeleteItem(id);
return Redirect(ayf);
}
catch (Exception ex)
{
ay.setGeneralError(TempData, util.ay.GetSQLError(ex));
return RedirectToAction("Index", "Home");
}
}
#endregion delete
#region Menu and rights
private void formInit(ScheduleMarker c)
{
//set rights
util.ay.setViewBagRights(ViewBag, RootObjectTypes.ScheduleMarker);
#region Generate menu
string baseurl = ay.genBaseSiteUrl(Url);
string sId = c.ID.ToString();
ayMenu m = new ayMenu();
if (c.IsFollowUp)
{
m.title = "ScheduleMarker.Label.FollowUp";
m.icon = "icon-FollowUp";
}
else
{
m.title = "O.ScheduleMarker";
m.icon = "icon-ScheduleMarker";
}
if (!c.IsFollowUp && ViewBag.ayCanEdit)
m.menuItems.Add(new ayMenuItem("navitem", "UI.Toolbar.New", baseurl + "ScheduleMarker/Create", "icon-Duplicate"));
if (!c.IsFollowUp && c.CanDuplicate)
m.menuItems.Add(new ayMenuItem("navitem", "UI.Command.Duplicate", baseurl + "ScheduleMarker/Duplicate?id=" + sId, "icon-Duplicate"));
m.menuItems.Add(new ayMenuItem("scriptitem", "UI.Command.RecordHistory", "alert('" +
ay.RecordHistoryText(c.Creator, c.Modifier, c.Created, c.Modified) +
"')", "icon-RecordHistory"));
if (ViewBag.ayCanDelete)
{
m.menuItems.Add(new ayMenuItem("divider", "", "", ""));
m.menuItems.Add(new ayMenuItem("navitem", "UI.Command.Delete", baseurl + "ScheduleMarker/Delete?id=" + sId , "icon-Delete", ay.PromptForDelete(),"ay-set-ret-url"));
}
ViewBag.ayMenu = m;
#endregion generate menu
}
#endregion
}//eoc
}