Esempio n. 1
0
        public async Task PostCompayWithDuplicateISIN_ReturnsException()
        {
            var isin    = "US0378331005";
            var context = GetContextWithData();
            var service = new CompanyService(context);

            await Assert.ThrowsAsync <InvalidOperationException>(() => service.AddAsync(new Core.Models.Company()
            {
                Name     = "Test",
                Exchange = "NASDAQ",
                ISIN     = isin,
                Ticker   = "TST",
            }));
        }
        public async Task ThrowException_IfCompanyNameIsNull_Test()
        {
            var company = CompanyGeneratorUtil.GenerateCompany();

            var dto = new CompanyDto
            {
                CreationDate = company.CreationDate,
                Name         = null
            };

            var options = TestUtilities.GetOptions(nameof(ThrowException_IfCompanyNameIsNull_Test));

            using (var actContext = new EmployeeManagementSystemContext(options))
            {
                var sut = new CompanyService(actContext);
                await sut.AddAsync(dto);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!PageContext.ModelState.IsValid)
            {
                var validator   = new CompanyViewModelValidator();
                var createCheck = validator.Validate(Company);
                createCheck.AddToModelState(ModelState, nameof(Company));

                return(Page());
            }

            var company = new Company
            {
                Name = Company.Name,
                Nip  = Company.Nip,
                BankAccountNumber = Company.BankAccountNumber,
                OwnerId           = SelectedUser
            };

            await _companyService.AddAsync(company);

            return(Redirect("/"));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> RegisterIotUser([FromBody] UserRegisterIotModel user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await SysUserService.AddAsync(new SysUserDto()
                    {
                        LoginName              = user.LoginName,
                        UserName               = user.Name,
                        Password               = user.Password,
                        Email                  = user.Email,
                        SysRoleSerialnum       = user.RoleCode,
                        SysDepartmentSerialnum = user.DepartmentCode,
                        Status                 = 0,
                        CreateTime             = DateTime.Now
                    });

                    if (result > 0)
                    {
                        //添加企业
                        var company = new CompanyDto
                        {
                            Serialnum              = user.DepartmentCode + "", //todo 生成企业编码
                            Name                   = user.CompanyName,
                            Addr                   = user.Location,
                            Status                 = 0,
                            CreateTime             = DateTime.Now,
                            SysDepartmentSerialnum = user.DepartmentCode,
                            ContactMan             = user.Name,
                            ContactPhone           = user.Mobile
                        };

                        var companyInsertResult = await CompanyService.AddAsync(company);

                        if (companyInsertResult > 0)
                        {
                            //添加基地
                            var farm = new FarmDto();
                            farm.Serialnum              = company.Serialnum;
                            farm.APIKey                 = Guid.NewGuid().ToString();
                            farm.UploadPassword         = "******"; //上传密码应随机生成
                            farm.Name                   = company.Name + "-默认基地";
                            farm.CompanySerialnum       = company.Serialnum;
                            farm.Address                = company.Addr;
                            farm.ContactMan             = user.Name;
                            farm.ContactPhone           = user.Mobile;
                            farm.Status                 = false;
                            farm.SysDepartmentSerialnum = user.DepartmentCode;

                            await FarmService.AddAsync(farm);
                        }
                        else
                        {
                            ModelState.AddModelError("farm", "默认基地生成失败");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("company", "企业添加失败");
                    }
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions.Any())
                    {
                        ex.InnerExceptions.ForEach(e => { ModelState.AddModelError(e.HResult.ToString(), e); });
                    }
                }
            }
            else
            {
                ModelState.AddModelError("user", "用户添加失败");
            }
            return(new ApiV1Result(ModelState.IsValid ? ResultMessageType.Success : ResultMessageType.InternalError,
                                   ModelState.ToString(), null));
        }
Esempio n. 5
0
        public async Task <IHttpActionResult> RegisterIotUser([FromBody] UserRegisterIotModel user)
        {
            return(await ResultFactory.Create(ModelState, async arg =>
            {
                var result = await SysUserService.AddAsync(new SysUserDto()
                {
                    LoginName = user.LoginName,
                    UserName = user.Name,
                    Password = user.Password,
                    Email = user.Email,
                    SysRoleSerialnum = user.RoleCode,
                    SysDepartmentSerialnum = user.DepartmentCode,
                    Status = 0,
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                });
                if (result > 0)
                {
                    //添加企业
                    var company = new CompanyDto
                    {
                        Serialnum = user.DepartmentCode + "",     //todo 生成企业编码
                        Name = user.CompanyName,
                        Addr = user.Location,
                        Status = 0,
                        CreateTime = DateTime.Now,
                        UpdateTime = DateTime.Now,
                        SysDepartmentSerialnum = user.DepartmentCode,
                        ContactMan = user.Name,
                        ContactPhone = user.Mobile
                    };

                    var companyInsertResult = await CompanyService.AddAsync(company);
                    if (companyInsertResult > 0)
                    {
                        //添加基地
                        var farm = new FarmDto();
                        farm.Serialnum = company.Serialnum;
                        farm.APIKey = Guid.NewGuid().ToString();
                        farm.UploadPassword = "******";     //上传密码应随机生成
                        farm.Name = company.Name + "-默认基地";
                        farm.CompanySerialnum = company.Serialnum;
                        farm.Address = company.Addr;
                        farm.ContactMan = user.Name;
                        farm.CreateTime = DateTime.Now;
                        farm.UpdateTime = DateTime.Now;
                        farm.ContactPhone = user.Mobile;
                        farm.Status = false;
                        farm.SysDepartmentSerialnum = user.DepartmentCode;

                        await FarmService.AddAsync(farm);
                    }
                    else
                    {
                        ModelState.AddModelError("farm", "默认基地生成失败");
                    }
                }
                else
                {
                    ModelState.AddModelError("company", "企业添加失败");
                }
                return true;
            }, user, "success", "请检查请求参数"));
        }