示例#1
0
        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);
                }
            }
        }
示例#2
0
        /// <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);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Removing the given user from online users tabel
        /// </summary>
        /// <param name="username">Username</param>
        public void Logout(string username)
        {
            if (username != "")
            {
                OnlineUser onlineUser = dc.OnlineUsers.SingleOrDefault(x => x.Username == username);
                if (dc.OnlineUsers.Any(x => x.Username == username))
                {
                    dc.OnlineUsers.DeleteOnSubmit(onlineUser);
                    dc.SubmitChanges();

                    // Save query to log
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(DateTime.Now + " - " + username + " logged off");
                    }
                }
            }
        }