public JsonResult Create(FormCollection col)
 {
     try
     {
         Guid         gid   = Tool.String2Guid(col["GUID"]);
         CUSTOMERINFO model = new CUSTOMERINFO();
         if (gid == Guid.Empty)
         {
             model.GUID       = Guid.NewGuid();
             model.CREATETIME = DateTime.Now;
             model.ISDELETED  = 0;
             FillModel(ref model, col);
             string pwd = Tool.GetMD5Hash(Tool.textToBytes(col["CUSTOMERPWD"]));
             model.CUSTOMERPWD = pwd;
             DbContext.CUSTOMERINFO.Add(model);
         }
         else
         {
             model = DbContext.CUSTOMERINFO.FirstOrDefault(m => m.GUID == gid);
             FillModel(ref model, col);
             DbContext.Entry(model).State = System.Data.EntityState.Modified;
         }
         DbContext.SaveChanges();
         return(new JsonM().ToJson(true, MsgHelper.SaveSuccess));
     }
     catch (Exception ex)
     {
         return(new JsonM().ToJson(false, MsgHelper.SaveFail, ex.Message));
     }
 }
        private void FillModel(ref CUSTOMERINFO model, FormCollection col)
        {
            model.ADDR            = col["ADDR"];
            model.BUSINESSLICENSE = col["BUSINESSLICENSE"];
            model.CITY            = col["CITY"];
            model.CITYID          = Tool.String2Guid2(col["CITYID"]);
            model.CUSTOMERPHONE   = col["CUSTOMERPHONE"];


            model.INVITECODE     = col["INVITECODE"];
            model.SALESMANID     = Tool.String2Guid2(col["SALESMANID"]);
            model.SALESMANNAME   = col["SALESMANNAME"];
            model.SHOPLEADERNAME = col["SHOPLEADERNAME"];
            model.SHOPNAME       = col["SHOPNAME"];
        }
        public ActionResult Create(string q_guid = "")
        {
            ViewData["city"] = base.AreaListOptions;

            ViewData["Salesman"] = YeWuYuanOptions;

            CUSTOMERINFO model;

            if (string.IsNullOrEmpty(q_guid))
            {
                model = new CUSTOMERINFO();
            }
            else
            {
                Guid g = Tool.String2Guid(q_guid);
                model = DbContext.CUSTOMERINFO.FirstOrDefault(m => m.GUID == g);
            }

            return(View(model));
        }