public IActionResult Doubling(int?input)
        {
            var log = new Log
            {
                CreatedAt = DateTime.Now,
                EndPoint  = "/doubling",
                Data      = $"input={input}"
            };

            logCont.logs.Add(log);
            logCont.SaveChanges();

            if (input == null)
            {
                return(new JsonResult(new
                {
                    error = "Please provide an input!"
                }));
            }
            else
            {
                return(new JsonResult(new
                {
                    received = input,
                    result = input * 2
                }));
            }
        }
 public Log Post([FromBody] Log log)
 {
     SetCurrentDateIfNull(log);
     _context.Logs.Add(log);
     _context.SaveChanges();
     return(log);
 }
Example #3
0
        public IHttpActionResult PutLogItem(long id, LogItem logItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != logItem.Id)
            {
                return(BadRequest());
            }

            db.Entry(logItem).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LogItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
 public Task LogCreate(LogModel log)
 {
     lock (locker)
     {
         context.Logs.Add(log);
         context.SaveChanges();
     }
     return(Task.CompletedTask);
 }
 public void Add(ElectCity entry)
 {
     try
     {
         _context.ElectCities.Add(entry);
         _context.SaveChanges();
     }
     catch { throw; }
 }
 public void Add(Log entry)
 {
     try
     {
         _context.Log.Add(entry);
         _context.SaveChanges();
     }
     catch { throw; }
 }
Example #7
0
        public IActionResult Accept(int EventID)
        {
            QuestionableEvent chosenEvent = _context.QuestionableEvents.Find(EventID);

            chosenEvent.status           = QuestionableEventStatus.UserAccepted;
            chosenEvent.UpdatedTimestamp = DateTime.Now;
            _context.QuestionableEvents.Update(chosenEvent);
            _context.SaveChanges();
            TempData["Alert"]   = "Success";
            TempData["Message"] = "Your response has been recorded successfully";
            return(RedirectToAction("View", new { EventID = chosenEvent.ID }));
        }
Example #8
0
 public void LogError(Type t, string Message, Exception e)
 {
     using (context)
     {
         context.Add(new LogEntry()
         {
             LogTime      = DateTime.Now,
             ErrorType    = "Error",
             ErrorMessage = Message,
             Location     = t.FullName,
             StackTrace   = e.StackTrace
         });
         context.SaveChanges();
     }
 }
