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;
            }
        }
示例#2
0
        //新增客户
        public ActionResult AddCustomer(string UserName, string PassWord, string TenantName, string PhoneNumber, string Email)
        {
            CustomerInfoVM param = new CustomerInfoVM();
            param.UserInfo = new UserInfoViewModel();
            param.UserInfo.UserName = UserName;
            param.UserInfo.Password = PassWord;

            param.Tenant = new TenantViewModel();
            param.Tenant.TenantName = TenantName;
            param.Tenant.PhoneNumber = PhoneNumber;
            param.Tenant.Email = Email;
            if (SessionUserInfo.SelectedOperate != null)
            {
                param.Tenant.SuperTenantID = SessionUserInfo.SelectedOperate.TenantCode;
            }
            else
            {
                param.Tenant.SuperTenantID = SessionUserInfo.TenantCode;
            }
            param.UserInfo.EncryptPwd = MD5Core.Encrypt(param.UserInfo.Password);

            CommandResultViewModel vm = this._OperationsService.AddCustomer(param);

            int result = (vm != null && (int)vm.CommandResult == 0) ? 1 : 0;
            
            return Json(new
            {
                result = result,
                data = vm.Msg
            });
        }
示例#3
0
 private List<CustomerInfoVM> ConvertToVM(IList<EMTenant> ltTenant)
 {
     List<CustomerInfoVM> ltVM = new List<CustomerInfoVM>();
     foreach (var tenant in ltTenant)
     {
         CustomerInfoVM vm = new CustomerInfoVM();
         vm.UserInfo = new UserInfoViewModel()
         {
             TenantCode = tenant.TenantCode,
             UserCode = tenant.RegisterUserCode,
             UserName = tenant.RegisterUserName
         };
         vm.Tenant = ConvertToViewModel(ltTenant.FirstOrDefault(s => s.TenantCode == tenant.TenantCode));
         ltVM.Add(vm);
     }
     return ltVM;
 }