Exemplo n.º 1
0
        public void Handle(HttpListenerRequest request, HttpListenerResponse response)
        {
            using (var ms = new MemoryStream())
            {
                request.InputStream.CopyTo(ms);
                var content           = Encoding.UTF8.GetString(ms.ToArray());
                var registrationModel = JObject.Parse(content);

                var phoneNumber = registrationModel["phoneNumber"].ToString();
                var password    = registrationModel["password"].ToString();

                var user = _dbContext.ApplicationUsers.Add(new ApplicationUser()
                {
                    PhoneNumber  = phoneNumber,
                    PasswordHash = password
                });

                var mainChat = _dbContext.ChatRooms.Find(1);
                var junction = new ApplicationUserChatRoomJunction()
                {
                    ApplicationUserId     = user.Entity.Id,
                    ChatRoomId            = mainChat.Id,
                    ApplicationUserStatus = ApplicationUserInChatStatus.Active
                };

                _dbContext.ApplicationUserChatRooms.Add(junction);
                _dbContext.SaveChanges();

                response.StatusCode = 200;
                response.OutputStream.Write(Encoding.UTF8.GetBytes("OK!"));
                response.Close();
            }
        }
Exemplo n.º 2
0
        public void Handle(HttpListenerRequest request, HttpListenerResponse response)
        {
            using (var ms = new MemoryStream())
            {
                if (request.HttpMethod == "OPTIONS")
                {
                    response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
                    response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                    response.AddHeader("Access-Control-Max-Age", "1728000");
                }
                response.AppendHeader("Access-Control-Allow-Origin", "*");

                request.InputStream.CopyTo(ms);
                var content           = Encoding.UTF8.GetString(ms.ToArray());
                var registrationModel = JObject.Parse(content);

                var phoneNumber = registrationModel["phoneNumber"].ToString();
                var password    = registrationModel["password"].ToString();

                var user = _dbContext.ApplicationUsers.Add(new ApplicationUser()
                {
                    PhoneNumber  = phoneNumber,
                    PasswordHash = password
                });

                _dbContext.SaveChanges();

                var mainChat = _dbContext.ChatRooms.Find(1);
                var junction = new ApplicationUserChatRoomJunction()
                {
                    ApplicationUserId     = user.Entity.Id,
                    ChatRoomId            = mainChat.Id,
                    ApplicationUserStatus = ApplicationUserInChatStatus.Active
                };

                _dbContext.ApplicationUserChatRooms.Add(junction);
                _dbContext.SaveChanges();

                response.StatusCode = 200;
                response.OutputStream.Write(Encoding.UTF8.GetBytes("OK!"));
                response.Close();
            }
        }
Exemplo n.º 3
0
        public void Handle(HttpListenerRequest request, HttpListenerResponse response)
        {
            using (var ms = new MemoryStream())
            {
                request.InputStream.CopyTo(ms);
                var content       = Encoding.UTF8.GetString(ms.ToArray());
                var junctionModel = JObject.Parse(content);

                var sessionId       = junctionModel["SessionId"].ToString();
                var chatRoomId      = junctionModel["ChatRoomId"].ToString();
                var userPhoneNumber = junctionModel["UserPhoneNumber"].ToString();

                var user = GetUserByPhoneNumber(userPhoneNumber);

                var sender = _sessionManagementService.GetUserBySession(sessionId);

                if (sender == null || chatRoomId == null || user == null)
                {
                    response.StatusCode = 404;

                    response.OutputStream.Write(Encoding.UTF8.GetBytes("NOT FOUND!"));
                    response.Close();
                    return;
                }

                var junction = new ApplicationUserChatRoomJunction()
                {
                    ApplicationUserId     = user.Id,
                    ChatRoomId            = Int32.Parse(chatRoomId),
                    ApplicationUserStatus = ApplicationUserInChatStatus.Active
                };

                _dbContext.ApplicationUserChatRooms.Add(junction);
                _dbContext.SaveChanges();

                response.StatusCode = 200;
                response.Close();
            }
        }