/// <summary> /// Post /// </summary> public ActionResult Post(LogInfo logInfo) { LogLogic logic = new LogLogic(); if (!ModelState.IsValid) { //return badre(ModelState); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "参数不合法")); } //检查安全密钥 if (!logic.CheckKeyIsIsValid(logInfo)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "安全密钥不匹配,请检查安全密钥!")); } #region 设置颜色 var color = "#FFFF33"; switch (logInfo.Level) { case "Error": color = "#FF3030"; break; case "Warn": color = "#FFC125"; break; case "Debug": color = "#FAEBD7"; break; case "Info": color = "#FCFCFC"; break; case "Trace": color = "#3CB371"; break; default: break; } #endregion var data = new LogAttachment() { Title = HttpUtility.UrlDecode(logInfo.Title), Text = HttpUtility.UrlDecode(logInfo.Message), Pretext = logInfo.Level, Color = color, Fallback = logInfo.Title }; return(Json(Log(data))); }
private static string Log(LogAttachment data) { string json = JsonConvert.SerializeObject(data); var bytesToPost = System.Text.Encoding.UTF8.GetBytes(json); var wc = new WebClient(); //Content-Type设置为application/json wc.Headers.Add("Content-Type", "application/json"); var responseBytes = wc.UploadData(url, "POST", bytesToPost); var responseText = System.Text.Encoding.UTF8.GetString(responseBytes); return(responseText); }
public async Task <LogAttachment> SaveLogAttachmentAsync(LogAttachment attachment, CancellationToken cancellationToken = default(CancellationToken)) { return(await _logAttachmentRepository.SaveOrUpdateAsync(attachment, cancellationToken)); }
public IActionResult NewLog(NewLogView model, IFormCollection form, ICollection <IFormFile> files) { PopulateLogViewModel(model); if (model.LogType == LogTypes.Work && String.IsNullOrWhiteSpace(form["nonUnitPersonnel"])) { model.ErrorMessage = "You need to specify at least 1 person to be part of the work log."; return(View(model)); } try { try { if (files != null && files.Any()) { foreach (var file in files) { if (file != null && !String.IsNullOrWhiteSpace(file.FileName)) { string extension = Path.GetExtension(file.FileName); if (!String.IsNullOrWhiteSpace(extension)) { extension = extension.ToLower(); } if (extension != ".jpg" && extension != ".jpeg" && extension != ".png" && extension != ".gif" && extension != ".pdf" && extension != ".doc" && extension != ".docx" && extension != ".ppt" && extension != ".pptx" && extension != ".pps" && extension != ".ppsx" && extension != ".odt" && extension != ".xls" && extension != ".xlsx" && extension != ".txt" && extension != ".rtf") { model.ErrorMessage = string.Format("File type ({0}) is not importable.", extension); } if (file.Length > 10000000) { model.ErrorMessage = "Document is too large, must be smaller then 10MB."; } } } } } catch { } if (!String.IsNullOrWhiteSpace(model.ErrorMessage)) { return(View(model)); } // Get all unit blocks in the report List <int> unitsInReport = (from object key in form.Keys where key.ToString().StartsWith("unit_personnel_") select int.Parse(key.ToString().Replace("unit_personnel_", ""))).ToList(); model.Log.LoggedByUserId = UserId; model.Log.DepartmentId = model.Department.DepartmentId; model.Log.Narrative = System.Net.WebUtility.HtmlDecode(model.Log.Narrative); model.Log.Cause = System.Net.WebUtility.HtmlDecode(model.Log.Cause); model.Log.InitialReport = System.Net.WebUtility.HtmlDecode(model.Log.InitialReport); model.Log.LogType = (int)model.LogType; if (model.Log.StationGroupId == 0) { model.Log.StationGroupId = null; } model.Log.Units = new Collection <LogUnit>(); model.Log.Users = new Collection <LogUser>(); if (String.IsNullOrWhiteSpace(model.Log.InvestigatedByUserId)) { model.Log.InvestigatedByUserId = null; } if (model.Log.StationGroupId.HasValue && model.Log.StationGroupId.Value == 0) { model.Log.StationGroupId = null; } if (model.LogType == LogTypes.Run) { if (model.CallId == 0) { model.Call.DepartmentId = DepartmentId; model.Call.ReportingUserId = UserId; model.Call.Priority = (int)model.CallPriority; if (model.Call.Type == "No Type") { model.Call.Type = null; } model.Call = _callsService.SaveCall(model.Call); model.Log.CallId = model.Call.CallId; model.Log.StartedOn = model.Call.LoggedOn; } else { var call = _callsService.GetCallById(model.CallId); call.Priority = (int)model.CallPriority; call.NatureOfCall = model.Call.NatureOfCall; call.Address = model.Call.Address; call.LoggedOn = model.Call.LoggedOn; call.Name = model.Call.Name; model.Call = _callsService.SaveCall(call); model.Log.CallId = model.Call.CallId; } } if (model.LogType == LogTypes.Work) { var startedOn = form["Log.StartedOn"]; var endedOn = form["Log.EndedOn"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(endedOn)) { model.Log.EndedOn = DateTime.Parse(endedOn); } } if (model.LogType == LogTypes.Meeting) { var startedOn = form["Log.StartedOn"]; var endedOn = form["Log.EndedOn"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(endedOn)) { model.Log.EndedOn = DateTime.Parse(endedOn); } } if (model.LogType == LogTypes.Coroner) { var startedOn = form["coronerDate"]; var caseNumber = form["caseNumber"]; var coronerInstructors = form["coronerInstructors"]; var coronerDestination = form["coronerDestination"]; var coronerOthers = form["coronerOthers"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(caseNumber)) { model.Log.ExternalId = caseNumber; } if (!String.IsNullOrWhiteSpace(coronerInstructors)) { model.Log.Instructors = coronerInstructors; } if (!String.IsNullOrWhiteSpace(coronerDestination)) { model.Log.Location = coronerDestination; } if (!String.IsNullOrWhiteSpace(coronerOthers)) { model.Log.OtherPersonnel = coronerOthers; } } foreach (var i in unitsInReport) { var unit = new LogUnit(); unit.UnitId = i; if (!string.IsNullOrWhiteSpace(form["unit_dispatchtime_" + i])) { unit.Dispatched = DateTime.Parse(form["unit_dispatchtime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_enroutetime_" + i])) { unit.Enroute = DateTime.Parse(form["unit_enroutetime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_onscenetime_" + i])) { unit.OnScene = DateTime.Parse(form["unit_onscenetime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_releasedtime_" + i])) { unit.Released = DateTime.Parse(form["unit_releasedtime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_inquarterstime_" + i])) { unit.InQuarters = DateTime.Parse(form["unit_inquarterstime_" + i]); } model.Log.Units.Add(unit); if (!string.IsNullOrWhiteSpace(form["unit_personnel_" + i])) { var personnelIds = form["unit_personnel_" + i].ToString().Split(char.Parse(",")); foreach (var personnelId in personnelIds) { var logUser = new LogUser(); logUser.UserId = personnelId; logUser.UnitId = i; model.Log.Users.Add(logUser); } } } if (!string.IsNullOrWhiteSpace(form["nonUnitPersonnel"])) { var personnelIds = form["nonUnitPersonnel"].ToString().Split(char.Parse(",")); foreach (var personnelId in personnelIds) { var logUser = new LogUser(); logUser.UserId = personnelId; model.Log.Users.Add(logUser); } } var savedLog = _workLogsService.SaveLog(model.Log); try { if (files != null) { foreach (var file in files) { if (file != null && file.Length > 0) { LogAttachment attachment = new LogAttachment(); attachment.LogId = savedLog.LogId; attachment.Type = file.ContentType; attachment.FileName = file.FileName; byte[] uploadedFile = new byte[file.OpenReadStream().Length]; file.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length); attachment.Data = uploadedFile; attachment.UserId = UserId; attachment.Timestamp = DateTime.UtcNow; _workLogsService.SaveLogAttachment(attachment); } } } } catch { } _eventAggregator.SendMessage <LogAddedEvent>(new LogAddedEvent() { DepartmentId = DepartmentId, Log = model.Log }); } catch (Exception ex) { Logging.LogException(ex); model.ErrorMessage = "We encountered an error trying to save your log. Please check your form to ensure it's properly filled out and try again."; return(View(model)); } return(RedirectToAction("Index")); }
public LogAttachment SaveLogAttachment(LogAttachment attachment) { _logAttachmentRepository.SaveOrUpdate(attachment); return(attachment); }
public LogAttachmentInfo(LogAttachment attachment) : base(attachment.Level, attachment.TimeStamp, true) { _attachment = attachment; }