Example #1
0
 private static SimpleJson SaveRegion()
 {
     string type = WebUtil.Param("type");
     if (type != "p" && type != "c" && type != "d")
         return new SimpleJson()
             .HandleError(string.Format("Invalidate type {0} in action SaveRegion", type));
     string opt = WebUtil.Param("opt");
     if (opt != "create" && opt != "update")
         return new SimpleJson()
             .HandleError("Invalidate operation in action SaveRegion");
     using (ISession session = new Session())
     {
         if (type == "p")
         {
             #region province
             Province pro = new Province();
             pro.Code = WebUtil.Param("code");
             pro.Name = WebUtil.Param("name");
             pro.Alias = WebUtil.Param("alias");
             if (opt == "create")
                 pro.Create(session);
             else
             {
                 pro.ProvinceId = WebUtil.ParamInt("id", -1);
                 pro.Update(session, "Code", "Name", "Alias");
             }
             return pro.GetJSON();
             #endregion
         }
         else if (type == "c")
         {
             #region city
             City city = new City();
             city.CityCode = WebUtil.Param("code");
             city.Name = WebUtil.Param("name");
             city.ProvinceId = WebUtil.ParamInt("parent", -1);
             if (opt == "create")
             {
                 city.Create(session);
             }
             else
             {
                 city.CityId = WebUtil.ParamInt("id", -1);
                 city.Update(session, "CityCode", "Name");
             }
             return city.GetJSON();
             #endregion
         }
         else if (type == "d")
         {
             #region district
             District district = new District();
             district.Name = WebUtil.Param("name");
             district.ZipCode = WebUtil.Param("zip");
             district.Door2Door = WebUtil.Param("ship") == "1" ? true : false;
             district.CityId = WebUtil.ParamInt("parent", -1);
             if (opt == "create")
             {
                 district.Create(session);
             }
             else
             {
                 district.DistrictId = WebUtil.ParamInt("id", -1);
                 district.Update(session, "Name", "ZipCode", "Door2Door");
             }
             return district.GetJSON();
             #endregion
         }
     }
     return null;
 }