Ejemplo n.º 1
0
        private void RouteCopy(HttpContext context)
        {
            string id = context.Request.QueryString["id"];

            ClassLibrary.BLL.Routes   routeBll   = new ClassLibrary.BLL.Routes();
            ClassLibrary.Model.Routes routemodel = routeBll.GetModel(int.Parse(id));
            if (routemodel == null || routemodel.Title == "")
            {
                Print(context, "error");
                return;
            }
            string[] oldImgs      = routemodel.Image.Split(',');
            string   fileFullPath = context.Server.MapPath(SysConfig.UploadFilePathRoutesImg);
            string   newImgs      = "";

            for (int i = 0; i < oldImgs.Length; i++)
            {
                string ext      = Path.GetExtension(oldImgs[i]);
                string fileName = Function.GetRandomTime() + ext;
                try
                {
                    File.Copy(fileFullPath + oldImgs[i], fileFullPath + fileName);
                } catch (Exception e) {
                }
                newImgs += fileName + ",";
            }
            if (!string.IsNullOrEmpty(newImgs))
            {
                newImgs = newImgs.Substring(0, newImgs.Length - 1);
            }
            routemodel.Image       = newImgs;
            routemodel.Display     = false;
            routemodel.ViewCount   = 0;
            routemodel.Order       = 999;
            routemodel.FirstTime   = DateTime.Now.ToString("yyyy-MM-dd");
            routemodel.CreatedTime = DateTime.Now;

            if (routeBll.Add(routemodel) > 0)
            {
                if (routemodel.DetailType)
                {
                    int routeId = routeBll.GetLastId();
                    ClassLibrary.BLL.RouteDetails          rdBll      = new ClassLibrary.BLL.RouteDetails();
                    List <ClassLibrary.Model.RouteDetails> detailList = rdBll.GetModelList("routeId = " + routemodel.ID);
                    foreach (ClassLibrary.Model.RouteDetails model in detailList)
                    {
                        model.RouteID = routeId;
                        rdBll.Add(model);
                    }
                    Print(context, "success");
                }
            }
            else
            {
                Print(context, "error");
            }
        }