public IHttpActionResult Add(InputStoreArchiveModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             //返回错误
             return(JsonResultHelper.JsonResult(1000, ModelState.Values.SelectMany(p => p.Errors.Select(s => s.ErrorMessage))));
         }
         else
         {
             if (dbContext.ST_Store.Any(p => p.Name == model.Name))
             {
                 return(JsonResultHelper.JsonResult(1000, "该门店已存在"));
             }
             if (dbContext.ST_Store.Any(p => p.Code == model.Code))
             {
                 return(JsonResultHelper.JsonResult(1000, "该门店编码已存在"));
             }
             ST_Store store = new ST_Store()
             {
                 Address        = model.Address,
                 Code           = model.Code,
                 IdPersonRegion = model.IdPersonRegion,
                 IdSupervisor   = model.IdSupervisor,
                 RegionId       = model.RegionId,
                 Remark         = model.Remark,
                 Name           = model.Name,
                 IdArea         = model.IdArea
             };
             dbContext.ST_Store.Add(store);
             dbContext.SaveChanges();
             string sql = string.Format("	INSERT  REF_STORE_PERSON  VALUES ({0},{1})", store.IdSupervisor, store.Id);
             dbContext.Database.ExecuteSqlCommand(sql);
             return(JsonResultHelper.JsonResult(store.Id));
         }
     }
     catch (Exception ex)
     {
         return(JsonResultHelper.JsonResult(1000, ex.Message));
     }
 }
 public IHttpActionResult Update(InputStoreArchiveModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             //返回错误
             return(JsonResultHelper.JsonResult(1000, ModelState.Values.SelectMany(p => p.Errors.Select(s => s.ErrorMessage))));
         }
         else
         {
             //if (dbContext.ST_Store.Any(p => p.Name == model.Name))
             //{
             //    return JsonResultHelper.JsonResult(1000, "该门店已存在");
             //}
             //if (dbContext.ST_Store.Any(p => p.Code == model.Code))
             //{
             //    return JsonResultHelper.JsonResult(1000, "该门店编码已存在");
             //}
             var info = dbContext.ST_Store.FirstOrDefault(p => p.Id == model.Id);
             info.IdPersonRegion = model.IdPersonRegion;
             info.IdSupervisor   = model.IdSupervisor;
             info.Address        = model.Address;
             info.Code           = model.Code;
             info.RegionId       = model.RegionId;
             info.Remark         = model.Remark;
             info.Name           = model.Name;
             info.IdArea         = model.IdArea;
             dbContext.SaveChanges();
             return(JsonResultHelper.JsonResult(0, "OK", model));
         }
     }
     catch (Exception ex)
     {
         return(JsonResultHelper.JsonResult(1000, ex.Message));
     }
 }