Ejemplo n.º 1
0
 public void CreateNewUnit(EditUnitModel model)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var unit = new Unit()
         {
             Name = model.FormData.Name,
             IsFlowUint = model.FormData.IsFlowUnit,
             IsWebUint = model.FormData.IsWebUnit,
             ParentUint = model.ParentId.HasValue ? _unitRepository.Find(model.ParentId.Value) : null
         };
         _unitRepository.Save(unit);
         var user = new User()
         {
             Account = "admin",
             Name = "管理员",
             Pwd = Md5Utility.GetMd5HashCode("admin"),
             Unit = unit
         };
         InitUnitPermissions(unit, user);
         _userRepository.Save(user);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Ejemplo n.º 2
0
 public JsonResult EditUnitPost(EditUnitModel model)
 {
     try
     {
         _unitAction.CreateNewUnit(model);
     }
     catch (Exception)
     {
         return new NewtonsoftJsonResult() { Data = new { status = "failure" } };
     }
     return new NewtonsoftJsonResult() { Data = new { status = "success" } };
 }
Ejemplo n.º 3
0
 public void UpdateUnit(EditUnitModel model)
 {
     if (model.Id == null)
         throw new ArgumentException("id不能为null");
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var unit = _unitRepository.Find(model.Id.Value);
         unit.Name = model.FormData.Name;
         unit.IsWebUint = model.FormData.IsWebUnit;
         unit.IsFlowUint = model.FormData.IsFlowUnit;
         var admin = _userRepository.FindByAccount("admin", unit.Id);
         InitUnitPermissions(unit, admin);
         _unitRepository.Save(unit);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }