Beispiel #1
0
        public IActionResult Post([FromBody] Message message)
        {
            if (message == null)
            {
                return(BadRequest());
            }

            db.MessagesNew.Add(message);
            db.SaveChanges();
            return(Ok(message));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "ID,Text,Date,FromUser,ToUser")] Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(message));
        }
Beispiel #3
0
        public string RemoveOneMessage()
        {
            if (IsTesting && _messages?.Messages != null && _messages.Messages.Any())
            {
                _messages.Messages.Remove(_messages.Messages.First());
                _messages.SaveChanges();
                return("Removed message");
            }


            return("not avaiable in production");
        }
Beispiel #4
0
        private static void AddAuditEvent(EventMessage message, MessagesContext dbContext)
        {
            var ae = new AuditEvent
            {
                Ip        = message.IP,
                Initiator = message.Initiator,
                Browser   = message.Browser,
                Platform  = message.Platform,
                Date      = message.Date,
                TenantId  = message.TenantId,
                UserId    = message.UserId,
                Page      = message.Page,
                Action    = (int)message.Action,
                Target    = message.Target?.ToString()
            };

            if (message.Description != null && message.Description.Any())
            {
                ae.Description =
                    JsonConvert.SerializeObject(GetSafeDescription(message.Description), new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                });
            }

            dbContext.AuditEvents.Add(ae);
            dbContext.SaveChanges();
        }
Beispiel #5
0
        private static void AddLoginEvent(EventMessage message, MessagesContext dbContext)
        {
            var le = new LoginEvents
            {
                Ip       = message.IP,
                Login    = message.Initiator,
                Browser  = message.Browser,
                Platform = message.Platform,
                Date     = message.Date,
                TenantId = message.TenantId,
                UserId   = message.UserId,
                Page     = message.Page,
                Action   = (int)message.Action
            };

            if (message.Description != null && message.Description.Any())
            {
                le.Description =
                    JsonConvert.SerializeObject(message.Description, new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                });
            }

            dbContext.LoginEvents.Add(le);
            dbContext.SaveChanges();
        }
Beispiel #6
0
        public static void Initialize(MessagesContext context)
        {
            context.Database.EnsureCreated();
            if (context.Messages.Any())
            {
                return;
            }
            var messages = new Message[]
            {
                new Message {
                    Title = "Sverige vidare i VM", Body = "Enkelt!"
                },
                new Message {
                    Title = "Microsoft köper GitHub", Body = "Hmmmmm"
                },
                new Message {
                    Title = "En elefant promenerade...", Body = "...på en liten liten spindeltråd."
                }
            };

            foreach (Message m in messages)
            {
                context.Messages.Add(m);
            }
            context.SaveChanges();
        }
Beispiel #7
0
        public async Task <MessageViewModel> SendAsync(string text, int chatID, string senderID)
        {
            Message m = new Message {
                ChatID = chatID, Content = text, UserID = senderID, When = DateTime.Now
            };

            _messages.Messages.Add(m);
            _messages.SaveChanges();
            return(await _messageConverter.ToViewModel(m));
        }
        public bool Save()
        {
            try
            {
                var changes = _messageContext.SaveChanges();

                return(changes >= 0);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error in Save()  {e.Message}");
                _logger.LogError($"Error in Save()  {e.Message}");
                return(false);
            }
        }
Beispiel #9
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Database
            var dbContext = new MessagesContext();

            dbContext.Database.EnsureCreated();
            if (!dbContext.Messages.Any())
            {
                dbContext.Messages.Add
                (
                    new Model.Message
                {
                    User    = "******",
                    Content = "Hello!"
                }
                );
            }
            dbContext.SaveChanges();

            // Exceptions in Development
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseRouting();

            // Routes
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #10
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Beispiel #11
0
 public Message Add(Message msg)
 {
     _context.Messages.Add(msg);
     _context.SaveChanges();
     return(msg);
 }