Esempio n. 1
0
        public CommonResponse LogSignature([FromBody] LogSignatureRequest inputRequest)
        {
            try
            {
                if (inputRequest == null)
                {
                    return(new LoginAndQueryResponse {
                        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 CommonResponse { StatusCode = "100004", Description = "error identity" };
                // }

//System.IO.File.WriteAllBytes(inputRequest.SignatureFile);//todo

                return(new CommonResponse
                {
                    StatusCode = "100000",
                    Description = "ok",
                });
            }
            catch (Exception ex)
            {
                return(new CommonResponse {
                    StatusCode = "100003", Description = ex.Message
                });
            }
        }
Esempio n. 2
0
        public async Task <CommonResponse> LogSignature([FromBody] LogSignatureRequest inputRequest)
        {
            try
            {
                var input = JsonConvert.SerializeObject(inputRequest);
                await Task.Run(() =>
                               LogRequest(input, "LogSignature", Request.HttpContext.Connection.RemoteIpAddress.ToString()));

                if (inputRequest == null)
                {
                    Log.Error("LogSignature,{0}", Global.Status[responseCode.studyRequestError].Description);
                    return(new CommonResponse
                    {
                        StatusCode = Global.Status[responseCode.studyRequestError].StatusCode,
                        Description = Global.Status[responseCode.studyRequestError].Description
                    });
                }
                Log.Information("LogSignature,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("LogSignature,{0}", Global.Status[responseCode.studyTokenError].Description);
                    return(new CommonResponse
                    {
                        StatusCode = Global.Status[responseCode.studyTokenError].StatusCode,
                        Description = Global.Status[responseCode.studyTokenError].Description
                    });
                }
                var cryptographicid = CryptographyHelpers.StudyEncrypt(identity);
                var theuser         = _db1.User.FirstOrDefault(async => async.Identity == identity || async.Identity == cryptographicid);
                if (theuser == null)
                {
                    return(new CommonResponse {
                        StatusCode = "100004", Description = "error identity"
                    });
                }
                var date = DateTime.Today;
                //    var dir = string.Format("{0}{1}{2}", date.Year, date.Month, date.Day);
                var fpath = Global.SignaturePath;//Path.Combine(Global.SignaturePath, dir);
                if (!Directory.Exists(fpath))
                {
                    Directory.CreateDirectory(fpath);
                }
                var subfpath = identity;
                if (!string.IsNullOrEmpty(theuser.Photofile))
                {
                    subfpath = theuser.Photofile;
                }
                var fname = Path.Combine(fpath, subfpath + inputRequest.SignatureType);
                var index = inputRequest.SignatureFile.IndexOf("base64,");
                //  Log.Information("LogSignature,{0}", inputRequest.SignatureFile.Substring(index + 7));
                System.IO.File.WriteAllBytes(fname, Convert.FromBase64String(inputRequest.SignatureFile.Substring(index + 7)));

                switch (inputRequest.SignatureType)
                {
                case SignatureType.PhysicalCondition:
                    theuser.Firstsigned = "1";
                    // if (!string.IsNullOrEmpty(inputRequest.PostalAddress))
                    // {
                    //     theuser.Postaladdress = inputRequest.PostalAddress;
                    // }
                    break;

                case SignatureType.EducationalRecord:
                    theuser.Signed = "1";
                    break;

                default:
                    break;
                }
                if (inputRequest.SignatureType == SignatureType.EducationalRecord)
                {
                    _db1.History.Add(new History
                    {
                        Identity       = cryptographicid,
                        Drivinglicense = theuser.Drivinglicense,
                        Deductedmarks  = theuser.Deductedmarks,
                        Name           = theuser.Name,
                        Syncphone      = theuser.Syncphone,
                        Phone          = theuser.Phone,
                        Syncdate       = theuser.Syncdate,
                        Startdate      = theuser.Startdate,
                        Completed      = theuser.Completed,
                        Finishdate     = DateTime.Now,
                        Stoplicense    = theuser.Stoplicense,
                        Noticedate     = theuser.Noticedate,
                        Wechat         = theuser.Wechat,
                        Studylog       = theuser.Studylog,
                        Postaladdress  = theuser.Postaladdress,
                        Drugrelated    = theuser.Drugrelated,
                        Fullmark       = theuser.Fullmark,
                        Inspect        = theuser.Inspect,
                        Completelog    = theuser.Completelog,
                        Signed         = theuser.Signed,
                        Photostatus    = theuser.Photostatus,
                        Firstsigned    = theuser.Firstsigned,
                        Photofile      = theuser.Photofile,
                        Status         = theuser.Status,
                        Token          = theuser.Token,
                        Lasttoken      = theuser.Lasttoken,
                        Licensetype    = theuser.Licensetype
                    });
                    _db1.User.Remove(theuser);
                }
                _db1.SaveChanges();
                return(new CommonResponse
                {
                    StatusCode = Global.Status[responseCode.studyOk].StatusCode,
                    Description = Global.Status[responseCode.studyOk].Description,
                });
            }
            catch (Exception ex)
            {
                Log.Error("LogSignature,{0}", ex);
                return(new CommonResponse
                {
                    StatusCode = Global.Status[responseCode.studyProgramError].StatusCode,
                    Description = Global.Status[responseCode.studyProgramError].Description
                });
            }
        }