public CommonResponse CompleteCourses([FromBody] CompleteCoursesRequest inputRequest) { try { if (inputRequest == null) { return(new CommonResponse { StatusCode = "100002", Description = "请求错误,请检查请求参数!" }); } Log.Info("CompleteCourses input:" + JsonConvert.SerializeObject(inputRequest)); return(new CommonResponse { StatusCode = "100000", Description = "ok", }); } catch (Exception ex) { Log.Error("CompleteCourses", ex); return(new CommonResponse { StatusCode = "100003", Description = ex.Message }); } }
public CommonResponse InspectCompleteCourses([FromBody] CompleteCoursesRequest inputRequest) { try { if (inputRequest == null) { return(new CommonResponse { StatusCode = "100002", Description = "请求错误,请检查请求参数!" }); } var found = false; var identity = string.Empty; foreach (var a in tokens) { if (a.Token == inputRequest.Token) { identity = a.Identity; found = true; break; } } if (!found) { return(new CommonResponse { StatusCode = "100001", Description = "error token" }); } var theuser = _db1.User.FirstOrDefault(async => async.Identity == identity); if (theuser == null) { return(new GetLearnerInfoResponse { StatusCode = "100004", Description = "error identity" }); } // theuser. = DateTime.Now; theuser.Studylog += inputRequest.AllRecords + inputRequest.AllStatus; _db1.History.Add(new History { Identity = theuser.Identity, Name = theuser.Name, Phone = theuser.Phone, Syncdate = theuser.Syncdate, Startdate = theuser.Startdate, Finishdate = DateTime.Now, Stoplicense = theuser.Stoplicense, Noticedate = theuser.Noticedate, Wechat = theuser.Wechat, Studylog = theuser.Studylog, Drugrelated = theuser.Drugrelated, // Photo = theuser.Photo, Fullmark = theuser.Fullmark, Inspect = theuser.Inspect, Licensetype = theuser.Licensetype, // Timestamp = DateTime.Now }); _db1.User.Remove(theuser); _db1.SaveChanges(); return(new CommonResponse { StatusCode = "100000", Description = "ok", }); } catch (Exception ex) { // Log.Error("CompleteCourses", ex); return(new CommonResponse { StatusCode = "100003", Description = ex.Message }); } }
public async Task <CommonResponse> InspectCompleteCourses([FromBody] CompleteCoursesRequest inputRequest) { try { var input = JsonConvert.SerializeObject(inputRequest); await Task.Run(() => LogRequest(input, "InspectCompleteCourses", Request.HttpContext.Connection.RemoteIpAddress.ToString())); if (inputRequest == null) { Log.Error("InspectCompleteCourses,{0}", Global.Status[responseCode.RequestError].Description); return(new CommonResponse { StatusCode = Global.Status[responseCode.RequestError].StatusCode, Description = Global.Status[responseCode.RequestError].Description }); } Log.Information("InspectCompleteCourses,input={0},from {1}", input, Request.HttpContext.Connection.RemoteIpAddress); var found = false; var identity = string.Empty; foreach (var a in tokens) { if (a.Token == inputRequest.Token) { identity = a.Identity; found = true; break; } } if (!found) { Log.Error("InspectCompleteCourses,{0},token={1}", Global.Status[responseCode.TokenError].Description, inputRequest.Token); return(new CommonResponse { StatusCode = Global.Status[responseCode.TokenError].StatusCode, Description = Global.Status[responseCode.TokenError].Description }); } var cryptographicid = CryptographyHelpers.StudyEncrypt(identity); var theuser = _db1.User.FirstOrDefault(async => async.Identity == identity || async.Identity == cryptographicid); // var theuser = _db1.User.FirstOrDefault(async => async.Identity == identity); if (theuser == null) { Log.Error("InspectCompleteCourses,{0},identity={1}", Global.Status[responseCode.InvalidIdentiy].Description, identity); return(new CommonResponse { StatusCode = Global.Status[responseCode.InvalidIdentiy].StatusCode, Description = Global.Status[responseCode.InvalidIdentiy].Description }); } if (theuser.Completed == "1") { return(new CommonResponse { StatusCode = Global.Status[responseCode.ok].StatusCode, Description = Global.Status[responseCode.ok].Description, }); } // theuser. = DateTime.Now; var clog = inputRequest.AllStatus.Length < 80 ? inputRequest.AllStatus : inputRequest.AllStatus.Substring(0, 78); theuser.Completelog = clog; theuser.Completed = "1"; // theuser.Syncdate=DateTime.Now; _db1.SaveChanges(); if (inputRequest.AllRecords != null) { var date = DateTime.Today; // var dir = string.Format("{0}{1}{2}", date.Year, date.Month, date.Day); var subfpath = identity; if (!string.IsNullOrEmpty(theuser.Photofile)) { subfpath = theuser.Photofile; } var fpath = Path.Combine(Global.LogPhotoPath, subfpath); if (!Directory.Exists(fpath)) { Directory.CreateDirectory(fpath); } var fname = Path.Combine(fpath, "exam_result.txt"); Log.Information("filename is: {0}", fname); System.IO.File.WriteAllBytes(fname, inputRequest.AllRecords); } return(new CommonResponse { StatusCode = Global.Status[responseCode.ok].StatusCode, Description = Global.Status[responseCode.ok].Description, }); } catch (Exception ex) { Log.Error("InspectCompleteCourses,{0},exception={1}", Global.Status[responseCode.ProgramError].Description, ex); return(new CommonResponse { StatusCode = Global.Status[responseCode.ProgramError].StatusCode, Description = Global.Status[responseCode.ProgramError].Description }); } }