public IHttpActionResult Post() { LineChannel ChannelObj = null; LineEvents LineEvent = null; if (ChannelObj == null) { if (LineChannel.VaridateSignature(Request, Channel_secret)) { ChannelObj = new LineChannel(Channel_Access_Token); LineEvent = JsonConvert.DeserializeObject <LineReceivedMsg>(Request.Content.ReadAsStringAsync().Result).events.FirstOrDefault(); } } if (ChannelObj == null) { return(BadRequest()); } if (LineEvent != null) { Models.LineUserSpeak dbModel = new Models.LineUserSpeak(LineEvent, ChannelObj); switch (LineEvent.type) { case EventType.message: if (LineEvent.message.type == MessageType.text) { string strLineMsg = LineEvent.message.text; if (strLineMsg == "$統計") { /*GET DATA*/ string msg = dbModel.GetReportsDefault(strConn); ChannelObj.SendReplyMessage(LineEvent.replyToken, new NewLineMessageApi.MessageObj.TextMessage(msg)); dbModel = null; } else if (strLineMsg == "$功能" || strLineMsg.ToLower() == "$menu") { NewLineMessageApi.TemplatesMsg.CarouselMessage msgObj = GetCarouselMsg(strConn, LineEvent, ChannelObj); ChannelObj.SendReplyMessage(LineEvent.replyToken, new NewLineMessageApi.MessageObj.TemplateMessage() { altText = "我要查資料", template = msgObj }); dbModel = null; } } if (dbModel != null) { /*save*/ dbModel.Save(strConn); } break; case EventType.follow: break; case EventType.unfollow: break; case EventType.join: switch (LineEvent.source.type) { case SourceType.user: break; case SourceType.group: if (LineEvent.source.groupId != "123") { ChannelObj.Leave(LineEvent.source.groupId, SourceType.group); } break; case SourceType.room: ChannelObj.Leave(LineEvent.source.roomId, SourceType.room); break; default: break; } break; case EventType.leave: break; case EventType.postback: if (LineEvent.postback.data == "統計資料日期") { if (LineEvent.postback.Params != null) { var time = LineEvent.postback.Params.date; if (time.HasValue) { ChannelObj.SendReplyMessage(LineEvent.replyToken, new NewLineMessageApi.MessageObj.TextMessage(dbModel.GetReportsDefault(strConn, time.Value))); } } } break; case EventType.beacon: break; default: break; } } return(Ok()); }
public ActionResult Add(ChannelObj model, string m) { try { menuId = SmartUtil.GetMenuId(m); ViewBag.MenuId = HttpUtility.UrlDecode(m); var errorMsg = ""; if (ModelState.IsValid) { if (model.ITBID == 0) { ViewBag.HeaderTitle = "Add Channel"; ViewBag.StatusVisible = false; ViewBag.ButtonText = "Save"; } else { //var d = _repo.GetSession(0, true); ViewBag.HeaderTitle = "Edit Channel"; ViewBag.StatusVisible = true; ViewBag.ButtonText = "Update"; } if (model.ITBID > 0) { //using (var txscope = new TransactionScope(TransactionScopeOption.RequiresNew)) //{ var BType = new SM_CHANNELSTEMP() { CODE = model.CODE, DESCRIPTION = model.DESCRIPTION, STATUS = open, RECORDID = model.ITBID, USERID = User.Identity.Name, CREATEDATE = DateTime.Now }; repoChannelTemp.Insert(BType); if (uow.Save(User.Identity.Name) > 0) { SM_AUTHLIST auth = new SM_AUTHLIST() { CREATEDATE = DateTime.Now, EVENTTYPE = model.STATUS == active ? eventEdit : model.STATUS, MENUID = menuId, //MENUNAME = "", RECORDID = BType.ITBID, STATUS = open, // TABLENAME = "ADMIN_DEPARTMENT", URL = Request.FilePath, USERID = User.Identity.Name, INSTITUTION_ITBID = institutionId, POSTTYPE = Single }; repoAuth.Insert(auth); var rst = uow.Save(User.Identity.Name) > 0 ? true : false; if (rst) { EmailerNotification.SendForAuthorization(menuId, fullName, deptCode, institutionId, "Channel Record"); TempData["msg"] = "Record Updated SuccessFully...Authorization Pending."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(RedirectToAction("Index", "Channel", new { m = m })); //return Json(new { RespCode = 0, RespMessage = "Record Updated SuccessFully...Authorization Pending." }); } else { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); //return Json(new { RespCode = 1, RespMessage = "Problem Updating Record." }); } } } else { var BType = new SM_CHANNELSTEMP() { CODE = model.CODE, DESCRIPTION = model.DESCRIPTION, STATUS = open, RECORDID = model.ITBID, USERID = User.Identity.Name, CREATEDATE = DateTime.Now }; repoChannelTemp.Insert(BType); if (uow.Save(User.Identity.Name) > 0) { //var controller = ControllerContext.Controller..ToString(); SM_AUTHLIST auth = new SM_AUTHLIST() { CREATEDATE = DateTime.Now, EVENTTYPE = eventInsert, MENUID = menuId, //MENUNAME = "", RECORDID = BType.ITBID, STATUS = open, // TABLENAME = "ADMIN_DEPARTMENT", URL = Request.FilePath, USERID = User.Identity.Name, INSTITUTION_ITBID = institutionId, POSTTYPE = Single }; repoAuth.Insert(auth); var rst = uow.Save(User.Identity.Name) > 0 ? true : false; if (rst) { //newR = 1; EmailerNotification.SendForAuthorization(menuId, fullName, deptCode, institutionId, "Channel Record"); TempData["msg"] = "Record Created SuccessFully...Authorization Pending."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(RedirectToAction("Index", new { m = m })); //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); } else { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); // return Json(new { RespCode = 1, RespMessage = "Problem Creating Record." }); } } } } // If we got this far, something failed, redisplay form //errorMsg = GetModelError(); errorMsg = ModelStateErrorHandler.StringifyModelErrors(ModelState); ViewBag.Message = errorMsg; return(View("Add", model)); } catch (SqlException ex) { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); //return Json(new { RespCode = 1, RespMessage = ex.Message }); } catch (Exception ex) { ViewBag.Message = "Problem Updating Record."; //return Json(new { RespCode = 0, RespMessage = "Record Created SuccessFully...Authorization Pending." }); return(View("Add", model)); //return Json(new { RespCode = 1, RespMessage = ex.Message }); } }