Esempio n. 1
0
        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
            });
        }