Example #9
0
        public IActionResult ChangeState(int EventID)
        {
            QuestionableEvent qe = _logContext.QuestionableEvents.Find(EventID);

            if (qe.status.Equals(QuestionableEventStatus.UserAccepted) || qe.status.Equals(QuestionableEventStatus.AdminAccepted))
            {
                qe.status = QuestionableEventStatus.LockedAccepted;
            }
            else if (qe.status.Equals(QuestionableEventStatus.UserRejected) || qe.status.Equals(QuestionableEventStatus.AdminRejected))
            {
                qe.status = QuestionableEventStatus.LockedRejected;
            }
            else if (qe.status.Equals(QuestionableEventStatus.LockedAccepted) && qe.ReviewUserID > 0)
            {
                qe.status = QuestionableEventStatus.UserAccepted;
            }
            else if (qe.status.Equals(QuestionableEventStatus.LockedRejected) && qe.ReviewUserID > 0)
            {
                qe.status = QuestionableEventStatus.UserRejected;
            }
            else if (qe.status.Equals(QuestionableEventStatus.LockedAccepted))
            {
                qe.status = QuestionableEventStatus.AdminAccepted;
            }
            else if (qe.status.Equals(QuestionableEventStatus.LockedRejected))
            {
                qe.status = QuestionableEventStatus.AdminRejected;
            }
            _logContext.QuestionableEvents.Update(qe);
            _logContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void RegistarLog(ActionExecutedContext filterContext)
        {
            try
            {
                var modelJson = "";

                if (filterContext.HttpContext.Request.HttpMethod.ToLower() == "post")
                {
                    var form = Form(filterContext.HttpContext);
                    form.Remove(form.First(c => c.Key == "__RequestVerificationToken"));
                    modelJson = form.Aggregate("{", (current, item) => current + string.Format("'{0}':" + "'{1}',", item.Key, item.Value)) + "}";
                }

                var usuarioEstaAutenticado = filterContext.HttpContext.User.Identity.IsAuthenticated;

                var log = new Auditoria(
                    usuarioEstaAutenticado ? filterContext.HttpContext.User.Identity.GetUserName() : "Anonimo",
                    "Tecdisa OS",
                    GetIp(filterContext),
                    filterContext.HttpContext.Request.Url.AbsoluteUri,
                    modelJson
                    );

                _context.LogAuditoria.Add(log);
                _context.SaveChanges();
            } catch (Exception ex)
            {
                // Grava log de erro
            }
        }
Example #11
0
        // store received messages
        public static Task <bool> SaveMessageAsync(string clientId, string message)
        {
            return(Task.Run(() =>
            {
                using (var ctx = new LogContext())
                {
                    try
                    {
                        // trying save a new message to database
                        var log = new Log()
                        {
                            ClientId = clientId, Message = message, Created = DateTime.Now
                        };

                        ctx.Logs.Add(log);
                        ctx.SaveChanges();

                        return true;
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                }
            }));
        }
Example #12
0
 public void Create(string endpoint, string data)
 {
     _context.Add(new Log {
         CreatedAt = DateTime.Now, Endpoint = endpoint, Data = data
     });
     _context.SaveChanges();
 }
Example #13
0
        public void AddToDatabase()
        {
            var options = new DbContextOptionsBuilder <LogContext>()
                          .UseInMemoryDatabase(databaseName: "LogTrace")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new LogContext(options))
            {
                var log = new LogRepository(context);
                log.Add(new FileText()
                {
                    IdDocument = 1077866886, Date = DateTime.Now
                }).Wait();
                context.SaveChanges();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new LogContext(options))
            {
                var x = context.LogTraces.CountAsync().Result;
                Assert.AreEqual(1, x);
                Assert.AreEqual(1077866889, context.LogTraces.SingleAsync().Result.IdDocument);
            }
        }
Example #14
0
        public void Log(Exception ex)
        {
            try
            {
                using (var db = new LogContext())
                {
                    var request = ConfigureRequest(db);

                    var log = new ErrorLog
                    {
                        Message      = ex.Message,
                        Request      = request,
                        SessionToken = "168895.9998398.908983",
                        SystemGuid   = RequestID,
                        FullMessage  = ex.ToString(),
                        Type         = ex.GetType().ToString()
                    };
                    db.ErrorLogs.Add(log);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                // what the heck do we do when logging an error errors?
            }
        }
Example #15
0
        public void LogXml(string xml, bool isRequest = false)
        {
            try
            {
                using (var db = new LogContext())
                {
                    var request = ConfigureRequest(db);

                    var log = new XmlLog
                    {
                        Message      = "Xml record",
                        Request      = request,
                        SessionToken = "8675309",
                        SystemGuid   = RequestID,
                        Username     = "******",
                        Xml          = xml,
                        Type         = isRequest ? "Request" : "Response"
                    };
                    db.XmlLogs.Add(log);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                // do something cool
            }
        }
Example #16
0
        public JsonResult Sticker(string id)
        {
            string apiKey = System.Web.Configuration.WebConfigurationManager.AppSettings["APIKEY"];



            string url = "https://api.giphy.com/v1/stickers/translate?api_key=" + apiKey + "&s=" + id;

            Debug.WriteLine(url);


            WebRequest  request     = WebRequest.Create(url);
            WebResponse getResponce = request.GetResponse();

            Stream giphyStream = WebRequest.Create(url).GetResponse().GetResponseStream();


            var giphyData = new System.Web.Script.Serialization.JavaScriptSerializer()
                            .Deserialize <Object>(new StreamReader(giphyStream)
                                                  .ReadToEnd());



            LogData item = new LogData();

            item.IPAddress     = Request.UserHostAddress;
            item.Request       = id;
            item.ClientBrowser = Request.UserAgent;
            db.Log.Add(item);
            db.SaveChanges();

            //giphyStream.Close();

            return(Json(giphyData, JsonRequestBehavior.AllowGet));
        }
Example #17
0
 /// <summary>
 /// 创建一个对象
 /// </summary>
 /// <param name="db">数据库</param>
 /// <param name="entity">实体</param>
 public int Create(SysLogModel entity)
 {
     using (LogContext db = new LogContext())
     {
         db.SysLogs.Add(entity);
         return(db.SaveChanges());
     }
 }
Example #18
0
 public void Save(string endPoint, string data)
 {
     context.Logs.Add(new Log {
         EndPoint = endPoint,
         Data     = data
     });
     context.SaveChanges();
 }
Example #19
0
        public ActionResult <IEnumerable <string> > GetPayment(int id)
        {
            var payment = _paymentContext.Payment.Find(id);

            if (payment == null)
            {
                return(new string[] { "No payments are associated with this ID!" });
            }
            string cardNumber = maskCardNumber(payment.cardNumber);

            Log log = new Log(DateTime.Now, "Merchant viewed payment " + payment.paymentID);

            _logContext.Log.Add(log);
            _logContext.SaveChanges();

            return(new string[] { "Payment ID: " + payment.paymentID.ToString(), "Card Number: " + cardNumber, "Expiry Date: " + payment.expiryDate, "Amount " + payment.amount, "Currency: " + payment.currency, "CVV: " + payment.cvv, "Status: " + payment.status });
        }
        public IActionResult Add([FromBody] LogEntry logEntry)
        {
            _context.Logs.Add(logEntry);
            var count = _context.SaveChanges();

            _logger.LogDebug("{0} records saved to database", count);
            return(CreatedAtRoute("GetLog", new { id = logEntry.Id }, logEntry));
        }
Example #21
0
 public void Archive(string endpoint, string data)
 {
     context.Add(new Log {
         Endpoint  = endpoint,
         Data      = data,
         CreatedAt = DateTime.Now
     });
     context.SaveChanges();
 }
        public double Distance(double x1, double y1, double x2, double y2, LogContext db)
        {
            double      result = Math.Round(Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)), 2);
            DistanceLog log    = new DistanceLog(DateTime.Now, x1, y1, x2, y2, result);

            db.DistanceLogs.Add(log);
            db.SaveChanges();
            return(result);
        }
Example #23
0
        public void CreateLog(int id, string time, string message)
        {
            var log = new Log {
                Id = id, Time = time, Message = message
            };

            _logContext.Logs.Add(log);
            _logContext.SaveChanges();
        }
Example #24
0
 public static void Save(Passage passage)
 {
     using (var ctx = new LogContext())
     {
         //Passage stud = new Passage(Passage.DirectionType.IN);
         ctx.Passages.Add(passage);
         ctx.SaveChanges();
     }
 }
Example #25
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var req = GetRequestLogDto(context);

            _context.RequestLogs.Add(req);
            _context.SaveChanges();

            base.OnActionExecuting(context);
        }
