Ejemplo n.º 1
0
        /// <summary>
        /// 新增或更新小程序或其他公众号二维码推广信息
        /// </summary>
        /// <param name="qrCodeExtension"></param>
        /// <param name="workUser"></param>
        /// <returns></returns>
        public ReturnValueModel AddorUpdateQRCodeExtension(QRcodeExtension qrCodeExtension, WorkUser workUser)
        {
            ReturnValueModel rvm = new ReturnValueModel();
            //获取参数查询数据库是否已存在有效的重复数据
            var qrRepeated = _rep.FirstOrDefault <QRcodeExtension>(s => s.Id == qrCodeExtension.Id && s.IsDeleted != 1);

            //如果存在则该操作为编辑操作if
            if (qrRepeated != null)
            {
                //判断数据库是否存在内容重复的有效数据
                var contentRepetition = _rep.FirstOrDefault <QRcodeExtension>(s => s.AppId == qrCodeExtension.AppId && s.AppName == qrCodeExtension.AppName && s.AppType == qrCodeExtension.AppType && s.IsDeleted != 1);
                //判断重复有效数据是否存在,存在则执行修改操作,不存在则跳出程序
                if (contentRepetition != null)
                {
                    rvm.Success = false;
                    rvm.Msg     = "There are duplicate data in this information.";
                }
                else
                {
                    qrRepeated.Id         = qrCodeExtension.Id;
                    qrRepeated.AppId      = qrCodeExtension.AppId;
                    qrRepeated.AppName    = qrCodeExtension.AppName;
                    qrRepeated.AppType    = qrCodeExtension.AppType;
                    qrRepeated.UpdateTime = DateTime.Now;
                    qrRepeated.UpdateUser = workUser.User.Id;
                    //给记录进行更新操作
                    _rep.Update(qrRepeated);
                    //保存执行的操作
                    var send = _rep.SaveChanges();
                    //判断是否操作成功
                    if (send > 0)
                    {
                        rvm.Success = true;
                        rvm.Msg     = "success";
                        rvm.Result  = contentRepetition ?? qrRepeated;
                    }
                    else
                    {
                        rvm.Success = false;
                        rvm.Msg     = "Failure to modify";
                    }
                }
            }
            //如果不存在,则该操作为新增操作
            else
            {
                //判断重复有效数据是否存在,存在则执行修改操作,不存在则跳出程序
                var contentRepetition = _rep.FirstOrDefault <QRcodeExtension>(s => s.AppId == qrCodeExtension.AppId && s.AppName == qrCodeExtension.AppName && s.AppType == qrCodeExtension.AppType && s.IsDeleted != 1);
                if (contentRepetition != null)
                {
                    rvm.Success = false;
                    rvm.Msg     = "There are duplicate data in this information.";
                }
                else
                {
                    //string strCode = "http://buo.fresenius-kabi.com.cn/admin?APPID=0&Type=1&ActivityID=12";
                    //QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
                    //QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
                    //QRCode qrcode = new QRCode(qrCodeData);
                    //Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false);
                    //if (!Directory.Exists("F:\\QRCode"))
                    //    Directory.CreateDirectory("F:\\QRCode");
                    //string sq = Guid.NewGuid().ToString();
                    //qrCodeImage.Save("F:\\QRCode\\"+sq+".jpg");
                    QRcodeExtension qRcode = new QRcodeExtension();
                    qRcode.Id         = Guid.NewGuid().ToString();
                    qRcode.AppId      = qrCodeExtension.AppId;
                    qRcode.AppName    = qrCodeExtension.AppName;
                    qRcode.AppType    = qrCodeExtension.AppType;
                    qRcode.CreateTime = DateTime.Now;
                    qRcode.CreateUser = workUser.User.Id;
                    qRcode.IsDeleted  = 0;
                    //添加一条新数据
                    _rep.Insert(qRcode);
                    //保存新增数据
                    var send = _rep.SaveChanges();
                    //判断操作是否成功
                    if (send > 0)
                    {
                        rvm.Success = true;
                        rvm.Msg     = "success";
                        rvm.Result  = contentRepetition ?? qRcode;
                    }
                    else
                    {
                        rvm.Success = false;
                        rvm.Msg     = "New failure";
                    }
                }
            }
            return(rvm);
        }
Ejemplo n.º 2
0
        public IHttpActionResult AddorUpdateQRCodeExtension(QRcodeExtension qRcodeExtension)
        {
            var ret = _ExtensionService.AddorUpdateQRCodeExtension(qRcodeExtension, WorkUser);

            return(Ok(ret));
        }