public int FixThreadData(string business_id, [FromQuery] string access_token) { int count = 0; if (access_token != "@bazavietnam") { return(count); } foreach (var t in _threadService.GetThreads(business_id, "", "", "", "", "", new Paging { Limit = 100000 }).Result) { var status = string.IsNullOrWhiteSpace(t.agent_id) ? "pending" : "active"; var unread = t.sender_ext_id != t.channel_ext_id; if (t.timestamp > 9999999999 || t.status != status || t.timestamp < 99999999 || t.unread != unread) { t.unread = unread; t.status = status; count++; if (t.timestamp > 9999999999) { t.timestamp = t.timestamp / 1000; } if (t.timestamp < 99999999) { t.timestamp = t.timestamp * 1000; } _threadService.CreateThread(t, false); } } return(count); }
public IActionResult AddThread(ThreadViewModel thread, string id) { var category = _categoryService.GetCategoryById(int.Parse(id)); thread.Category = category; _threadService.CreateThread(thread); return(RedirectToAction("Category", "Category", new { category.Id })); }
public ActionResult <Thread> CreateThread([FromBody] Thread_Detail create) { Thread thread = new Thread(); thread = _ThreadService.CreateThread(create); if (thread == null) { return(BadRequest()); } return(Ok(thread)); }
public IActionResult Create(Thread thread) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { thread.User = _userService.GetUser(HttpContext.GetCurrentUserId()); var createdThreadId = _threadService.CreateThread(thread); return(RedirectToAction("Index", "Comments", new { threadId = createdThreadId })); } return(View()); }
public IActionResult AddThread2(string categoryId, string title) { ThreadViewModel thread = new ThreadViewModel(); thread.Id = Guid.NewGuid().ToString(); thread.Title = title; thread.CategoryId = categoryId; thread.DateCreated = DateTime.Now; _threadService.CreateThread(thread); return(RedirectToAction("ShowAllThreads", new { categoryId, categoryTitle = title })); }
public IActionResult Create(ThreadViewModel vm) { if (ModelState.IsValid) { var thread = _mapper.Map <Thread>(vm); _threadService.CreateThread(thread); return(RedirectToAction("List", "Thread")); } vm.Section = _sectionService.SectionList().Select(t => new SelectListItem { Value = t.Id.ToString(), Text = t.SectionName }).ToList(); return(View(vm)); }
public async Task <ActionResult <IEnumerable <Thread> > > PostNewThread(OpPost thread) { string route = Request.Path.Value; string boardName = route.Split('/').Last(); var board = await _boardService.GetBoardByName(boardName); Thread opPost = new Thread() { Content = thread.content, Subject = thread.subject, ImgUrl = thread.file.data, BoardId = board.Id, }; Thread createdThread = await _threadService.CreateThread(opPost); createdThread = await _threadService.UpdateThread(createdThread); //return CreatedAtAction(nameof(GetThreadsByBoard), new { boardName = boardName }, createdThread); return(StatusCode(201)); }
public async System.Threading.Tasks.Task SaveWebhookMessaging(ZaloMessage data, string agent_id, bool real_time_update, Channel channel) { var is_new = false; if (channel == null) { var channels = await _channelService.GetChannelsByExtId(data.oaid.ToString()); if (channels.Count > 0) { channel = channels[0]; } } if (channel == null) { return; } var customer_ext_id = ""; if (Convert.ToInt64(data.fromuid) > 0 && data.fromuid.ToString() != channel.ext_id) { customer_ext_id = data.fromuid.ToString(); } else { customer_ext_id = data.touid.ToString(); } var customer_id = CustomerService.FormatId01(channel.business_id, customer_ext_id); Customer customer = _customerService.GetById(channel.business_id, customer_id); if (customer == null) { is_new = true; } if (string.IsNullOrWhiteSpace(data.message) && string.IsNullOrWhiteSpace(data.href)) { return; } customer = await GetCustomer(channel, data, customer, customer_ext_id); //if (is_new && string.IsNullOrWhiteSpace(data.message) && string.IsNullOrWhiteSpace(data.href)) // data.message = customer.name + " cần hỗ trợ"; var message = await CreateMessage(channel, data, customer, true); var thread = await CreateThread(channel, message, customer, true); //customer.unread = false; //customer.nonreply = false; customer.active_thread = JsonConvert.SerializeObject(thread); customer.agent_id = agent_id; _customerService.CreateCustomer(customer, true); _messageService.CreateMessage(customer.business_id, message, true); _threadService.CreateThread(thread, true); }
public async Task <dynamic> SavePhoneHookData(Phone data) { try { if (data == null || string.IsNullOrWhiteSpace(data.customer_phone)) { return new { status = false } } ; var channel = _channelService.GetById(data.business_id, data.channel_id); var business = _businessService.GetById(data.business_id); var customer = await CreateCustomer(data, business, channel); if (customer == null) { return new { status = false } } ; var thread = await CreateThread(data, customer, business, channel); var messager = await CreateMessage(data, thread, customer, business, channel); if (customer != null) { customer.active_thread = JsonConvert.SerializeObject(thread); customer.agent_id = data.agent_id; } if (customer != null && thread != null && messager != null) { _customerService.CreateCustomer(customer, true); _threadService.CreateThread(thread, true); _messageService.CreateMessage(data.business_id, messager, true); return(new { type = "upsert_hibaza", data = new { status = true, customer_id = customer.id, thread_id = thread.id, message_id = messager.id, agent_id = data.agent_id } }); } else { return(new { type = "upsert_hibaza", data = new { status = false, customer_id = customer.id, thread_id = thread.id, message_id = messager.id, agent_id = data.agent_id } }); } //if (string.IsNullOrWhiteSpace(data.business_id) || string.IsNullOrWhiteSpace(data.channel_id)) //{ // var customers = await _customerService.GetCustomerFromPhone(data.customer_phone); // if (customers != null && customers.Count == 1) // { // data.business_id = customers[0].business_id; // data.channel_id = customers[0].channel_id; // } // if (customers != null && customers.Count > 1) // { // var business_id = customers[0].business_id; // var channel_id = customers[0].channel_id; // foreach (var cus in customers) // { // if (string.IsNullOrWhiteSpace(cus.business_id) && cus.business_id != business_id) // { // business_id = ""; // break; // } // } // if (!string.IsNullOrWhiteSpace(business_id)) // { // data.business_id = business_id; // data.channel_id = channel_id; // } // } //} //if (string.IsNullOrWhiteSpace(data.business_id)) //{ // return new // { // type = "upsert_hibaza", // data = new // { // status = false, // customer_id = "", // thread_id = "", // message_id = "", // agent_id = data.agent_id // } // }; //} } catch (Exception ex) { _logService.CreateAsync(new Log { name = "Webhook hotline..", message = ex.Message, details = JsonConvert.SerializeObject(ex.StackTrace) }); return(null); } }