/// <summary> /// Entity转Model /// </summary> /// <param name="entity"></param> /// <returns></returns> private UserEvent EntityToModel(CTMS_USEREVENT entity) { if (entity != null) { var model = new UserEvent() { EventID = entity.EVENTID, UserApplyId = entity.USERAPPLYID, ActionType = entity.ACTIONTYPE, ActionInfo = entity.ACTIONINFO, ReceiptTime = entity.RECEIPTTIME, EndTime = entity.ENDTIME, ActionStatus = entity.ACTIONSTATUS == null?"": EnumHelper.GetDescription((ActionStatus)int.Parse(entity.ACTIONSTATUS)), FromUser = entity.FROMUSER, ToUser = entity.TOUSER, CreateTime = entity.CREATETIME, ModelType = entity.MODELTYPE, ModelId = entity.MODELID, Remarks = entity.REMARKS, LinkUrl = entity.LINKURL }; return(model); } return(null); }
/// <summary> /// Model转Entity /// </summary> /// <param name="model"></param> /// <returns></returns> private CTMS_USEREVENT ModelToEntity(UserEvent model) { if (model != null) { var entity = new CTMS_USEREVENT() { EVENTID = model.EventID, USERAPPLYID = model.UserApplyId, ACTIONTYPE = model.ActionType, ACTIONINFO = model.ActionInfo, RECEIPTTIME = model.ReceiptTime, ENDTIME = model.EndTime, ACTIONSTATUS = model.ActionStatus, FROMUSER = model.FromUser, TOUSER = model.ToUser, CREATETIME = model.CreateTime, MODELTYPE = model.ModelType, MODELID = model.ModelId, REMARKS = model.Remarks, LINKURL = model.LinkUrl }; return(entity); } return(null); }
/// <summary> /// 更新 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Edit(UserEvent model) { if (model == null) { return(false); } using (UserEventDAL dal = new UserEventDAL()) { CTMS_USEREVENT entitys = ModelToEntity(model); return(dal.Edit(entitys)); } }
/// <summary> /// 新增 /// </summary> /// <param name="model"></param> /// <returns></returns> public string Add(UserEvent model) { if (model == null) { return(string.Empty); } using (UserEventDAL dal = new UserEventDAL()) { CTMS_USEREVENT entity = ModelToEntity(model); entity.EVENTID = string.IsNullOrEmpty(model.EventID) ? Guid.NewGuid().ToString("N") : model.EventID; return(dal.Add(entity)); } }
/// <summary> /// 修改咨询 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Edit(MyQuestion model, string eventID = "") { if (string.IsNullOrEmpty(model.ID)) { LogService.WriteInfoLog(logTitle, "试图修改为空的MyQuestion实体!"); throw new KeyNotFoundException(); } using (DbContext db = new CRDatabase()) { db.Entry(ModelToEntity(model)).State = EntityState.Modified; if (!string.IsNullOrEmpty(eventID)) { CTMS_USEREVENT userEvent = db.Set <CTMS_USEREVENT>().Find(eventID); if (userEvent != null) { userEvent.ACTIONSTATUS = "3"; userEvent.ENDTIME = model.EditTime; db.Entry(userEvent).State = EntityState.Modified; } } return(db.SaveChanges() > 0); } }