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); }
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)); }
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; } }
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 })); }
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(); } }
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 } }
// 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; } } })); }
public void Create(string endpoint, string data) { _context.Add(new Log { CreatedAt = DateTime.Now, Endpoint = endpoint, Data = data }); _context.SaveChanges(); }
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); } }
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? } }
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 } }
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)); }
/// <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()); } }
public void Save(string endPoint, string data) { context.Logs.Add(new Log { EndPoint = endPoint, Data = data }); context.SaveChanges(); }
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)); }
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); }
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(); }
public static void Save(Passage passage) { using (var ctx = new LogContext()) { //Passage stud = new Passage(Passage.DirectionType.IN); ctx.Passages.Add(passage); ctx.SaveChanges(); } }
public override void OnActionExecuting(ActionExecutingContext context) { var req = GetRequestLogDto(context); _context.RequestLogs.Add(req); _context.SaveChanges(); base.OnActionExecuting(context); }
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)); } }
public void Create(string endPoint, string data) { logContext.Logs.Add(new Log() { EndPoint = endPoint, Data = data, }); logContext.SaveChanges(); }
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(); } }
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(); } }
public void OnNext(IEnumerable <StatisticEvent> value) { using (var context = new LogContext()) { foreach (var statisticEvent in value) { context.Set <StatisticEvent>().Add(statisticEvent); } context.SaveChanges(); } }
public void OnNext(IEnumerable<StatisticEvent> value) { using(var context = new LogContext()) { foreach (var statisticEvent in value) { context.Set<StatisticEvent>().Add(statisticEvent); } context.SaveChanges(); } }
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(); }
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 }