public async Task <ActionResult> AddLine([FromBody] GetLine code)
        {
            var lineList = await db.Line.Where(c => c.LineId == code.LineId && c.ApplicationName == code.ApplicationName).Select(o => o.LineId).FirstOrDefaultAsync();

            if (lineList != code.LineId)
            {
                db.Line.Add(new Line {
                    LineId          = code.LineId,
                    ApplicationName = code.ApplicationName
                });
                await db.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <ActionResult> AddEmails([FromBody] GetEmail x)
        {
            var applist = await db.Emails.Where(m => m.Application == x.Application).Select(m => m.Application).FirstOrDefaultAsync();

            if (applist != x.Application && x.Application != null)
            {
                db.Emails.Add(new Emails {
                    Application = x.Application,
                    Email_1     = x.Email_1,
                    Email_2     = x.Email_2,
                    Email_3     = x.Email_3,
                    Enable      = x.Enable
                });
                await db.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #3
0
        public async Task <ActionResult> AddLog([FromBody] GetLogInfos x)
        {
            x.DateTime = x.DateTime.ToLocalTime();
            db.LogInfos.Add(new LogInfo {
                LogLevel    = x.LogLevel,
                Message     = x.Message,
                DateTime    = x.DateTime,
                Application = x.Application,
                Ip          = x.Ip,
                Category    = x.Catelog
            });
            var data = new LogInfo {
                LogLevel    = x.LogLevel,
                Message     = x.Message,
                DateTime    = x.DateTime,
                Application = x.Application,
                Ip          = x.Ip,
                Category    = x.Catelog
            };
            var emailList = db.Emails.Where(z => z.Enable && z.Application == data.Application).Select(m => new { m.Email_1, m.Email_2, m.Email_3 }).ToList();
            var email1    = emailList.Select(y => y.Email_1);
            var email2    = emailList.Select(y => y.Email_2);
            var email3    = emailList.Select(y => y.Email_3);
            var allEmail  = email1.Concat(email2).Concat(email3).Distinct().ToArray();

            foreach (var emails in allEmail)
            {
                email.EnqueueMail(emails);
            }
            if (data.LogLevel == LogLevel.Critical)
            {
                email.Enqueue(data);
                await SendLine(data);
            }
            await db.SaveChangesAsync();

            await hubContext.Clients.All.SendAsync("LogReceived", data);

            return(Ok());
        }