public TrainingService(ChatContext context, ISessionsService sessionsService, IGoalsService goals) { _context = context; _sessionsService = sessionsService; _goalsService = goals; }
public static void AddMessage(Message message) //Adds message from user to contact to the DB { try { using (var ctx = new ChatContext()) { ctx.Messages.Add(message); ctx.SaveChanges(); } } catch (Exception e) { Report.log(DeviceToReport.DAL, LogLevel.Information, $"Message from {message.Sender} to {message.Receiver} was not added to DB"); Report.log(DeviceToReport.DAL, LogLevel.Information, e.Message); throw e; } }
public static List <Message> GetListOfMessages(string userA, string userB) { List <Message> messages = new List <Message>(); try { using (var ctx = new ChatContext()) { messages = ctx.Messages.Where(m => (m.Sender == userA || m.Receiver == userA) && (m.Sender == userB || m.Receiver == userB)) .ToList(); return(messages.OrderBy(m => m.SentTime).ToList()); } } catch (Exception e) { Report.log(DeviceToReport.DAL, LogLevel.Information, $"could not retrieve message between {userA} and {userB}"); Report.log(DeviceToReport.DAL, LogLevel.Information, e.Message); throw e; } }
public static List <string> GetAllUsers() { List <string> users = new List <string>(); try { using (var ctx = new ChatContext()) { foreach (User u in ctx.Users) { users.Add(u.UserName); } } return(users); } catch (Exception e) { Report.log(DeviceToReport.DAL, LogLevel.Information, "Could not get list of users from DB"); Report.log(DeviceToReport.DAL, LogLevel.Information, e.Message); throw e; } }
public static bool IsUserInDB(string userName) //Returns True if username is taken, False otherwise { try { using (var ctx = new ChatContext()) { //userName is not in DB if (ctx.Users.FirstOrDefault(u => u.UserName.ToUpper() == userName.ToUpper()) == null) { return(false); } //userName exists in DB return(true); } } catch (Exception e) { Report.log(DeviceToReport.DAL, LogLevel.Exception, $"Error while searching DB for {userName}"); Report.log(DeviceToReport.DAL, LogLevel.Exception, e.Message); throw e; } }
public SessionService(ChatContext context) { _context = context; }
public GoalsService(ChatContext context, ILogger <GoalsService> logger) { _context = context; _logger = logger; }