Пример #1
0
        public ActionResult Create(ChatRoomUser model)
        {
            //MVC uses ModelState to track the correctness of the supplied Person "model."
            //If the model is valid, it means that MVC didn't detect any errors as defined
            //in the attributes in the Person class.
            if (ModelState.IsValid)
            {
                /*if(CurrentPicUrl != "")
                {
                    model.PicUrl = CurrentPicUrl;
                    CurrentPicUrl = "";
                }*/

                //Add the person to the DB.  This queues them for insertion but doesn't
                //actually insert the value into the DB.  For that, we need the next command.

                //model.setRandomPic();
                Db.users.Add(model);

                //tell the DB to save any queued changes.
                Db.SaveChanges();

                //Once we're done, redirect to the Index action of HomeController.
                return RedirectToAction("Login");
            }
            else
            {
                ModelState.AddModelError("", "One or more issues were found with your submission. Please try again.");
            }
            //If we got here, it means that the model's state is invalid.  Simply return
            //to the create page and display any errors.
            return View("Login", model);
        }
Пример #2
0
 public ChatMessage()
 {
     Author = new ChatRoomUser();
     Message = "";
     MessageDate = DateTime.Now;
     Room = new ChatRoom();
 }
Пример #3
0
 public ChatMessage()
 {
     Author      = new ChatRoomUser();
     Message     = "";
     MessageDate = DateTime.Now;
     Room        = new ChatRoom();
 }
Пример #4
0
        protected override void Seed(MyDbContext context)
        {
            base.Seed(context);

            ChatRoomUser admin = new ChatRoomUser();

            admin.Email     = "*****@*****.**";
            admin.FirstName = "Admin";
            admin.LastName  = "Chat";
            admin.Password  = "******";
            admin.isAdmin   = true;


            context.users.Add(admin);
            context.SaveChanges();
        }
Пример #5
0
        public ActionResult Login(ChatRoomUser model)
        {
            int uId = 0;
            bool found = false;
            Session["userid"] = null;
            Session["canwrite"] = false;
            Session["isadmin"] = false;

            foreach (ChatRoomUser p in Db.users)
            {
                if (model.Email == p.Email && model.Password == p.Password)
                {
                    uId = p.Id;

                    Session["userid"] = p.Id;
                    Session["name"] = p.FirstName + " " + p.LastName;
                    Session["login"] = true;
                    Session["ScrollHeight"] = 0;
                    if (p.Email == "*****@*****.**")
                    {
                        Session["isadmin"] = true;
                    }
                    Db.currentUser = p;
                    found = true;
                    //break;
                    foreach (ChatRoom cr in Db.chatRooms)
                    {
                        cr.isCurrent = false;
                        Db.Entry(cr).State = System.Data.Entity.EntityState.Modified;
                    }
                    Db.SaveChanges();
                }
            }
            if (!found)
            {
                foreach (string key in ModelState.Keys)
                {
                    ModelState[key].Errors.Clear();
                }

                ModelState.AddModelError("", "Invalid User Name / Password");
                return View("Login");
            }
            Db.SaveChanges();
            //return RedirectToAction("Login");
            //return View("MyBlogs", new { model = db.CurrentBlogger });
            return RedirectToAction("ChatIndex", "ChatRoom");
        }
Пример #6
0
        public ActionResult Edit(ChatRoomUser model)
        {
            //again, check modelstate to make sure everything went okay
            if (ModelState.IsValid)
            {
                //Because the item already exists in the DB, we want to tell EF that
                //one of its models has been changed.  We use this somewhat strange syntax to
                //accomplish this task.
                Db.Entry(model).State = System.Data.Entity.EntityState.Modified;

                //Again, the above command adds the request to a queue.  To execute the queue,
                //we need to call SaveChanges()
                Db.SaveChanges();

                //when complete, redirect to Index
                return RedirectToAction("Index");
            }

            //Things must've went bad, so send back to the Create view.
            return View("Create", model);
        }