Ejemplo n.º 1
0
 public ActionResult chatpwd(int? id, string password)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Chat chat = db.chat.Find(id);
     if (chat == null)
     {
         return HttpNotFound();
     }
     else if (string.IsNullOrEmpty(password) || password != chat.password)
     {
         ViewBag.pwderror = "Invalid password";
         return RedirectToAction("chatpwd/" + chat.ID);
     }
     string currentUserId = User.Identity.GetUserId();
     var currentUser = db.Users.FirstOrDefault(x => x.Id == currentUserId);
     ChatUsers chatuser = new ChatUsers();
     db.chatuser.Add(chatuser);
     currentUser.logeduser.Add(chatuser);
     chat.logeduser.Add(chatuser);
     db.SaveChanges();
     return RedirectToAction("Details/" + id);
 }
Ejemplo n.º 2
0
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            string currentUserId = User.Identity.GetUserId();
            var currentUser = db.Users.FirstOrDefault(x => x.Id == currentUserId);
            Chat chat = db.chat.Find(id);
            if (chat == null)
            {
                return HttpNotFound();
            }

            if (db.chatuser.FirstOrDefault(ch => ch.user.Id == currentUser.Id && ch.chat.ID == id) == null)
            {
                if (string.IsNullOrEmpty(chat.password))
                {
                    ChatUsers chatuser = new ChatUsers();
                    db.chatuser.Add(chatuser);
                    currentUser.logeduser.Add(chatuser);
                    chat.logeduser.Add(chatuser);
                    db.SaveChanges();
                }
                else
                {
                    return RedirectToAction("chatpwd/" + chat.ID);
                }
            }
            return View(chat);
        }