Exemplo n.º 1
0
        public ResultContent UpdateUserIncludeVehicle(EMUserGroupOrViewModel userViewModel)
        {
            ResultContent rc = new ResultContent();
            try
            {
                IUserService userService = new UserService();

                EMUser newEntity = ConvertTo(userViewModel);
                EMUser oldEntity = userService.GetUser(newEntity.UserCode);
                newEntity.CreateTime = oldEntity.CreateTime;
                userService.Update(newEntity);
                IEMVehicleOfUserService vosSerive = new EMVehicleOfUserService();
                //先删除再添加
                vosSerive.Delete(newEntity.UserCode);
                if (userViewModel.UserGroupID == null)
                {
                    var query = from f in userViewModel.VehicleCodeList select new EMVehicleOfUser { UserCode = newEntity.UserCode, VehicleCode = f };
                    List<EMVehicleOfUser> vosList = query.ToList();
                    vosSerive.Insert(vosList);
                }
                rc.Result = true;
                rc.Message = "修改成功!";
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                rc.Result = false;
                rc.Message = ex.Message;
            }
            return rc;
        }
Exemplo n.º 2
0
 public ResultContent AddUserIncludeVehicle(EMUserGroupOrViewModel userViewModel)
 {
     ResultContent rc = new ResultContent();
     try
     {
         IUserService userService = new UserService();
         bool bl = userService.ExistsUser(userViewModel.UserName);
         if (bl)
         {
             rc.Result = false;
             rc.Message = "用户名已存在!";
         }
         else
         {
             IdentityNoService identityNoServ = new IdentityNoService();
             userViewModel.UserCode = identityNoServ.GetUserSerialNo();
             userViewModel.CreateTime = DateTime.Now;
             EMUser entity = ConvertTo(userViewModel);
             entity.Tenant = new EMTenant() { TenantCode = entity.TenantCode };
             userService.Add(entity);
             if (userViewModel.UserGroupID == null)
             {
                 var query = from f in userViewModel.VehicleCodeList select new EMVehicleOfUser { UserCode = entity.UserCode, VehicleCode = f };
                 List<EMVehicleOfUser> vosList = query.ToList();
                 IEMVehicleOfUserService vosSerive = new EMVehicleOfUserService();
                 vosSerive.Insert(vosList);
             }
             rc.Result = true;
             rc.Message = "添加成功!";
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message, ex);
         rc.Result = false;
         rc.Message = ex.Message;
     }
     return rc;
 }