// Add your own data access methods here. If you wish to // expose your public method to a WCF service, marked them with // the attribute [NCPublish], and another T4 template will generate your service contract /// <summary> /// This method gets list of user messages as per status /// </summary> /// <param name="userID">userID</param> /// <param name="status">status</param> /// <param name="sortColName">sortColName</param> /// <param name="sortOrder">sortOrder</param> /// <returns></returns> public List <InternalUserMessage> GetUserMessages(int userID, string status, string sortColName, string sortOrder) { try { using (var unitOfWork = new EFUnitOfWork()) { var userMsgRepo = new InternalUserMessageRepository(new EFRepository <InternalUserMessage>(), unitOfWork); ObjectSet <InternalUserMessage> userMsgObjSet = ((CurrentDeskClientsEntities)userMsgRepo.Repository.UnitOfWork.Context).InternalUserMessages; //Get sort param name by reflection var sortParam = typeof(InternalUserMessage).GetProperty(sortColName); //Sort order asc if (String.Equals(sortOrder.ToLower(), "asc")) { var userMsgs = userMsgObjSet.Where(msg => msg.FK_ToUserID == userID && msg.MessageStatus == status && msg.IsDeleted == false).ToList(); return(userMsgs.OrderBy(msg => sortParam.GetValue(msg, null)).ToList()); } //Sort order desc else { var userMsgs = userMsgObjSet.Where(msg => msg.FK_ToUserID == userID && msg.MessageStatus == status && msg.IsDeleted == false).ToList(); return(userMsgs.OrderByDescending(msg => sortParam.GetValue(msg, null)).ToList()); } } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); throw; } }
/// <summary> /// This method sets IsRead value of a message to true /// </summary> /// <param name="msgID">msgID</param> public void SetMessageIsReadTrue(int msgID) { try { using (var unitOfWork = new EFUnitOfWork()) { var userMsgRepo = new InternalUserMessageRepository(new EFRepository <InternalUserMessage>(), unitOfWork); ObjectSet <InternalUserMessage> userMsgObjSet = ((CurrentDeskClientsEntities)userMsgRepo.Repository.UnitOfWork.Context).InternalUserMessages; //Get that particular msg var selectedMsg = userMsgObjSet.Where(msg => msg.PK_MessageID == msgID).FirstOrDefault(); if (selectedMsg != null) { selectedMsg.IsRead = true; userMsgRepo.Save(); } } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); throw; } }
/// <summary> /// This method sets method status to archive /// </summary> /// <param name="pkMsgIDs">pkMsgIDs</param> /// <returns></returns> public bool ArchiveSelectedMessage(string pkMsgIDs) { try { using (var unitOfWork = new EFUnitOfWork()) { var userMsgRepo = new InternalUserMessageRepository(new EFRepository <InternalUserMessage>(), unitOfWork); ObjectSet <InternalUserMessage> userMsgObjSet = ((CurrentDeskClientsEntities)userMsgRepo.Repository.UnitOfWork.Context).InternalUserMessages; //Get array of msg IDs var arrMsgIDs = pkMsgIDs.TrimEnd(',').Split(','); foreach (var msg in arrMsgIDs) { int msgID = Convert.ToInt32(msg); //Get selected msg var selectedMsg = userMsgObjSet.Where(msge => msge.PK_MessageID == msgID).FirstOrDefault(); //Update status if (selectedMsg != null) { selectedMsg.MessageStatus = "archive"; } } userMsgRepo.Save(); return(true); } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); return(false); } }
/// <summary> /// This method returns no. of new messages are there for user /// </summary> /// <param name="userID">userID</param> /// <returns></returns> public int CheckNewUserMessage(int userID) { try { using (var unitOfWork = new EFUnitOfWork()) { var userMsgRepo = new InternalUserMessageRepository(new EFRepository <InternalUserMessage>(), unitOfWork); ObjectSet <InternalUserMessage> userMsgObjSet = ((CurrentDeskClientsEntities)userMsgRepo.Repository.UnitOfWork.Context).InternalUserMessages; //Get any new messages return(userMsgObjSet.Where(msg => msg.FK_ToUserID == userID && msg.IsRead == false).Count()); } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); throw; } }