/// <summary>
        /// 查询下载统计记录
        /// </summary>
        /// <param name="conn"></param>
        /// <returns></returns>
        public static List <AppDownloadCount> AppCampaignList(SqlConnection conn)
        {
            var list = new List <AppDownloadCount>();

            using (var reader = SqlHelper.ExecuteReaderV2(conn, CommandType.Text, @"SELECT a.*,ISNULL(b.DownloadCount,0) DownloadCount FROM Tuhu_sem.dbo.tbl_AppCampaign a WITH(NOLOCK) LEFT JOIN (SELECT CampaignID,COUNT(*) DownloadCount FROM Tuhu_sem.dbo.tbl_AppDownloadAction WITH(NOLOCK) GROUP BY CampaignID) b ON a.PKID=b.CampaignID where IsDeleted!=1"))
            {
                while (reader.Read())
                {
                    var app = new AppDownloadCount()
                    {
                        PKID           = reader.GetTuhuValue <int>(0),
                        ArticleTitle   = reader.GetTuhuString(1),
                        Channel        = reader.GetTuhuString(2),
                        OtherChannel   = reader.GetTuhuString(3),
                        AppUrl         = reader.GetTuhuString(4),
                        IsDeleted      = reader.GetTuhuValue <bool>(5).ToString(),
                        Creator        = reader.GetTuhuString(6),
                        CreateDateTime = reader.GetTuhuValue <DateTime>(7),
                        Deletor        = reader.GetTuhuString(8),
                        DeleteDateTime = reader.GetTuhuValue <DateTime>(9),
                        DownloadCount  = reader.GetTuhuValue <int>(10).ToString()
                    };

                    list.Add(app);
                }
            }
            return(list);

            //  return dt == null || dt.Rows.Count == 0 ? new List<AppDownloadCount>() : dt.c<AppDownloadCount>().ToList();
        }
        /// <summary>
        /// 新增下载统计记录
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="adc"></param>
        /// <returns></returns>
        public static int CreateApp(SqlConnection conn, AppDownloadCount adc)
        {
            string insertSql = "INSERT Tuhu_sem.dbo.tbl_AppCampaign WITH(ROWLOCK) VALUES  ( @ArticleTitle ,@Channel ,@OtherChannel ,@AppPath, 0 ,@Creator ,GETDATE() , '' , NULL);SET @pkid=SCOPE_IDENTITY();";
            var    para      = new[] {
                new SqlParameter("@ArticleTitle", adc.ArticleTitle),
                new SqlParameter("@Channel", adc.Channel),
                new SqlParameter("@OtherChannel", adc.OtherChannel),
                new SqlParameter("@AppPath", adc.AppUrl),
                new SqlParameter("@Creator", adc.Creator),
                new SqlParameter("@pkid", DbType.Int32)
                {
                    Direction = ParameterDirection.Output
                }
            };

            SqlHelper.ExecuteNonQueryV2(conn, CommandType.Text, insertSql, para);
            return(int.Parse(para.Last().Value.ToString()));
        }
        public async Task <ActionResult> AppDownloadListAsync(FormCollection fc)
        {
            HttpPostedFileBase file = Request.Files["appPath"];

            if (file != null)
            {
                AppDownloadCount adc = new AppDownloadCount()
                {
                    ArticleTitle = fc["apptitle"],
                    Channel      = fc["appchannel"],
                    Creator      = User.Identity.Name,
                    AppUrl       = "",
                    OtherChannel = fc["otherSpread"]
                };

                int pkid = new SemCampaignHandler(DbScopeManager).CreateApp(adc);
                try
                {
                    var str = await SaveFileAsync(file);

                    if (str.Success)
                    {
                        new SemCampaignHandler(DbScopeManager).CreateOrDeleteApp(imgUrl + str.Result, pkid);
                    }
                    else
                    {
                        //没有更新成功,把之前新增的记录删除
                        var wew = new SemCampaignHandler(DbScopeManager).CreateOrDeleteApp("", pkid);
                    }
                }
                catch (Exception ex)
                {
                    new SemCampaignHandler(DbScopeManager).CreateOrDeleteApp("", pkid);
                    return(Json(ex.Message));
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(Json("没有获取到上传文件,请返回重新提交!"));
            }
        }
Example #4
0
 public int CreateApp(AppDownloadCount adc)
 {
     return(dbManager.Execute(connection => DALSemCampaign.CreateApp(connection, adc)));
 }