示例#1
0
        public ActionResult PhotoImport(int id, string path)
        {
            var actDal = new ActDal();
            var act    = actDal.GetModel(id);

            if (act == null)
            {
                return(Json("环节不存在"));
            }

            if (act.Depth != 2)
            {
                return(ReJson(false, "该项目不属于环节"));
            }

            path = Server.MapPath("~/upload/");
            if (!Directory.Exists(path))
            {
                return(ReJson(false, "路径不存在"));
            }

            var folder     = new DirectoryInfo(path);
            var types      = new[] { ".jpg", ".jpeg", ".gif", ".png", ".bmp" };
            var files      = folder.GetFiles().OrderBy(_ => _.Name).ToList();
            int validCount = 0;

            foreach (var file in files)
            {
                if (!types.Contains(file.Extension, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                var stream = file.OpenRead();
                var re     = actDal.UploadPic(stream);
                if (!re.Success)
                {
                    return(ReJson(false, string.Format("照片名为{0}未保存成功,原因{1},可以继续点导入重试", file.Name, re.Info)));
                }

                var photo = new Act {
                    Name = file.Name, ParentFid = id, PhotoUrl = re.Info, Enable = true, OrderIndex = ConvertHelper.StrToInt(file.Name)
                };
                re = actDal.EditAct(photo);
                if (!re.Success)
                {
                    return(ReJson(false, string.Format("照片名为{0}未保存成功,原因{1},可以继续点导入重试", file.Name, re.Info)));
                }
                validCount++;
                stream.Close();
                file.Delete();
            }

            if (validCount == 0)
            {
                return(ReJson(false, "没有文件导入"));
            }

            return(ReJson(false, "全部导入成功"));
        }
示例#2
0
        /// <summary>
        /// 获取照片
        /// </summary>
        /// <param name="fid"></param>
        /// <param name="pn"></param>
        /// <returns></returns>
        public ActionResult Photos(int fid, int pn = 1)
        {
            var act = ActDal.GetModel(fid);

            if (act == null)
            {
                return(Json(null));
            }

            var where = "";
            if (act.Depth == 1)
            {
                where = string.Format("RootFid={0} and Depth=3", fid);
            }
            else
            {
                where = string.Format("ParentFid={0}", fid);
            }

            return(Json(ActDal.GetList(string.Format("Enable=1 and {0}", where), 32, pn, true, "*", "OrderIndex"), JsonRequestBehavior.AllowGet));
        }
示例#3
0
        /// <summary>
        /// 获取环节
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        public ActionResult Steps(int fid)
        {
            var act = ActDal.GetModel(fid);

            if (act == null)
            {
                return(Json(null));
            }

            if (act.Depth == 1)
            {
                fid = act.Id;
            }
            else if (act.Depth == 2)
            {
                fid = act.ParentFid;
            }

            var rootAct = ActDal.GetModel(act.RootFid);

            return(Json(new { steps = ActDal.GetList(string.Format("Enable=1 and ParentFid={0}", fid), 10, 1, true, "*", "OrderIndex"), cover = rootAct == null ? "" : rootAct.PhotoUrl }, JsonRequestBehavior.AllowGet));
        }