public void Login(string username, string password) { eShopDBDataContext dc = new eShopDBDataContext(); if (CheckIfUserOnline(username)) { OperationContext.Current.GetCallbackChannel <ILoginServiceCallBack>().ResponseToLogin(-2); } else { var query = from a in dc.Users where a.Username == username & a.Password == password select a.Username; if (query.Count() == 0) { OperationContext.Current.GetCallbackChannel <ILoginServiceCallBack>().ResponseToLogin(-1); } else { OnlineUser newOnlineUser = new OnlineUser() { Username = username }; // Save query to log using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(DateTime.Now + " - " + "Adding user " + username + " as online user"); } dc.OnlineUsers.InsertOnSubmit(newOnlineUser); dc.SubmitChanges(); OperationContext.Current.GetCallbackChannel <ILoginServiceCallBack>().ResponseToLogin(1); } } }
private bool CheckIfUserOnline(string username) { eShopDBDataContext dc = new eShopDBDataContext(); if (dc.OnlineUsers.Any(u => u.Username == username)) { return(true); } return(false); }
private int CheckIfUsernameExists(string username) { eShopDBDataContext dc = new eShopDBDataContext(); if (dc.Users.Any(u => u.Username == username)) { return(1); } return(-1); }
private int CheckIfIdExists(int id) { eShopDBDataContext dc = new eShopDBDataContext(); if (dc.Customers.Any(u => u.CustomerId == id)) { return(1); } return(-1); }
/// <summary> /// Checks if the business id exists /// </summary> /// <param name="id">Business Id</param> /// <returns>1 if exists, 0 otherwise</returns> private int CheckIfBusinessIdExists(int id) { eShopDBDataContext dc = new eShopDBDataContext(); if (dc.Businesses.Any(u => u.BusinessId == id)) { return(1); } return(-1); }
/// <summary> /// Creates User and Customer entities and adds them to the database /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="customerId"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="address"></param> /// <param name="phone"></param> /// <param name="accountBalance"></param> public void SignUp(string username, string password, int customerId, string firstName, string lastName, string address, string phone, int accountBalance) { eShopDBDataContext dc = new eShopDBDataContext(); if (CheckIfUsernameExists(username) == 1) { OperationContext.Current.GetCallbackChannel <ISignUpServiceCallBack>().ResponseToSignUp(-1); } else { if (CheckIfIdExists(customerId) == 1) { OperationContext.Current.GetCallbackChannel <ISignUpServiceCallBack>().ResponseToSignUp(-2); } else { User newUser = new User() { Username = username, Password = password, CustomerId = customerId }; using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(DateTime.Now + " - " + "Creating new user and new customer for " + firstName + " " + lastName); } dc.Users.InsertOnSubmit(newUser); dc.SubmitChanges(); Customer newCustomer = new Customer() { FirstName = firstName, LastName = lastName, Address = address, Phone = phone, CustomerId = customerId, AccountBalance = accountBalance }; dc.Customers.InsertOnSubmit(newCustomer); dc.SubmitChanges(); OperationContext.Current.GetCallbackChannel <ISignUpServiceCallBack>().ResponseToSignUp(1); } } }