public bool DeleteNotices(NoticesModel model) { try { using (var db = new PORTALEntities()) { var item = (from c in db.SysNotices where c.Id == model.Id select c).FirstOrDefault(); if (item == null) { return(false); } item.IsDelete = true; item.DeleteDate = model.UpdateDate; item.DeleteUid = model.UpdateUid; db.SaveChanges(); return(true); } } catch (Exception ex) { LogHelper.Error("CategoryRepository Update Category: " + ex.Message + " Inner exception: " + ex.InnerException.Message); return(false); } }
public ActionResult Insert() { var model = new NoticesModel() { Active = true }; return(View(model)); }
public async Task <ActionResult> UpdateNotices(OutModels.Models.Notices n) { try { NoticesModel pcm = (NoticesModel)_mapper.Map <OutModels.Models.Notices, NoticesModel>(n); return(new JsonResult(await this._repository.Update(pcm))); } catch (Exception ex) { return(null); } }
public async Task <ActionResult> AddNotices(OutModels.Models.Notices n) { try { NoticesModel b = (NoticesModel)_mapper.Map <OutModels.Models.Notices, NoticesModel>(n); return(new JsonResult(await this._repository.Insert(b))); } catch (Exception ex) { return(null); } }
public ActionResult ForceDelete(int id) { var model = new NoticesModel() { Id = id, UpdateUid = User.GetClaimValue(ClaimTypes.PrimarySid), UpdateDate = DateTime.Now }; var repository = new NoticesRepository(); return(Json(repository.DeleteNotices(model) ? new { result = "OK" } : new { result = "ERROR" })); }
/// <summary> /// 添加通告信息(同时添加附件信息) /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool AddNotices(NoticesModel model) { int nid = Common.Instance._Notices.AddNoticesReturnID(model); //添加附件信息 if (nid > 0 && model.Attachments != null) { for (int i = 0; i < model.Attachments.Count; i++) { model.Attachments[i].ObjectID = nid.ToString(); SysattachmentsBLL.AddSysattachments(model.Attachments[i]); } } return(nid > 0); }
/// <summary> /// 查 /// </summary> /// <param name="model">empty model with key value</param> /// <returns></returns> public static NoticesModel GetNoticesInfo(NoticesModel model) { model = Common.Instance._Notices.GetNoticesInfo(model); if (model != null) { //附件 Hashtable where = new Hashtable(); where.Add(SysattachmentsArgs.ObjectID, model.NID); var list = SysattachmentsBLL.GetSysattachmentsList(where); if (list != null && list.Count > 0) { model.Attachments = list; } //创建人名 model.NCreaterName = BusinessLogic.Cache.UsersCache.GetName(model.NCreater); } return(model); }
/// <summary> /// 改 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UpdateNotices(NoticesModel model) { bool res = Common.Instance._Notices.UpdateNotices(model); if (res && model.Attachments != null && model.Attachments.Count > 0) { //增加新增的附件 for (int i = 0; i < model.Attachments.Count; i++) { if (model.Attachments[i].AID <= 0) { model.Attachments[i].ObjectID = model.NID.ToString(); SysattachmentsBLL.AddSysattachments(model.Attachments[i]); } } } return(res); }
public bool InsertNotices(NoticesModel model) { try { if (model == null) { return(false); } using (var db = new PORTALEntities()) { var result = (from l in db.SP_SYS_NOTICES_INSERT(model.Subject, model.Descript, model.Active, model.FilePath, model.FileName, model.Writer) select l).FirstOrDefault(); return(result == "OK"); } } catch (Exception ex) { LogHelper.Error("NoticesRepository Insert Notices: " + ex.Message + " Inner exception: " + ex.InnerException.Message); return(false); } }
public ActionResult Insert(NoticesModel model) { //model.Id = Guid.NewGuid(); model.UpdateUid = User.GetClaimValue(ClaimTypes.Sid); model.UpdateDate = DateTime.Now; model.Writer = User.GetClaimValue(ClaimTypes.PrimarySid); model.WriteDate = DateTime.Now; model.WriterName = User.GetClaimValue(ClaimTypes.Name); model.UpdateName = User.GetClaimValue(ClaimTypes.Name); //if (!ModelState.IsValid) // return View(); if ((new NoticesRepository()).InsertNotices(model)) { //nếu insert thành công thì copy các file đã upload sang đúng thư mục category của nó //if(!string.IsNullOrEmpty(model.FileName) && !string.IsNullOrEmpty(model.CategoryName)) //{ // var listFilePath = model.FilePath.Split('|'); // var listFileName = model.FileName.Split('|'); // for (var i = 0; i <listFileName.Length; i++) // { // if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Resources/notices/" + model.CategoryName))) // { // Directory.CreateDirectory( // System.Web.HttpContext.Current.Server.MapPath("~/Resources/notices/" + model.CategoryName)); // } // var serverPath = Request.MapPath("~" + listFilePath[i]); // if (System.IO.File.Exists(serverPath)) // { // System.IO.File.Move(serverPath, Request.MapPath(listFilePath[i].Replace("/Resources/notices/", "/Resources/notices/" + model.CategoryName + "/"))); // } // } //} } ModelState.AddModelError("InsertError", "Add new user faile! Pls contact to admin!"); MessageHelper.ShowMessage(this, "Error", "Insert fail! Pls contact to admin!", NotificationStyle.Error); return(View()); }
public string Edit(NoticesModel model) { model.UpdateUid = User.GetClaimValue(ClaimTypes.Sid); model.UpdateDate = DateTime.Now; model.Writer = User.GetClaimValue(ClaimTypes.PrimarySid); model.WriteDate = DateTime.Now; model.WriterName = User.GetClaimValue(ClaimTypes.Name); //model.ATTACH_FILE = (fileUpload[0] != null); model.UpdateName = User.GetClaimValue(ClaimTypes.Name); if ((new NoticesRepository()).UpdateNotices(model)) { //nếu update thành công thì copy các file đã upload sang đúng thư mục category của nó //if (!string.IsNullOrEmpty(model.FileName) && !string.IsNullOrEmpty(model.CategoryName)) //{ // var listFilePath = model.FilePath.Split('|'); // var listFileName = model.FileName.Split('|'); // for (var i = 0; i < listFileName.Length; i++) // { // if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Resources/notices/" + model.CategoryName))) // { // Directory.CreateDirectory( // System.Web.HttpContext.Current.Server.MapPath("~/Resources/notices/" + model.CategoryName)); // } // var serverPath = Request.MapPath("~" + listFilePath[i]); // if (System.IO.File.Exists(serverPath)) // { // System.IO.File.Move(serverPath, Request.MapPath(listFilePath[i].Replace("/Resources/notices/", "/Resources/notices/" + model.CategoryName + "/"))); // } // } //} } //MessageHelper.ShowMessage(this, "Error", "Update fail! Pls contact to admin!", NotificationStyle.Error); return("OK"); }