public ActionResult MessageAutoResponse(ResponseMessageViewModel form) { //2表示自动回复信息 每个用户在数据库只有一条对应的自动回复的信息 var data = _responseMessageRepository.Find( Specification<ResponseMessage>.Eval( o => o.ResponseType == 2 && o.UserId == WebSecurity.GetUserId(User.Identity.Name))); form.AddTime = DateTime.Now; form.UserId = WebSecurity.GetUserId(User.Identity.Name); form.ResponseType = 2; if (form.ButtonType != 0) { form.Content = ""; } if (form.ButtonType != 1) { form.ResponseMusicID = null; } if (form.ButtonType != 2) { form.ResponseImageID = null; } if (form.ButtonType != 3) { form.ResponseVideoID = null; } if (form.ButtonType != 4) { form.ResponseImageTextID = null; } if (form.ButtonType != 5) { form.Link = ""; } ResponseMessage ResponseMessage = Mapper.Map<ResponseMessageViewModel, ResponseMessage>(form); if (form.ResponseMessageID == 0 && data == null) { _responseMessageRepository.Add(ResponseMessage); _responseMessageRepository.Context.Commit(); form = Mapper.Map<ResponseMessage, ResponseMessageViewModel>(ResponseMessage); } else { data.ButtonType = form.ButtonType; data.AddTime = DateTime.Now; data.ResponseImageTextID = form.ResponseImageTextID; data.ResponseImageID = form.ResponseImageID; data.ResponseMusicID = form.ResponseMusicID; data.ResponseVideoID = form.ResponseVideoID; form.Content = form.Content ?? ""; data.Content = form.Content.Trim(); data.Link = form.Link; _responseMessageRepository.Update(data); _responseMessageRepository.Context.Commit(); form = Mapper.Map<ResponseMessage, ResponseMessageViewModel>(data); } return View(form); }
public ActionResult AddedMessageAutoResponse(ResponseMessageViewModel form) { ViewData["AddSuccessMessage"] = ""; try { //1表示被添加自动回复信息 每个用户在数据库只有一条对应的被添加自动回复的信息 var data = _responseMessageRepository.Find( Specification<ResponseMessage>.Eval( o => o.ResponseType == 1 && o.UserId == WebSecurity.GetUserId(User.Identity.Name))); form.AddTime = DateTime.Now; form.UserId = WebSecurity.GetUserId(User.Identity.Name); form.ResponseType = 1; if (form.ButtonType != 0) { form.Content = ""; } if (form.ButtonType != 1) { form.ResponseMusicID = null; } if (form.ButtonType != 2) { form.ResponseImageID = null; } if (form.ButtonType != 3) { form.ResponseVideoID = null; } if (form.ButtonType != 4) { form.ResponseImageTextID = null; } if (form.ButtonType != 5) { form.Link = ""; } ResponseMessage ResponseMessage = Mapper.Map<ResponseMessageViewModel, ResponseMessage>(form); if (form.ResponseMessageID == 0 && data == null) { _responseMessageRepository.Add(ResponseMessage); _responseMessageRepository.Context.Commit(); form = Mapper.Map<ResponseMessage, ResponseMessageViewModel>(ResponseMessage); } else { data.ButtonType = form.ButtonType; data.AddTime = DateTime.Now; data.ResponseImageTextID = form.ResponseImageTextID; data.ResponseImageID = form.ResponseImageID; data.ResponseMusicID = form.ResponseMusicID; data.ResponseVideoID = form.ResponseVideoID; data.Content = form.Content; data.Link = form.Link; _responseMessageRepository.Update(data); _responseMessageRepository.Context.Commit(); form = Mapper.Map<ResponseMessage, ResponseMessageViewModel>(data); ViewData["AddSuccessMessage"] = " ** 提交成功"; } return View(form); } catch (Exception ex) { return Json(new { ErrorMessage = ex.Message }); } }
public JsonResult GetResponseMessage(int ResponseMessageID) { var data = _responseMessageRepository.Find( Specification<ResponseMessage>.Eval(o => o.ResponseMessageID == ResponseMessageID)); ResponseMessageViewModel ResponseMessage = new ResponseMessageViewModel(); ResponseMessage.ResponseImage = Mapper.Map<ResponseImage, ResponseImageViewModel>(data.ResponseImage); ResponseMessage.ResponseImageText = Mapper.Map<ResponseImageText, ResponseImageTextViewModel>(data.ResponseImageText); ResponseMessage.ResponseMusic = Mapper.Map<ResponseMusic, ResponseMusicViewModel>(data.ResponseMusic); ResponseMessage.ResponseVideo = Mapper.Map<ResponseVideo, ResponseVideoViewModel>(data.ResponseVideo); return Json(ResponseMessage); }