public User Login(string username, string password) { try { using (var db = new AppContext()) { var user = db.Users.Where(x => x.UserName == username && x.Password == password).SingleOrDefault(); if (user != null) { //Get callback funktion and update it when exists IReminderCallback callback = OperationContext.Current.GetCallbackChannel <IReminderCallback>(); if (Callbacks.ContainsKey(user.Id)) { Callbacks[user.Id] = callback; } else { Callbacks.Add(user.Id, callback); } //Update login date user.LastLoginDate = DateTime.Now; db.Entry(user).Property(x => x.LastLoginDate).IsModified = true; db.SaveChanges(); var sendNotReseivedThread = new Thread(new ThreadStart(() => ReminderManager.SendNotReseived(user.Id))); sendNotReseivedThread.IsBackground = true; sendNotReseivedThread.Start(); return(user); } else { throw new FaultException <NotCorrectUsernameOrPassword>( new NotCorrectUsernameOrPassword(string.Format("User with username '{0}' and password '{1}' was not found.", username, password)), new FaultReason("User with such username and password was not found. Please check the spelling of the username and password.")); } } } catch (FaultException <NotCorrectUsernameOrPassword> e) { throw e; } catch (Exception) { return(new User()); } }
public async Task ReminderForApps(int p_id, string app_date, string time, IReminderCallback callback) { AppointmentDetails result = new AppointmentDetails(); try { if (DBHandler.db == null) { DBHandler.DBConnection(); } var apps = await DBHandler.db.Table <Appointment>().ToListAsync(); var docs = await DBHandler.db.Table <Doctor>().ToListAsync(); var hosp = await DBHandler.db.Table <Hospital>().ToListAsync(); var details = (from a in apps join d in docs on a.DOC_ID equals d.ID join h in hosp on a.HOS_ID equals h.ID where a.APP_DATE.Equals(app_date) && DateTime.Parse(a.start_time).Subtract(DateTime.Parse(time)).Minutes == 30 //DateTime.Parse(time) select new AppointmentDetails { app_date = a.APP_DATE, doc_name = d.Name, hosp_name = h.Name, id = a.ID, location = h.Location, Timeslot = a.start_time } ); result = details.FirstOrDefault(); if (result != null) { callback.ReminderReadSuccess(result); } else { callback.ReminderReadFail(); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Appointment details select exception=" + e.Message); } }