public JsonResult Edit(ResponseMessage ResponseMessage)
 {
     ResponseMessage.AddTime = DateTime.Now;
     _responseMessageRepository.Add(ResponseMessage);
     _responseMessageRepository.Context.Commit();
     return Json(ResponseMessage);
 }
        public ActionResult ResponseMessageSubmit(string datas)
        {
            List<ResponseMessage> responseMessages =
                Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResponseMessage>>(datas);
            List<ResponseMessage> rms;
            if (responseMessages.Count == 0)
            {
                return PartialView("ResponseMessageEdit");
            }
            if (responseMessages[0].ButtonID > 0)
            {
                var buttonId = int.Parse(responseMessages[0].ButtonID.ToString());
                rms =
                    _responseMessageRepository.FindAll().Where(s => s.ButtonID == buttonId).ToList();
            }
            else
            {
                var subButtonId = int.Parse(responseMessages[0].SubButtonID.ToString());
                rms =
                    _responseMessageRepository.FindAll().Where(s => s.SubButtonID == subButtonId).ToList();
            }
            foreach (var item in rms)
            {
                _responseMessageRepository.Remove(item);
                _responseMessageRepository.Context.Commit();
            }
            var rms2 = new List<ResponseMessage>();
            foreach (var item in responseMessages)
            {
                if (item.ButtonType != 4)
                {
                    var data = new ResponseMessage
                    {
                        ButtonType = item.ButtonType,
                        AddTime = DateTime.Now,
                        ResponseImageTextID = item.ResponseImageTextID,
                        ResponseImageID = item.ResponseImageID,
                        ResponseMusicID = item.ResponseMusicID,
                        ResponseVideoID = item.ResponseVideoID,
                        Content = item.Content,
                        Link = item.Link,
                        ButtonID = item.ButtonID == 0 ? null : item.ButtonID,
                        SubButtonID = item.SubButtonID == 0 ? null : item.SubButtonID
                    };
                    _responseMessageRepository.Add(data);
                    _responseMessageRepository.Context.Commit();
                    rms2.Add(data);
                }
                else
                {
                    item.ID = Guid.Empty;
                    item.ButtonID = item.ButtonID == 0 ? null : item.ButtonID;
                    item.SubButtonID = item.SubButtonID == 0 ? null : item.SubButtonID;
                    item.ResponseMessageID = 0;
                    item.AddTime = DateTime.Now;
                    _responseMessageRepository.Add(item);
                    _responseMessageRepository.Context.Commit();
                    item.ResponseImageText =
                        _responseImageTextRepository.Find(
                            Specification<ResponseImageText>.Eval(o => o.ResponseImageTextID == item.ResponseImageTextID));

                    rms2.Add(item);
                }
            }

            return PartialView("ResponseMessageIndex", rms2);
        }
 public JsonResult CreateOrEdit(ResponseMessage ResponseMessage)
 {
     if (!String.IsNullOrEmpty(ResponseMessage.ResponseMessageID.ToString()) &&
         ResponseMessage.ResponseMessageID != 0)
     {
         ResponseMessage RM =
             _responseMessageRepository.Find(
                 Specification<ResponseMessage>.Eval(
                     o => o.ResponseMessageID == ResponseMessage.ResponseMessageID));
         RM.ResponseVideoID = ResponseMessage.ResponseVideoID;
         RM.ResponseImageID = ResponseMessage.ResponseImageID;
         RM.ResponseImageTextID = ResponseMessage.ResponseImageTextID;
         RM.ResponseMusicID = ResponseMessage.ResponseMusicID;
         RM.Link = ResponseMessage.Link;
         RM.Content = ResponseMessage.Content;
         RM.AddTime = DateTime.Now;
         RM.ResponseType = ResponseMessage.ResponseType;
         RM.ButtonType = ResponseMessage.ButtonType;
         _responseMessageRepository.Update(RM);
         _responseMessageRepository.Context.Commit();
     }
     else
     {
         ResponseMessage.AddTime = DateTime.Now;
         _responseMessageRepository.Add(ResponseMessage);
         _responseMessageRepository.Context.Commit();
     }
     return Json(ResponseMessage);
 }