Exemple #1
0
        public async Task MESSAGE_RECEIVED_VIEW(newMessage message)
        {
            var a = await _context.Messages.FindAsync(message.id);

            a.isViewed = true;
            _context.Messages.Update(a);
            await _context.SaveChangesAsync();
        }
Exemple #2
0
        public async Task SendMessage(string user, string message, string to)
        {
            if (message == "")
            {
                return;
            }
            ApplicationUser FirstUser = await _userManager.FindByEmailAsync(user);

            ApplicationUser SecondUser = await _userManager.FindByIdAsync(to);

            UserInfo firstUserInfo = await _context.UserInfo.FindAsync(FirstUser.Id);

            UserInfo secondUserInfo = await _context.UserInfo.FindAsync(SecondUser.Id);

            newMessage model = new newMessage
            {
                message      = message,
                id           = Guid.NewGuid().ToString(),
                firstUserId  = FirstUser.Id,
                secondUserId = SecondUser.Id,
                createDate   = DateTime.Now,
                avatar       = firstUserInfo.Avatar,
                firstId      = FirstUser.Id,
                secondId     = SecondUser.Id,
                withWhomId   = SecondUser.Id
            };

            // Добавляем диалог в таблицу бд
            if (_context.Dialogs.Where(x =>
                                       (x.firstUserId == FirstUser.Id &&
                                        x.secondUserId == to) ||
                                       (x.secondUserId == FirstUser.Id &&
                                        x.firstUserId == to)).ToList().Count() == 0)
            {
                await _context.Dialogs.AddAsync(new Dialogs
                {
                    id           = Guid.NewGuid().ToString(),
                    firstUserId  = FirstUser.Id,
                    secondUserId = SecondUser.Id,
                });
            }
            // ------------
            await _context.Messages.AddAsync(model);

            await _context.SaveChangesAsync();

            // Меняем айди на имена
            model.firstUserId  = firstUserInfo.FirstName;
            model.secondUserId = firstUserInfo.SecondName;
            await Clients.Caller.SendAsync("ReceiveMessage", model);

            await Clients.User(to).SendAsync("ReceiveMessage", model);
        }
Exemple #3
0
 private void navBarItem9_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
 {
     foreach (Control ctrl in xtraScrollableControl1.Controls)
     {
         ctrl.Dispose();
     }
     newMessage nm1 = new newMessage();
     nm1.Dock = DockStyle.Fill;
     xtraScrollableControl1.Controls.Add(nm1);
 }
Exemple #4
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Queue("messagetomom")] IAsyncCollector <newMessage> letterCollector,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            log.LogInformation($"This is req , {req}");



            /*     string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
             *   log.LogInformation("This is the request body", requestBody);
             *   var data = JsonConvert.DeserializeObject(requestBody);
             *   //TODO model HttpRequest from fields of MessageToMom*/

            string     requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            newMessage data        = JsonConvert.DeserializeObject <newMessage>(requestBody);

            /*     newMessage data = JsonConvert.DeserializeObject(requestBody);*/
            data.Greeting = data.Greeting ?? data?.Greeting;
            /*  Greeting = name ?? data?.Greeting; */

            log.LogInformation($"This is Data, {data}");

            newMessage obj = JsonConvert.DeserializeObject <newMessage>(requestBody);



            var newNote = new newMessage
            {
                Flattery = data.Flattery,
                Greeting = data.Greeting,
                HowMuch  = data.HowMuch,
                HowSoon  = data.HowSoon,
                From     = data.From
            };

            await letterCollector.AddAsync(newNote);



            /*   string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
             *
             * log.LogInformation($"This is the request body {requestBody}");
             *     Message data = JsonConvert.DeserializeObject(requestBody);
             *
             *
             *
             *
             *
             * //This is how I thought I would solve this problem.  I had a lot of trouble figuring out how to get the req.body out.
             * //I am still learning C# and it was quite different than what I have used before as far as api calls go.
             *
             * /*     var formEntryToBeParsed = [];
             *   req.Form.TryGetValue("out string", out formEntryToBeParsed);
             *   {
             *       log.LogInformation($"{formEntryToBeParsed}");
             *//* List<string> fieldToBeAssigned1 = ToString(); //Parse the string value or values
             *       string fieldToBeAssigned2; //Parse the string value or values
             *       double fieldToBeAssigned3; //Parse the string value or values
             *       DateTime fieldToBeAssigned4; //Parse the string value or value*//*
             *   }*/
            /*
             *          var message = new MessageToMom
             *          {
             *              Flattery = fieldToBeAssigned1,
             *              Greeting = fieldToBeAssigned2,
             *              HowMuch = fieldToBeAssigned3,
             *              HowSoon = fieldToBeAssigned4,
             *              From = "*****@*****.**"
             *
             *          };*/



            //Map new model values (from HttpRequest) to MessageToMom below

            /*  var message = new MessageToMom
             * {
             *    Flattery = new List<string> { "amazing", "fabulous", "profitable" },
             *    Greeting = "So Good To Hear From You",
             *    HowMuch = 1222.22M,
             *    HowSoon = DateTime.UtcNow.AddDays(1),
             *    From = "*****@*****.**"
             *
             * };
             *
             * await letterCollector.AddAsync(message);*/


            /*return new OkObjectResult(message);*/
            return((ActionResult) new OkObjectResult($"Hello, Johnny"));
        }