/// <summary> /// Obtiene un ChatConfig. /// </summary> ///<param name="pChatConfig">Si se pasa nulll se retorna default</param> /// <returns>ChatConfigList</returns> /// <Date>2015-01-19T10:21:49</Date> /// <Author>moviedo</Author> public static ChatConfigBE GetByParam(Guid?chatConfigGuid) { Database dataBase = null; DbCommand cmd = null; ChatConfigBE wChatConfig = null; //try //{ dataBase = DatabaseFactory.CreateDatabase(Common.Common.EpironChatLogs_CnnStringName); using (cmd = dataBase.GetStoredProcCommand("[Chat].[ChatConfig_g]")) { if (chatConfigGuid.HasValue != false) { dataBase.AddInParameter(cmd, "ChatConfigGuid", System.Data.DbType.Guid, chatConfigGuid); } using (IDataReader reader = dataBase.ExecuteReader(cmd)) { while (reader.Read()) { wChatConfig = new ChatConfigBE(); wChatConfig.ChatConfigId = Convert.ToInt32(reader["ChatConfigId"]); wChatConfig.ChatConfigName = reader["ChatConfigName"].ToString(); wChatConfig.ChatConfigCreated = Convert.ToDateTime(reader["ChatConfigCreated"]); //wChatConfig.ChatConfigTimeOut = Convert.ToInt32(reader["ChatConfigTimeOut"]); wChatConfig.ChatConfigGuid = Guid.Parse(reader["ChatConfigGuid"].ToString()); wChatConfig.EmailAvailable = bool.Parse(reader["ChatSendEmail"].ToString()); if (reader["ChatSurveyConfigText"] != DBNull.Value) { wChatConfig.ChatSurveyConfigText = reader["ChatSurveyConfigText"].ToString(); } if (reader["ChatSurveyConfigURL"] != DBNull.Value) { wChatConfig.ChatSurveyConfigURL = reader["ChatSurveyConfigURL"].ToString(); } if (reader["ChatSurveyConfigId"] != DBNull.Value) { wChatConfig.ChatSurveyConfigId = int.Parse(reader["ChatSurveyConfigId"].ToString()); } } } } return(wChatConfig); //} //catch (Exception ex) //{ // throw Fwk.Exceptions.ExceptionHelper.ProcessException(ex); //} }
public JsonResult CreateChatRoom(ChatRoomCreationModel model) { int userId = -1; int messageId = -1; int chatRoomId = -1; int count = 0; bool EmailAvailable = false; //<-- indica si el envio de emails esta disponible bool userIsAlreadyUsed = false; //<-- indica si el usuario ya tiene un chatroom activo bool isSurveyAvailable = false; //<-- indica si las encuestas estan disponibles string surveyText = null; string surveyUrl = null; try { count = EpironChatDAC.OnlineUsers_Count(model.ChatConfigId); ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(model.ChatConfigId); isSurveyAvailable = chatConfigBE.ChatSurveyConfigId != null; surveyText = chatConfigBE.ChatSurveyConfigText; surveyUrl = chatConfigBE.ChatSurveyConfigURL; if (count == 0) { EpironChatBC.CreateChatRoom_NoOperators(model.Phone, null, string.Empty, model.InitialMessage); return(Json(new { Result = "NO-OPERATORS", EmailAvailable = chatConfigBE.EmailAvailable })); } EpironChatBC.CreateChatRoom(model, out chatRoomId, out userId, out messageId, out userIsAlreadyUsed, out EmailAvailable); if (userIsAlreadyUsed) { return(Json(new { Result = "USER-SIGNED" })); } return(Json(new { Result = "OK", userId = userId, roomId = chatRoomId, messageId = messageId, EmailAvailable = EmailAvailable, surveyText = surveyText, isSurveyAvailable = isSurveyAvailable, surveyUrl = surveyUrl })); } catch (Exception ex) { Helper.Log(ex.Message); return(Json(new { Result = "ERROR", Message = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex) })); } }
/// <summary> /// Raliza la creación de un chatRoom para un No Operators /// </summary> /// <param name="phone"></param> /// <param name="url"></param> /// <param name="@case"></param> internal static void CreateChatRoom_NoOperators(string phone, string url, string @case, string menssage) { //Busca el cliente relacionado al telefono Este debe existir int userId = EpironChatBC.CheckPhoneId(phone, String.Empty, String.Empty); ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(null); int roomId = ChatRoomDAC.CreateChatRoom(chatConfigBE.ChatConfigId, (int)Common.Enumerations.ChatRoomStatus.ClosedLoggedOutRep, @case, url); //[08:55:38 a.m.]yulygasp: se lo concatenemos al mensaje es que no podemos pasarlo en otro campo //porque el etl no esta preparado para recibirlo //model.InitialMessage = String.Concat(model.InitialMessage, "|", model.ClientName); int messageId = EpironChatBC.InsertMessage(roomId, userId, menssage, null); }
/// <summary> /// Obtiene un ChatConfig. /// </summary> ///<param name="pChatConfig">Si se pasa nulll se retorna default</param> /// <returns>ChatConfigList</returns> /// <Date>2015-01-19T10:21:49</Date> /// <Author>moviedo</Author> public static ChatConfigBE GetByParam(Guid? chatConfigGuid) { Database dataBase = null; DbCommand cmd = null; ChatConfigBE wChatConfig = null; //try //{ dataBase = DatabaseFactory.CreateDatabase(Common.Common.EpironChatLogs_CnnStringName); using (cmd = dataBase.GetStoredProcCommand("[Chat].[ChatConfig_g]")) { if (chatConfigGuid.HasValue != false) dataBase.AddInParameter(cmd, "ChatConfigGuid", System.Data.DbType.Guid, chatConfigGuid); using (IDataReader reader = dataBase.ExecuteReader(cmd)) { while (reader.Read()) { wChatConfig = new ChatConfigBE(); wChatConfig.ChatConfigId = Convert.ToInt32(reader["ChatConfigId"]); wChatConfig.ChatConfigName = reader["ChatConfigName"].ToString(); wChatConfig.ChatConfigCreated = Convert.ToDateTime(reader["ChatConfigCreated"]); //wChatConfig.ChatConfigTimeOut = Convert.ToInt32(reader["ChatConfigTimeOut"]); wChatConfig.ChatConfigGuid = Guid.Parse(reader["ChatConfigGuid"].ToString()); wChatConfig.EmailAvailable = bool.Parse(reader["ChatSendEmail"].ToString()); if (reader["ChatSurveyConfigText"] != DBNull.Value) wChatConfig.ChatSurveyConfigText = reader["ChatSurveyConfigText"].ToString(); if (reader["ChatSurveyConfigURL"] != DBNull.Value) wChatConfig.ChatSurveyConfigURL = reader["ChatSurveyConfigURL"].ToString(); if (reader["ChatSurveyConfigId"] != DBNull.Value) wChatConfig.ChatSurveyConfigId = int.Parse(reader["ChatSurveyConfigId"].ToString()); } } } return wChatConfig; //} //catch (Exception ex) //{ // throw Fwk.Exceptions.ExceptionHelper.ProcessException(ex); //} }
/// <summary> /// REaliza la creacion de chatroom nuevo. Adicionalmente verifica si existen chatrooms activos por el usuario y los cierra /// </summary> /// <param name="model"></param> /// <param name="roomId"></param> /// <param name="userId"></param> internal static void CreateChatRoom(ChatRoomCreationModel model, out int roomId, out int userId, out int messageId, out bool userIsAlreadyUsed, out bool EmailAvailable) { roomId = -1; messageId = -1; //Busca el cliente relacionado al telefono userId = EpironChatBC.CheckPhoneId(model.Phone, model.ClientName, model.ClientEmail); ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(model.ChatConfigId); userIsAlreadyUsed = GetChatRoom_IfNotExpired(userId, chatConfigBE); EmailAvailable = chatConfigBE.EmailAvailable; if (userIsAlreadyUsed) { return; } roomId = ChatRoomDAC.CreateChatRoom(chatConfigBE.ChatConfigId, (int)Common.Enumerations.ChatRoomStatus.Waiting, String.Empty, null); //[08:55:38 a.m.]yulygasp: se lo concatenemos al mensaje es que no podemos pasarlo en otro campo //porque el etl no esta preparado para recibirlo //model.InitialMessage = String.Concat(model.InitialMessage, "|", model.ClientName); messageId = EpironChatBC.InsertMessage(roomId, userId, model.InitialMessage, null); }
/// <summary> /// /// </summary> /// <returns></returns> public static List <ChatConfigBE> RetriveAll() { Database dataBase = null; DbCommand cmd = null; ChatConfigList wChatConfigList = new ChatConfigList(); ChatConfigBE wChatConfig = null; //try //{ dataBase = DatabaseFactory.CreateDatabase(Common.Common.EpironChatLogs_CnnStringName); using (cmd = dataBase.GetStoredProcCommand("[Chat].[ChatConfig_s]")) { using (IDataReader reader = dataBase.ExecuteReader(cmd)) { while (reader.Read()) { wChatConfig = new ChatConfigBE(); wChatConfig.ChatConfigId = Convert.ToInt32(reader["ChatConfigId"]); wChatConfig.ChatConfigGuid = Guid.Parse(reader["ChatConfigGuid"].ToString()); wChatConfig.ChatConfigName = reader["ChatConfigName"].ToString(); wChatConfig.ChatConfigCreated = Convert.ToDateTime(reader["ChatConfigCreated"]); //wChatConfig.ChatConfigTimeOut = Convert.ToInt32(reader["ChatConfigTimeOut"]); wChatConfigList.Add(wChatConfig); } } } return(wChatConfigList); //} //catch (Exception ex) //{ // throw Fwk.Exceptions.ExceptionHelper.ProcessException(ex); //} }
/// <summary> /// REaliza la creacion de chatroom nuevo. Adicionalmente verifica si existen chatrooms activos por el usuario y los cierra /// </summary> /// <param name="model"></param> /// <param name="roomId"></param> /// <param name="userId"></param> internal static void CreateChatRoom_FromUrl(string phone, string url, string @case, out int roomId, out int userId, out int messageId, out bool userIsAlreadyUsed) { roomId = -1; //Busca el cliente relacionado al telefono Este debe existir userId = EpironChatBC.CheckPhoneId(phone, String.Empty, String.Empty); ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(null); userIsAlreadyUsed = GetChatRoom_IfNotExpired(userId, chatConfigBE); if (userIsAlreadyUsed) { messageId = 0; return; } roomId = ChatRoomDAC.CreateChatRoom(chatConfigBE.ChatConfigId, (int)Common.Enumerations.ChatRoomStatus.Waiting, @case, url); //[08:55:38 a.m.]yulygasp: se lo concatenemos al mensaje es que no podemos pasarlo en otro campo //porque el etl no esta preparado para recibirlo //model.InitialMessage = String.Concat(model.InitialMessage, "|", model.ClientName); messageId = EpironChatBC.InsertMessage(roomId, userId, string.Empty, null); }
/// <summary> /// Este se usa para casos donde el cliente (ej TP) tienbe su propio formulario de carga de dato y genera la URL . /// /// </summary> /// <param name="model"></param> /// <param name="phone"></param> /// <param name="initialMessage"></param> /// <param name="roomId"></param> /// <param name="userId"></param> /// <author>moviedo</author> internal static void CreateChatRoom(ChatRoomFromUrlModel model, String phone, String initialMessage, out int roomId, out int userId, out int messageId, out bool userIsAlreadyUsed, out bool EmailAvailable) { roomId = -1; messageId = -1; //Busca el cliente relacionado al telefono userId = EpironChatBC.CheckPhoneId(phone, model.ClientName, model.ClientEmail); ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(model.ChatConfigId); userIsAlreadyUsed = GetChatRoom_IfNotExpired(userId, chatConfigBE); EmailAvailable = chatConfigBE.EmailAvailable; if (userIsAlreadyUsed) { return; } roomId = ChatRoomDAC.CreateChatRoom(chatConfigBE.ChatConfigId, (int)Common.Enumerations.ChatRoomStatus.Waiting, String.Empty, null); messageId = EpironChatBC.InsertMessage(roomId, userId, initialMessage, null); }
/// <summary> /// Verificar chat activos del usuario.. Chaquea si expiraron y los actualiza en la bd /// </summary> /// <param name="userId"></param> /// <param name="configBE"></param> /// <returns></returns> internal static bool GetChatRoom_IfNotExpired(int userId, ChatConfigBE configBE) { List <ActiveChatRoomBE> chatroomList = ChatRoomDAC.RetriveActiveChatRooms(userId); return(chatroomList.Count > 0); }
/// <summary> /// Verificar chat activos del usuario.. Chaquea si expiraron y los actualiza en la bd /// </summary> /// <param name="userId"></param> /// <param name="configBE"></param> /// <returns></returns> internal static bool GetChatRoom_IfNotExpired(int userId, ChatConfigBE configBE) { List<ActiveChatRoomBE> chatroomList = ChatRoomDAC.RetriveActiveChatRooms(userId); return chatroomList.Count > 0; }
public ActionResult Chatfrm(string tel, string clientName, string email, string query) { bool anyIsNull = string.IsNullOrEmpty(Request.QueryString["tel"]) || string.IsNullOrEmpty(Request.QueryString["clientName"]) || string.IsNullOrEmpty(Request.QueryString["email"]) || string.IsNullOrEmpty(Request.QueryString["query"]); if (anyIsNull) { return(RedirectToAction("Index")); } ChatRoomFromUrlModel model = new ChatRoomFromUrlModel(); int chatRoomId = -1; int userId = -1; int messageId = -1; bool userIsAlreadyUsed = false; //<-- indica si el usuario ya tiene un chatroom activo //model.Phone = tel; model.ClientName = clientName; model.ClientEmail = email; //model.InitialMessage = query; bool emailAvailable = false; //<-- indica si el envio de emails esta disponible try { if (WebChat.Common.Common.Host_Referer != null)//<--pregunto si el parametro esta configurado { if (HttpContext.Request.ServerVariables["HTTP_REFERER"] == null || !HttpContext.Request.ServerVariables["HTTP_REFERER"].Contains(WebChat.Common.Common.Host_Referer)) { Helper.Log("Ruta de acceso incorrecta, HTTP_REFERER distinto de" + WebChat.Common.Common.Host_Referer); //Registro que se ingreso por un lugar que no correspondería ChatRoomFromUrlModel mChatRoomFromUrlModel = new ChatRoomFromUrlModel(); mChatRoomFromUrlModel.HaveException = true; return(View("Chat", mChatRoomFromUrlModel)); //abro el chat pero con excepcion, para detener todo. } } ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(null); if (chatConfigBE == null) { model.IsConfigavailable = false; //<--No hay configuraciones, en el cliente se mostrara un mensaje return(View("chat", model)); } model.OperatrCount = EpironChatDAC.OnlineUsers_Count(chatConfigBE.ChatConfigGuid); if (model.OperatrCount > 0) { EpironChatBC.CreateChatRoom(model, tel, query, out chatRoomId, out userId, out messageId, out userIsAlreadyUsed, out emailAvailable); } else { EpironChatBC.CreateChatRoom_NoOperators(tel, null, string.Empty, query); } model.ChatConfigId = chatConfigBE.ChatConfigGuid; model.UserId = userId; model.RoomId = chatRoomId; model.MessageId = messageId; model.userAlreadySigned = userIsAlreadyUsed; model.IsConfigavailable = true; model.EmailAvailable = chatConfigBE.EmailAvailable; //Survey model.SurveyAvailable = chatConfigBE.ChatSurveyConfigId != null; model.ChatSurveyConfigText = chatConfigBE.ChatSurveyConfigText; model.ChatSurveyConfigURL = chatConfigBE.ChatSurveyConfigURL; model.ChatSurveyConfigId = chatConfigBE.ChatSurveyConfigId; // Busco las appSettings List <ApplicationSettingBE> wAppSettingsList = ApplicationSettingBC.SearchApplicationSetting(); model.RetriveMessage_Timer = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.RetriveMessage_Timer)).Value); model.GetRecord_Timer = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.GetRecord_Timer)).Value); model.VersionWeb = wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.VersionWeb)).Value; model.GetRecordIdTries = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.GetRecordIdTries)).Value); model.ClientInactivityTimeOut = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.ClientInactivityTimeOut)).Value) / 1000; model.GetRecord_TimeOut = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.GetRecord_TimeOut)).Value) / 1000; model.MaxLength_Message = int.Parse(wAppSettingsList.Find(x => x.SettingId.Equals((int)Enumerations.ApplicationSettingId.MaxLength_Message)).Value); //if (isAjaxCall.HasValue) // return Json(new { Result = "OK", userId = userId, roomId = chatRoomId, count = model.OperatrCount, messageId = model.MessageId }, JsonRequestBehavior.AllowGet); return(View("chat", model)); } catch (Exception ex) { Helper.Log(ex.Message); //if (isAjaxCall.HasValue) //{ // return Json(new { Result = "ERROR", Message = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex) }); //} //else //{ model.HaveException = true; return(View("chat", model)); //} } }
public ActionResult SendEmail(string cellPhone, string email, string emailBody, bool toTheClientFlag, string pGuid, int pRoomId, int pIsNoOperator) { try { ChatMailSenderBE wChatMailSenderBE = null; if (pGuid == "0") { ChatConfigBE chatConfigBE = ChatConfigDAC.GetByParam(null); wChatMailSenderBE = EpironChatEmailBC.GetChatMailSenderByCongGuid(chatConfigBE.ChatConfigGuid); } else { Guid wGuid = new Guid(pGuid); wChatMailSenderBE = EpironChatEmailBC.GetChatMailSenderByCongGuid(wGuid); } ChatUserBE wChatUserBE = new ChatUserBE(); wChatUserBE.ChatUserEmail = email; //<--usaremos el email que el usuario nos provee, aunque este tenga uno previo, no lo modificaremos en la base if (toTheClientFlag) { string css = @" <style>.bubbleOwn { position: relative; width: 60%; /*height: 35px;*/ padding: 5px; background-color: #71C837; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; left: 1px; clear: both; margin:6px 0px 1px 8px; border: 1px solid #CCC; /*min-height: 35px;*/ } .bubbleThey { position: relative; width: 60%; /*height: 35px;*/ padding: 2px; background: white; border: 1px solid #CCC; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; float: right; margin-right: 1px; clear: both; margin:6px 8px 1px 0px; /*min-height: 35px;*/ } ._time { float: right; font-size: 10px; } </style>"; emailBody = css + emailBody; } bool isSent = EmailHelper.SentEmail(emailBody, toTheClientFlag, wChatMailSenderBE, wChatUserBE); if (isSent) { //se registra en la base que se ha enviado un email ChatEmailMessageBE wChatEmailMessageBE = new ChatEmailMessageBE(); // pIsNoOperator <-- Indica si este email se envia tras no encontrar operadores disponibles wChatEmailMessageBE.ChatDescription = pIsNoOperator == 1 ? "SIN-OPERADORES" : null; wChatEmailMessageBE.EmailFrom = wChatMailSenderBE.Email; if (pRoomId != 0) { wChatEmailMessageBE.ChatRoomId = pRoomId; } else { wChatEmailMessageBE.ChatRoomId = null; } wChatEmailMessageBE.Body = emailBody; if (toTheClientFlag) { wChatEmailMessageBE.Subject = "-Subject-"; wChatEmailMessageBE.DeliveredTo = wChatUserBE.ChatUserEmail; } else { wChatEmailMessageBE.Subject = wChatMailSenderBE.TagStartWith + wChatUserBE.ChatUserEmail + wChatMailSenderBE.TagEndWith; wChatEmailMessageBE.DeliveredTo = wChatMailSenderBE.Email; } bool saved = EpironChatEmailBC.InsertChatEmailMessage(wChatEmailMessageBE); if (saved) { return(Json(new { Result = "OK", Message = "Correo enviado correctamente" })); } else { return(Json(new { Result = "OK", Message = "Error al Guardar el Email" })); //<-- Revisar si se debe o no avisar al cliente } } else { return(Json(new { Result = "OK", Message = "Error al Enviar Correo" })); //<-- Revisar si se debe o no avisar al cliente } } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex) })); } }
/// <summary> /// /// </summary> /// <returns></returns> public static List<ChatConfigBE> RetriveAll() { Database dataBase = null; DbCommand cmd = null; ChatConfigList wChatConfigList = new ChatConfigList(); ChatConfigBE wChatConfig = null; //try //{ dataBase = DatabaseFactory.CreateDatabase(Common.Common.EpironChatLogs_CnnStringName); using (cmd = dataBase.GetStoredProcCommand("[Chat].[ChatConfig_s]")) { using (IDataReader reader = dataBase.ExecuteReader(cmd)) { while (reader.Read()) { wChatConfig = new ChatConfigBE(); wChatConfig.ChatConfigId = Convert.ToInt32(reader["ChatConfigId"]); wChatConfig.ChatConfigGuid = Guid.Parse(reader["ChatConfigGuid"].ToString()); wChatConfig.ChatConfigName = reader["ChatConfigName"].ToString(); wChatConfig.ChatConfigCreated = Convert.ToDateTime(reader["ChatConfigCreated"]); //wChatConfig.ChatConfigTimeOut = Convert.ToInt32(reader["ChatConfigTimeOut"]); wChatConfigList.Add(wChatConfig); } } } return wChatConfigList; //} //catch (Exception ex) //{ // throw Fwk.Exceptions.ExceptionHelper.ProcessException(ex); //} }