Beispiel #1
0
        public bool TryLoginAttempt(User t)
        {
            try
            {
                if (t.Name.Length > 20 || t.Password.Length > 20)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            database1Context    db = new database1Context();
            IQueryable <string> q  = from u in db.User where u.Name == t.Name select u.Password;

            string salt            = "WHAT IS THE NAME OF THE ";
            string encodedPassword = GetEncodedHash(t.Password, salt);

            if (q.Count() > 0)
            {
                return(q.Single() == encodedPassword);
            }
            else
            {
                t.Password = encodedPassword;
                db.User.Add(t);
                // Console.WriteLine("Sending to DB: {0}", t.ToString());
                db.SaveChanges();
                return(true);
            }
        }
Beispiel #2
0
        public bool AddMessage(ChatMessage msg)
        {
            if (msg.Body.Length > 200)
            {
                return(false);
            }

            database1Context db = new database1Context();
            IQueryable <int> q  = from r in db.User where r.Name == msg.Username select r.Id;

            if (q.Count() < 1)
            {
                return(false);
            }

            int userID = q.FirstOrDefault();

            Message t = new Message()
            {
                UserId = userID, Text = msg.Body
            };

            db.Message.Add(t);
            //Console.WriteLine("Sending to DB: {0}", t.ToString());
            db.SaveChanges();

            return(true);
        }
Beispiel #3
0
        public bool AddNewItem(ItemDetails item)
        {
            database1Context db = new database1Context();
            IQueryable <int> q  = from r in db.Item where r.Name == item.description select r.Id;

            if (q.Count() > 0)
            {
                return(false);
            }

            Item i = new Item()
            {
                Name = item.description
            };

            db.Item.Add(i);
            db.SaveChanges();

            return(true);
        }