コード例 #1
0
ファイル: PagesController.cs プロジェクト: adykn/D-R-M
        public ActionResult GetData(FormCollection frm, Entities m)
        {
            var str  = "";
            var sect = frm["sect"];
            var edid = Convert.ToInt32((string.IsNullOrEmpty(frm["edid"]) ? "0" : frm["edid"]));

            if (sect == null)
            {
                return(Content("Sorry"));
            }

            if (sect == "sav")
            {
                try
                {
                    var pfx = "";
                    var id  = Convert.ToInt32(frm["Page.Id" + pfx]);
                    var sc  = _db.Pages.FirstOrDefault(x => x.Id == id);
                    sc.Title = frm["Page.Title" + pfx];
                    //sc.Url= frm["Page.Url" + pfx];


                    try
                    {
                        if (m.UploadedFile1 != null)
                        {
                            DeleteImgAndThumbnail(sc.Img, null);
                            HttpPostedFileBase filePic = m.UploadedFile1;
                            sc.Img = SaveFile(filePic);
                        }
                        else
                        {
                            var selector = frm["selector"];
                            if (!string.IsNullOrEmpty(selector))
                            {
                                var gimg = new GetImgFrmUrl(selector, "/Content/img/ico/");
                                sc.Img = gimg.ImgPath;
                            }
                            else
                            {
                                sc.Img = frm["Page.Img" + pfx];
                            }
                        }
                    }
                    catch { }
                    str = "Done";
                    _db.SaveChanges();
                }
                catch
                {
                    str = "Error";
                }
            }
            if (sect == "frm")
            {
                var mm = _db.Pages.Find(edid);
                _ent.Page = mm;
                str       = PartialView("_Frm", _ent).RenderToString();
            }
            else if (sect == "imgLoc")
            {
                try
                {
                    var lst    = System.IO.Directory.GetFiles(Server.MapPath("/Content/img/ico/"));
                    var cnt    = 0;
                    var target = (string.IsNullOrEmpty(frm["target"]) ? "" : frm["target"]);
                    foreach (var i in lst)
                    {
                        cnt += 1;
                        var f = "/Content/img/ico/" + Path.GetFileName(i);
                        f    = f.Replace(" ", "%20");
                        str += "<div id='gdi-" + cnt + "' style='background-image:url(" + f + ");background-size:cover;' class='gpixbox gpall' onClick='$(\"#" + target + "\").val(\"" + f + "\");$(\".gpall\").removeClass(\"bdr\");$(\"#gdi-" + cnt + "\").addClass(\"bdr\");'> </div>";
                    }
                    if (lst.Count() == 0)
                    {
                        str = "Directory is empty";
                    }
                }
                catch (Exception)
                {
                    str += "No Net Connection";
                }
            }
            else if (sect == "img")
            {
                var s = frm["s"];
                var g = new GoogleImageFetcher._4dImageFetcher();
                try
                {
                    var lst = g.GetHtmlCode(s);
                    var cnt = 0;
                    foreach (var i in lst)
                    {
                        cnt += 1;
                        var f = i;
                        f    = f.Replace(" ", "%20");
                        str += "<div id='gdi-" + cnt + "' style='background-image:url(" + i + ");background-size:cover;' class='gpixbox gpall' onClick='$(\"#selector\").val(\"" + i + "\");$(\".gpall\").removeClass(\"bdr\");$(\"#gdi-" + cnt + "\").addClass(\"bdr\");'> </div>";
                    }
                }
                catch (Exception)
                {
                    str += "No Net Connection";
                }
            }



            return(Content(str));
        }
コード例 #2
0
ファイル: LivePageController.cs プロジェクト: adykn/D-R-M
        public async Task <ActionResult> GetData(FormCollection frm)
        {
            var sect = frm["sect"];
            var ids  = (string.IsNullOrEmpty(frm["edid"]) ? "0-0-0" : frm["edid"]);
            var idss = ids.Split('-');
            var edid = Convert.ToInt32(idss[0]);
            var str  = "";

            if (sect == null)
            {
                return(Json(new { status = "Bad Request" }, JsonRequestBehavior.AllowGet));
            }

            if (sect == "staS")
            {
                var m = await _db.LivePages.FirstOrDefaultAsync(x => x.Id == edid);

                if (m == null)
                {
                    return(Json(new { status = "Bad Request" }, JsonRequestBehavior.AllowGet));
                }
                m.Status           = frm["sta"];
                m.ApprovedByUserId = Entities.UserId;
                await _db.SaveChangesAsync();

                var list = JsonConvert.SerializeObject(m, Formatting.None, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                });
                return(Json(new { status = "Done" }, JsonRequestBehavior.AllowGet));
            }
            else if (sect == "imgLoc")
            {
                try
                {
                    var lst    = System.IO.Directory.GetFiles(Server.MapPath("/Content/img/Layout/"));
                    var cnt    = 0;
                    var target = (string.IsNullOrEmpty(frm["target"]) ? "" : frm["target"]);
                    foreach (var i in lst)
                    {
                        cnt += 1;
                        var f = "/Content/img/Layout/" + Path.GetFileName(i);

                        str += "<div id='gdi-" + cnt + "' style='background-image:url(" + f + ");background-size:cover;' class='gpixbox gpall' onClick='$(\"#" + target + "\").val(\"" + f + "\");$(\".gpall\").removeClass(\"bdr\");$(\"#gdi-" + cnt + "\").addClass(\"bdr\");'> </div>";
                    }
                    if (lst.Count() == 0)
                    {
                        str = "Directory is empty";
                    }
                    return(Content(str));
                    //return Json(new { status = "Done", data = str }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return(Content("No Net Connection"));
                }
            }
            else if (sect == "img")
            {
                var s = "\"" + frm["s"] + "\"";
                var t = "DefaultSrc";
                var g = new GoogleImageFetcher._4dImageFetcher();
                try
                {
                    var lst = g.GetHtmlCode(s);
                    var cnt = 0;
                    foreach (var i in lst)
                    {
                        cnt += 1;
                        str += "<div id='gdi-" + cnt + "' style='background-image:url(" + i + ");background-size:cover;' class='gpixbox gpall' onClick='$(\"#" + t + "\").val(\"" + i + "\");$(\".gpall\").removeClass(\"bdr\");$(\"#gdi-" + cnt + "\").addClass(\"bdr\");'> </div>";
                    }

                    return(Content(str));
                    //return Json(new { status = "Done", data = str }, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return(Content("Error"));
                }
            }

            return(Json(new { status = "error" }, JsonRequestBehavior.AllowGet));
        }