Ejemplo n.º 1
0
        public IActionResult MessageUser(int recipient, string message)
        {
            int?LogId = HttpContext.Session.GetInt32("UserId");

            if (LogId == null)
            {
                return(Redirect("/"));
            }
            DateTime now = DateTime.Now;

            Conversation nc = new Conversation();

            nc.RecipientId = recipient;
            nc.CreatedAt   = now;
            nc.UpdatedAt   = now;

            _context.conversations.Add(nc);
            _context.SaveChanges();

            Message nm = new Message();

            nm.Text           = message;
            nm.ConversationId = nc.ConversationId;
            nm.SenderId       = (int)LogId;
            nm.CreatedAt      = now;
            nm.UpdatedAt      = now;

            _context.messages.Add(nm);
            _context.SaveChanges();

            return(Redirect("/dashboard"));
        }
Ejemplo n.º 2
0
        public IActionResult CreateUser(RegisterUser u)
        {
            if (ModelState.IsValid)
            {
                List <User> users = _context.users.Where(nu => nu.Email == u.Email).ToList();
                if (users.Count > 0)
                {//checks for already used email
                    ViewBag.InvalidEmail = true;
                    return(View("Register"));
                }

                //generate new user
                User nUser = new User {
                    FirstName = u.FirstName, LastName = u.LastName, Email = u.Email
                };
                nUser.Password = _hasher.HashPassword(nUser, u.Password);
                if (_context.users.Count() == 0)
                {
                    nUser.UserLevel = 9;
                }
                else
                {
                    nUser.UserLevel = 1;
                }
                nUser.CreatedAt = DateTime.Now;

                _context.Add(nUser);
                _context.SaveChanges();

                HttpContext.Session.SetInt32("UserId", nUser.UserId);
                return(Redirect("/login"));
            }
            return(View("Register"));
        }