Exemple #1
0
 // Отправка сообщений
 public void Send(string name, string message)
 {
     Clients.All.addMessage(name, message);
     db.Messages.Add(new Message()
     {
         SenderName = name,
         Text       = message
     });
     db.SaveChanges();
 }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                MembershipUser         user =
                    Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);

                    SignalRChatContext context = new SignalRChatContext();
                    context.Users.Add(new User
                    {
                        UserId   = new Guid(user.ProviderUserKey.ToString()),
                        Nickname = model.UserName,
                        //Email = model.Email,
                        //Phone = model.Phone
                    });
                    context.SaveChanges();

                    return(View("Start"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #3
0
        public static UserCls CreateNewUser(UserPartial iUser, SignalRChatContext iDB)
        {
            var userToAdd = new Users
            {
                Age          = iUser.age,
                CreationDate = DateTime.Now,
                FirstName    = iUser.firstName,
                LastName     = iUser.lastName,
                Phone        = iUser.phone,
                UserName     = iUser.userName,
                Icon         = iUser.icon
            };

            iDB.Users.Add(userToAdd);
            iDB.SaveChanges();

            UserCls ret = new UserCls
            {
                id        = userToAdd.UserId,
                age       = userToAdd.Age,
                firstName = iUser.firstName,
                lastName  = iUser.lastName,
                phone     = iUser.phone,
                userName  = iUser.userName,
                icon      = iUser.icon
            };

            return(ret);
        }
        public static int GenerateCodeForUser(int iUserId, SignalRChatContext iDB)
        {
            SignInCodes addObj = new SignInCodes();
            var         code   = CreateCode();

            addObj.Code       = code;
            addObj.UpdateDate = DateTime.Now;
            addObj.UserId     = iUserId;

            var ret = iDB.SignInCodes.Add(addObj);

            iDB.SaveChanges();

            return(addObj.Code);
        }
Exemple #5
0
        public static MsgObject SendMsg(int iFromUser, int iToUser, string iMsg, SignalRChatContext iDb)
        {
            var msgToAdd = new Messages();

            msgToAdd.Msg           = iMsg;
            msgToAdd.MsgFromUserId = iFromUser;
            msgToAdd.MsgToUserId   = iToUser;
            msgToAdd.SendDate      = DateTime.Now;

            iDb.Messages.Add(msgToAdd);
            iDb.SaveChanges();

            MsgObject ret = new MsgObject();

            ret.msg        = msgToAdd.Msg;
            ret.fromUserId = msgToAdd.MsgFromUserId;
            ret.toUserId   = msgToAdd.MsgToUserId;
            ret.sentDate   = msgToAdd.SendDate;

            return(ret);
        }