187 lines
5.9 KiB
C#
187 lines
5.9 KiB
C#
using System;
|
|
using System.Web.Mvc;
|
|
using GZTW.AyaNova.BLL;
|
|
using ri.util;
|
|
|
|
namespace ri.Controllers
|
|
{
|
|
public class MemoController : Controller
|
|
{
|
|
#region List
|
|
//
|
|
// GET: /Memo/
|
|
public ActionResult Index()
|
|
{
|
|
ViewBag.newItemUrl = ay.genBaseSiteUrl(Url) + "Memo/Create";
|
|
ViewBag.newItemText = ay.lt("UI.Toolbar.New");
|
|
//NO MENU FOR LIST
|
|
|
|
//set rights
|
|
util.ay.setViewBagRights(ViewBag, RootObjectTypes.Memo);
|
|
|
|
return View();
|
|
}
|
|
#endregion list
|
|
|
|
#region View
|
|
//
|
|
// GET: /Memo/View/5
|
|
public ActionResult View(Guid id)
|
|
{
|
|
MemoFetcher c = MemoFetcher.GetItem(id, GZTW.AyaNova.BLL.User.CurrentUserLanguage);
|
|
if (c == null) return HttpNotFound();
|
|
formInit(c.ID);
|
|
//Since the user is about to view it, flag it as viewed
|
|
if (c.Viewed == false)
|
|
{
|
|
Memo.FlagMessageRead(c.ID);
|
|
}
|
|
//this is to prevent the save button from showing
|
|
ViewBag.ayReadOnly = true;
|
|
return View(c);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Create
|
|
//
|
|
// GET: /Memo/Create
|
|
public ActionResult Create(string m = "", string sid = "")
|
|
{
|
|
//display the form for creating a memo
|
|
formInit(Guid.Empty);
|
|
Memo newMemo = null;
|
|
ViewBag.createMode = m;
|
|
//ViewBag.SourceMemoId = sid;
|
|
if (string.IsNullOrWhiteSpace(m))
|
|
{
|
|
newMemo = GZTW.AyaNova.BLL.Memo.NewItem();
|
|
}
|
|
else
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sid))
|
|
throw new System.ArgumentException("MemoController->Create: Reply or Forward missing sid argument");
|
|
MemoFetcher sourceMemo = MemoFetcher.GetItem(new Guid(sid), GZTW.AyaNova.BLL.User.CurrentUserLanguage);
|
|
|
|
if (m == "reply")
|
|
{
|
|
ViewBag.replyToUser = sourceMemo.From;
|
|
newMemo = sourceMemo.ReplyForward(false);
|
|
}
|
|
else //it's a forward
|
|
{
|
|
newMemo = sourceMemo.ReplyForward(true);
|
|
|
|
}
|
|
}
|
|
|
|
return View(newMemo);
|
|
}
|
|
|
|
|
|
//
|
|
// POST: /Memo/Create
|
|
[HttpPost]
|
|
public ActionResult Create(FormCollection f)
|
|
{
|
|
|
|
//Parse memo info including list of recipients
|
|
//iterate through list of recipients and deliver a memo to each
|
|
string[] sTo = f["ToList"].Split(',');
|
|
string sSubject = f["Subject"];
|
|
|
|
|
|
foreach (string s in sTo)
|
|
{
|
|
try
|
|
{
|
|
Memo c = Memo.NewItem();
|
|
c.ToID = new Guid(s);
|
|
c.Subject = f["Subject"];
|
|
c.Message = ay.ParseMultiLineText("Message", f);
|
|
if (string.IsNullOrWhiteSpace(c.Subject))
|
|
c.Subject = "NO SUBJECT";
|
|
|
|
if (c.IsSavable)
|
|
c.Save();
|
|
else
|
|
{
|
|
//Broken rules
|
|
ayBrokenRules rulesError = new ayBrokenRules(c);
|
|
ViewBag.err = rulesError;
|
|
return Redirect(f["ayRetUrl"]);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ay.setGeneralError(TempData, ex);
|
|
//May not need a custom menu for this so for now keep out
|
|
//formInit(c);
|
|
return Redirect(f["ayRetUrl"]);
|
|
|
|
}
|
|
}
|
|
return Redirect(f["ayRetUrl"]);
|
|
}
|
|
#endregion create
|
|
|
|
#region Delete
|
|
//
|
|
// GET: /ClientNote/Delete/5
|
|
public ActionResult Delete(Guid id, string ayf)
|
|
{
|
|
try
|
|
{
|
|
Memo.DeleteItem(id);
|
|
return Redirect(ayf);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ay.setGeneralError(TempData, util.ay.GetSQLError(ex));
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
#endregion delete
|
|
|
|
#region Menu and rights
|
|
|
|
private void formInit(Guid currentMemoId)
|
|
{
|
|
|
|
bool isNew = currentMemoId == Guid.Empty;
|
|
|
|
//set rights
|
|
util.ay.setViewBagRights(ViewBag, RootObjectTypes.Memo);
|
|
|
|
|
|
#region Generate menu
|
|
ayMenu m = new ayMenu();
|
|
m.title = "O.Memo";
|
|
m.icon = "icon-Memo";
|
|
|
|
if (!isNew)
|
|
{
|
|
if (ViewBag.ayCanEdit)
|
|
{
|
|
m.menuItems.Add(new ayMenuItem("navitem", "UI.Toolbar.New", ay.genBaseSiteUrl(Url) + "Memo/Create", "icon-Add"));
|
|
m.menuItems.Add(new ayMenuItem("navitem", "Memo.Label.Command.Reply", ay.genBaseSiteUrl(Url) + "Memo/Create?m=reply&sid=" + currentMemoId.ToString()));
|
|
m.menuItems.Add(new ayMenuItem("navitem", "Memo.Label.Command.Forward", ay.genBaseSiteUrl(Url) + "Memo/Create?m=forward&sid=" + currentMemoId.ToString()));
|
|
}
|
|
if (ViewBag.ayCanDelete)
|
|
{
|
|
m.menuItems.Add(new ayMenuItem("divider", "", "", ""));
|
|
m.menuItems.Add(new ayMenuItem("navitem", "UI.Command.Delete", ay.genBaseSiteUrl(Url) + "Memo/Delete?id=" + currentMemoId.ToString(), "icon-Delete", ay.PromptForDelete(), "ay-set-ret-url"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ViewBag.ayMenu = m;
|
|
|
|
#endregion generate menu
|
|
}
|
|
#endregion
|
|
|
|
}//eoc
|
|
}
|