Example #26
0
        public ActionResult Post([FromBody] Log log)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                ctx.Logs.Add(log);
                int r = ctx.SaveChanges();

                return(Ok(log));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #27
0
        public void Create(string endPoint, string data)
        {
            logContext.Logs.Add(new Log()
            {
                EndPoint = endPoint,
                Data     = data,
            });

            logContext.SaveChanges();
        }
Example #28
0
        public static void Writer(string query)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<LogContext, Configuration>());

            using (var db = new LogContext())
            {
                Log newLog = new Log() { LogDate = DateTime.Now, LogQuery = query };
                db.Logs.Add(newLog);
                db.SaveChanges();
            }
        }
Example #29
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<LogContext, Configuration>());

            using (var db = new LogContext())
            {
                Log test = new Log() { LogDate = DateTime.Now, LogQuery = "alabala" };
                db.Logs.Add(test);
                db.SaveChanges();
            }
        }
Example #30
0
 public void OnNext(IEnumerable <StatisticEvent> value)
 {
     using (var context = new LogContext())
     {
         foreach (var statisticEvent in value)
         {
             context.Set <StatisticEvent>().Add(statisticEvent);
         }
         context.SaveChanges();
     }
 }
Example #31
0
 public void OnNext(IEnumerable<StatisticEvent> value)
 {
     using(var context = new LogContext())
     {
         foreach (var statisticEvent in value)
         {
             
             context.Set<StatisticEvent>().Add(statisticEvent);
         }
         context.SaveChanges();
     }
 }
Example #32
0
        private void InsertLog(string LogGroup, string LogMsg, string ErrorCode)
        {
            Logs log = new Logs();

            log.LogGroup  = LogGroup;
            log.LogMsg    = LogMsg;
            log.ErrorCode = ErrorCode;
            log.LogDate   = DateTime.Now;
            log.IpAddress = Utilities.GetIp();
            _logContext.tLogs.Add(log);
            _logContext.SaveChanges();
        }
Example #33
0
        public IActionResult Index()
        {
            logContext.Logs.Add(new Log()
            {
                EndPoint = "", Data = ""
            });
            logContext.SaveChanges();

            return(File("index.html", "text/html"));
        }
    private static void UpdateXMLToLogDB(LogContext logContext, XmlNode query)
    {
        var log = new CustomLogs();
        log.Date = DateTime.Now;
        log.QueryXML = query.OuterXml;
        logContext.Logs.Add(log);
        logContext.SaveChanges();

        //The reason why I am doing the SaveChanges here is because,
        //since some exceptions are thrown in the parsing, the processed 
        //queries might never be uploaded to the server
    }