public commonresponse uploadpic([FromBody] uploadpicrequest input) { // highlevel.LogRequest("uploadpic", "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString()); if (input == null) { return(highlevel.commonreturn(responseStatus.requesterror)); } var accinfo = highlevel.GetInfoByToken(Request.Headers); if (accinfo.status != responseStatus.ok) { return(accinfo); } _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now); if (!savePic(input.picture, input.picType, accinfo.Identity, accinfo.businessType)) { return(highlevel.commonreturn(responseStatus.fileprocesserror)); } if (input.picType == picType.unknown) { return(highlevel.commonreturn(responseStatus.pictypeerror)); } if (accinfo.businessType == businessType.unknown) { return(highlevel.commonreturn(responseStatus.businesstypeerror)); } try { using (var ddbb = new aboContext()) { var already = ddbb.Businesspic.FirstOrDefault(i => i.Businesstype == (int)accinfo.businessType && i.Identity == accinfo.Identity && i.Pictype == (short)input.picType); if (already == null) { var newpic = new Businesspic { Identity = accinfo.Identity, Businesstype = (short)accinfo.businessType, Pictype = (short)input.picType, Uploaded = true, Time = DateTime.Now }; // highlevel.infolog(_log, "uploadpic", JsonConvert.SerializeObject(newpic)); var ret = ddbb.Businesspic.Add(newpic); // highlevel.infolog(_log, "uploadpic88", JsonConvert.SerializeObject(ret.Entity)); } else { already.Uploaded = true; already.Time = DateTime.Now; } ddbb.SaveChanges(); } } catch (Exception ex) { highlevel.errorlog(_log, "uploadpic", ex); } try { var he = Request.Host.ToString(); foreach (var a in Request.Headers) { he += "--" + a.Key + "=" + a.Value; } Task.Run(() => highlevel.LogRequest(he + input.picType + accinfo.Identity, "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)accinfo.businessType)); } catch (Exception ex) { _log.LogError("dblog error:", ex); } _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}---over", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now); return(new commonresponse { status = responseStatus.ok }); }
public commonresponse uploadpic([FromBody] uploadpicrequest input) { LogRequest("uploadpic", "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString()); if (input == null) { return(new commonresponse { status = responseStatus.requesterror }); } var identity = string.Empty; var btype = businessType.basicinfo; try { var htoken = Request.Headers["token"].First(); if (string.IsNullOrEmpty(htoken)) { return(new commonresponse { status = responseStatus.tokenerror }); } var found = false; foreach (var a in tokens) { if (a.Token == htoken) { identity = a.idinfo.Identity; btype = a.idinfo.businessType; found = true; break; } } if (!found) { var redisdb = highlevel.redis.GetDatabase(); var cacheidinfo = redisdb.StringGet(htoken); if (cacheidinfo == "nil") { return(new commonresponse { status = responseStatus.tokenerror }); } var ci = JsonConvert.DeserializeObject <idinfo>(cacheidinfo); identity = ci.Identity; btype = ci.businessType; } } catch (Exception ex) { return(new commonresponse { status = responseStatus.tokenerror }); } // if (string.IsNullOrEmpty(input.id_back)) // { // return new commonresponse { status = responseStatus.imageerror }; // } if (!savePic(input.picture, input.picType, identity, btype)) { return new commonresponse { status = responseStatus.fileprocesserror } } ; _db1.Businesspic.Add(new Businesspic { Identity = identity, Businesstype = (short)btype, Pictype = (short)input.picType, Uploaded = true }); _db1.SaveChanges(); return(new commonresponse { status = responseStatus.ok }); }