129 lines
3.8 KiB
C#
129 lines
3.8 KiB
C#
using EnVisage.Code;
|
|
using EnVisage.Code.BLL;
|
|
using EnVisage.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
|
|
namespace EnVisage.Controllers
|
|
{
|
|
public class NoteController : BaseController
|
|
{
|
|
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult List(Guid? DomainId, Guid ParentId, int NoteType)
|
|
{
|
|
NoteManager _manager = new NoteManager(DbContext);
|
|
var notes = _manager.GetNotes(DomainId, ParentId, NoteType,true);
|
|
List<object> l = new List<object>();
|
|
foreach (var note in notes)
|
|
{
|
|
var n = new
|
|
{
|
|
Id = note.Id,
|
|
ParentId = note.ParentId,
|
|
Title = note.Title,
|
|
Details = note.Details,
|
|
DateAdded = note.DateAdded.ToString("MM/dd/yyyy"),
|
|
DomainId = note.DomainId,
|
|
NoteType = note.NoteType,
|
|
CreatedBy = note.Author.UserName
|
|
};
|
|
l.Add(n);
|
|
}
|
|
var userInfo = new
|
|
{
|
|
Id = this.HttpContext.User.Identity.GetID(),
|
|
Name = this.HttpContext.User.Identity.GetUserName(),
|
|
SuperUser = false
|
|
};
|
|
var rtData = new
|
|
{
|
|
Notes = l,
|
|
UserInfo = userInfo
|
|
};
|
|
return Json(rtData);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult View(Guid NoteId)
|
|
{
|
|
NoteManager _manager = new NoteManager(DbContext);
|
|
|
|
var note=(NoteModel) _manager.Load(NoteId, false);
|
|
var n = new
|
|
{
|
|
Id = note.Id,
|
|
ParentId = note.ParentId,
|
|
Title = note.Title,
|
|
Details = note.Details,
|
|
DateAdded = note.DateAdded.ToString("MM/dd/yyyy"),
|
|
DomainId = note.DomainId,
|
|
NoteType = note.NoteType,
|
|
CreatedBy = note.Author.UserName
|
|
};
|
|
return Json(n);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult Delete(Guid NoteId)
|
|
{
|
|
using (NoteManager _manager = new NoteManager())
|
|
{
|
|
_manager.Delete(NoteId);
|
|
}
|
|
|
|
var r = new { Ok = true };
|
|
return Json(r, JsonRequestBehavior.AllowGet);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult Edit(NoteModel m)
|
|
{
|
|
using (NoteManager _manager = new NoteManager())
|
|
{
|
|
_manager.Save(m);
|
|
}
|
|
|
|
var r = new { Ok = true };
|
|
return Json(r, JsonRequestBehavior.AllowGet);
|
|
}
|
|
public ActionResult AddNote(NoteModel m)
|
|
{
|
|
List<NoteModel> notes = null;
|
|
using (NoteManager _manager = new NoteManager())
|
|
{
|
|
notes = _manager.GetNotes(m.DomainId, m.ParentId.Value, m.NoteType, false);
|
|
}
|
|
|
|
var n = new
|
|
{
|
|
ParentId = m.ParentId,
|
|
DomainId = m.DomainId,
|
|
NoteType = m.NoteType
|
|
};
|
|
if (notes.Count > 0)
|
|
return PartialView("_list", n);
|
|
else
|
|
return PartialView("_edit", n);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult Count(Guid? DomainId, Guid ParentId, int NoteType)
|
|
{
|
|
NoteManager _manager = new NoteManager(DbContext);
|
|
var notes = _manager.GetNotes(DomainId, ParentId, NoteType,false);
|
|
int count = 0;
|
|
if (notes != null)
|
|
count = notes.Count();
|
|
var r = new { count = count};
|
|
return Json(r, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
}
|
|
} |