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;
 }
        public CommandResultViewModel AddCustomer(CustomerInfoVM customerVM)
        {
            CommandResultViewModel vm = new CommandResultViewModel();
            try
            {
                UserService serv = new UserService();
                bool isExists = serv.ExistsUser(customerVM.UserInfo.UserName);
                if (isExists)
                {
                    vm.CommandResult = EnumCommandResult.MisMatchCondition;
                    vm.Msg = string.Format("用户名" + customerVM.UserInfo.UserName + "已经存在,请重新输入!");
                    return vm;
                }
                EMTenantService tenantServ = new EMTenantService();
                var tempTenant = tenantServ.SelectByName(customerVM.Tenant.TenantName);
                if (tempTenant != null)
                {
                    vm.CommandResult = EnumCommandResult.MisMatchCondition;
                    vm.Msg = string.Format("客户名称" + customerVM.Tenant.TenantName + "已经存在,请重新输入!");
                    return vm;
                }

                IdentityNoService identityNoServ = new IdentityNoService();
                string tenantCode = identityNoServ.GetTenantSerialNo();
                EMTenant tenant = GetEMTenant(tenantCode,customerVM.Tenant);
                EMUserGroup userGroup = GetEMUserGroup(identityNoServ, tenantCode,customerVM.UserInfo);
                EMVehicleGroup vehicleGroup = GetEMVehicleGroup(identityNoServ, customerVM.UserInfo.UserName, tenantCode);
                EMUser user = GetEMUser(identityNoServ, customerVM.UserInfo, tenant, userGroup);
                IBaseService baseServ = new BaseService();
                tenant.RegisterUserCode = user.UserCode;
                tenant.RegisterUserName = user.UserName;
                baseServ.Add<EMTenant>(tenant);
                baseServ.Add<EMUserGroup>(userGroup);
                baseServ.Add<EMVehicleGroup>(vehicleGroup);
                baseServ.Add<EMUser>(user);

                vm.CommandResult = EnumCommandResult.Success;
                vm.Msg = "新增用户成功!";
                return vm;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                vm.CommandResult = EnumCommandResult.Failed;
                vm.Msg = ex.Message;
                return vm;
            }
        }
 public ResultContent AddUser(EMUserViewModel 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 = ConvertHelper.ConvertObj<EMUserViewModel, EMUser>(userViewModel);
             entity.Tenant = new EMTenant() { TenantCode = userViewModel.TenantCode };
             userService.Add(entity);
             rc.Result = true;
             rc.Message = "添加成功!";
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message, ex);
         rc.Result = false;
         rc.Message = ex.Message;
     }
     return rc;
 }
Exemple #4
0
        public CommandResultViewModel UserReg(string userName, string pwd, string email, string QQ, string companyName)
        {
            CommandResultViewModel vm = new CommandResultViewModel();
            try
            {
                IUserService serv = new UserService();
                bool isExists = serv.ExistsUser(userName);
                if (isExists)
                {
                    vm.CommandResult = EnumCommandResult.MisMatchCondition;
                    vm.Msg = string.Format("用户名" + userName + "已经存在,请重新输入!");
                    return vm;
                }

                IEMTenantService tenantServ = new EMTenantService();
                var tempTenant = tenantServ.SelectByName(companyName);
                if (tempTenant != null)
                {
                    vm.CommandResult = EnumCommandResult.MisMatchCondition;
                    vm.Msg = string.Format("姓名/公司名" + companyName + "已经存在,请重新输入!");
                    return vm;
                }
                
                IdentityNoService identityNoServ = new IdentityNoService();
                string tenantCode = identityNoServ.GetTenantSerialNo();
                EMTenant tenant = GetTenant(tenantCode,email,QQ,companyName,userName);
                EMUserGroup userGroup = GetEMUserGroup(identityNoServ, tenantCode);
                EMVehicleGroup vehicleGroup = GetEMVehicleGroup(identityNoServ,userName, tenantCode);
                EMUser user = GetEMUser(identityNoServ,userName, pwd, email,QQ, tenant, userGroup);
                IBaseService baseServ = new BaseService();
                tenant.RegisterUserCode = user.UserCode;
                baseServ.Add<EMTenant>(tenant);
                baseServ.Add<EMUserGroup>(userGroup);
                baseServ.Add<EMVehicleGroup>(vehicleGroup);
                baseServ.Add<EMUser>(user);

                vm.CommandResult = EnumCommandResult.Success;
                return vm;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                vm.CommandResult = EnumCommandResult.Failed;
                vm.Msg = ex.Message;
                return vm;
            }
        }