public IActionResult Register([FromBody] RegisterDto dto) { if (!ModelState.IsValid) { return(BadRequest()); } if (_context.AlpsUsers.Count(p => p.IDName == dto.Username) > 0) { return(this.AlpsActionWarning("已有相同用户名了,请更改用户名")); } AlpsUser newUser = AlpsUser.Create(dto.Username, dto.Password, dto.RealName, dto.IdentityNumber, dto.MobilePhoneNumber); newUser.AddRole(_context.AlpsRoles.FirstOrDefault(p => p.Name == "User")); _context.AlpsUsers.Add(newUser); if (_context.SaveChanges() == 2) { return(this.AlpsActionOk()); } else { return(this.AlpsActionWarning("身份信息有误,注册失败")); } }
void CommonMgrSeed(AlpsContext context) { #region 初始化管理员 AlpsRole role = AlpsRole.Create("Admin", "管理员"); context.AlpsRoles.Add(role); AlpsUser user = AlpsUser.Create("a", "a", "李", "123456", "223344"); user.AddRole(role); role = AlpsRole.Create("User", "用户"); context.AlpsRoles.Add(role); user.AddRole(role); context.AlpsUsers.Add(user); user = AlpsUser.Create("b", "b", "张三", "112233", "789789"); user.AddRole(role); context.AlpsUsers.Add(user); role = AlpsRole.Create("Cashier", "出纳"); context.AlpsRoles.Add(role); user = AlpsUser.Create("cw", "cw", "财务", "11", "22"); user.AddRole(role); context.AlpsUsers.Add(user); #endregion #region 初始化地址 context.Countries.Add(Country.Create("菲律宾")); Country country = Country.Create("中国"); context.Countries.Add(country); context.Provinces.Add(Province.Create("浙江省", country.ID)); context.Provinces.Add(Province.Create("广东省", country.ID)); context.Provinces.Add(Province.Create("江西省", country.ID)); context.Provinces.Add(Province.Create("湖南省", country.ID)); Province province = Province.Create("福建省", country.ID); context.Provinces.Add(province); context.Cities.Add(City.Create("泉州市", province.ID)); context.Cities.Add(City.Create("莆田市", province.ID)); context.Cities.Add(City.Create("宁德市", province.ID)); City city = City.Create("福州市", province.ID); context.Cities.Add(city); context.Counties.Add(County.Create("福清市", city.ID)); context.Counties.Add(County.Create("闽候县", city.ID)); context.Counties.Add(County.Create("鼓楼区", city.ID)); County county = County.Create("长乐区", city.ID); context.Counties.Add(county); context.SaveChanges(); #endregion #region 初始化部门 Department d = Department.Create("供销科"); context.Departments.Add(d); d = Department.Create("轧钢车间"); productDepartmentID = d.ID; context.Departments.Add(d); d = Department.Create("焊管车间"); context.Departments.Add(d); d = Department.Create("采购部"); context.Departments.Add(d); context.SaveChanges(); departmentID = d.ID; #endregion #region 初始化客户 Address address = Address.Create(county, "青口钢材市场"); Customer c = Customer.Create("江水金", address); context.Customers.Add(c); address = Address.Create(county, "青口钢材市场"); c = Customer.Create("陈依寿", address); context.Customers.Add(c); address = Address.Create(county, "青口钢材市场"); c = Customer.Create("林光江", address); context.Customers.Add(c); context.SaveChanges(); customerID = c.ID; #endregion #region 初始化供应商 SupplierClass sc = SupplierClass.Create("配件供应商"); context.SupplierClasses.Add(sc); sc = SupplierClass.Create("煤碳供应商"); context.SupplierClasses.Add(sc); SupplierClass gpsc = SupplierClass.Create("坯料供应商"); context.SupplierClasses.Add(gpsc); address = Address.Create(county, "漳州"); Supplier s = Supplier.Create("三宝", gpsc.ID, address); context.Suppliers.Add(s); address = Address.Create(county, "罗源"); s = Supplier.Create("亿鑫", gpsc.ID, address); context.Suppliers.Add(s); address = Address.Create(county, "松下镇"); s = Supplier.Create("大东海", gpsc.ID, address); context.Suppliers.Add(s); address = Address.Create(county, "吴航镇"); s = Supplier.Create("锦强", sc.ID, address); context.Suppliers.Add(s); context.SaveChanges(); supplierID = s.ID; #endregion #region 初始化交易账户 TradeAccount ta = TradeAccount.Create("宏建", TradeAccountType.SupplierAndCustomer, "13900000000", ""); context.TradeAccounts.Add(ta); ta = TradeAccount.Create("富鑫", TradeAccountType.SupplierAndCustomer, "13900000001", ""); context.TradeAccounts.Add(ta); ta = TradeAccount.Create("江水金", TradeAccountType.Customer, "13900000003", ""); context.TradeAccounts.Add(ta); ta = TradeAccount.Create("陈依寿", TradeAccountType.Customer, "13900000005", ""); context.TradeAccounts.Add(ta); ta = TradeAccount.Create("永盛金属", TradeAccountType.Customer, "13900000006", ""); context.TradeAccounts.Add(ta); ta = TradeAccount.Create("永盛钢贸", TradeAccountType.Customer, "13900000006", ""); context.TradeAccounts.Add(ta); context.SaveChanges(); #endregion #region 初始化单位 Unit unit = Unit.Create("吨", 1, false, 1000); context.Units.Add(unit); unitID = unit.ID; context.Units.Add(Unit.Create("公斤", 1, true)); context.Units.Add(Unit.Create("件", 2, true)); context.SaveChanges(); #endregion #region 初始化仓位 context.Positions.Add(new Position() { Name = "新建616", Number = "616", Warehouse = "新建仓库" }); Position position = new Position() { Name = "小槽315", Number = "315", Warehouse = "小槽仓库" }; context.Positions.Add(position); positionID = position.ID; position = new Position() { Name = "坯场-1", Number = "901", Warehouse = "坯场" }; context.Positions.Add(position); position = new Position() { Name = "坯场-2", Number = "902", Warehouse = "坯场" }; context.Positions.Add(position); context.SaveChanges(); #endregion #region 初始化类别 Catagory nCatagory = Catagory.Create("钢材"); nCatagory.AddChildCatagory(Catagory.Create("槽钢") .AddChildCatagory(Catagory.Create("5#")).AddChildCatagory(Catagory.Create("6.3#")). AddChildCatagory(Catagory.Create("8#")).AddChildCatagory(Catagory.Create("10#")) .AddChildCatagory(Catagory.Create("12#")).AddChildCatagory(Catagory.Create("14#")) .AddChildCatagory(Catagory.Create("16#")).AddChildCatagory(Catagory.Create("18#")) .AddChildCatagory(Catagory.Create("20#"))) .AddChildCatagory(Catagory.Create("角钢") .AddChildCatagory(Catagory.Create("3#")).AddChildCatagory(Catagory.Create("4#")) .AddChildCatagory(Catagory.Create("5#")).AddChildCatagory(Catagory.Create("6#"))) .AddChildCatagory(Catagory.Create("工字钢") .AddChildCatagory(Catagory.Create("10#")).AddChildCatagory(Catagory.Create("12#")) .AddChildCatagory(Catagory.Create("14#")).AddChildCatagory(Catagory.Create("16#")) .AddChildCatagory(Catagory.Create("18#")).AddChildCatagory(Catagory.Create("20a#"))); context.Catagories.Add(nCatagory); nCatagory = Catagory.Create("坯料").AddChildCatagory(Catagory.Create("连铸坯")); context.Catagories.Add(nCatagory); nCatagory = Catagory.Create("镀锌板管") .AddChildCatagory(Catagory.Create("方管").AddChildCatagory(Catagory.Create("16方")).AddChildCatagory(Catagory.Create("20方")).AddChildCatagory(Catagory.Create("32方"))) .AddChildCatagory(Catagory.Create("矩形管").AddChildCatagory(Catagory.Create("20*40")).AddChildCatagory(Catagory.Create("30*50")).AddChildCatagory(Catagory.Create("40*60"))) .AddChildCatagory(Catagory.Create("圆管").AddChildCatagory(Catagory.Create("2寸")).AddChildCatagory(Catagory.Create("3寸")).AddChildCatagory(Catagory.Create("4寸"))); context.Catagories.Add(nCatagory); nCatagory = Catagory.Create("轧辊"); context.Catagories.Add(nCatagory); context.SaveChanges(); #endregion #region 初始化产品 Product product = null; Catagory associatedCatagory = context.Catagories.FirstOrDefault(p => p.Name == "5#"); for (int i = 13; i < 30; i = i + 2) { product = Product.Create(associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(associatedCatagory); context.Products.Add(product); } associatedCatagory = context.Catagories.FirstOrDefault(p => p.Name == "6.3#"); for (int i = 15; i < 38; i = i + 2) { product = Product.Create(associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(associatedCatagory); context.Products.Add(product); } associatedCatagory = context.Catagories.FirstOrDefault(p => p.Name == "8#"); for (int i = 17; i < 48; i = i + 2) { product = Product.Create(associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", associatedCatagory.Name + i.ToString() + "-" + (i + 1).ToString() + "Kg", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(associatedCatagory); context.Products.Add(product); } foreach (Catagory childCatagory in context.Catagories.FirstOrDefault(p => p.Name == "工字钢").Children) { product = Product.Create(childCatagory.Name + "下偏3-5%", childCatagory.Name + "下偏3-5%", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(childCatagory); context.Products.Add(product); product = Product.Create(childCatagory.Name + "下偏8-10%", childCatagory.Name + "下偏8-10%", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(childCatagory); context.Products.Add(product); product = Product.Create(childCatagory.Name + "下偏18-20%", childCatagory.Name + "下偏18-20%", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(childCatagory); context.Products.Add(product); } associatedCatagory = context.Catagories.FirstOrDefault(p => p.Name == "连铸坯"); product = Product.Create("150*150", "150*150连铸坯", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(associatedCatagory); context.Products.Add(product); product = Product.Create("120*120", "120*120连铸坯", "系统创建", PricingMethod.PricingByWeight, 2000, unitID); product.SetCatagory(associatedCatagory); context.Products.Add(product); context.SaveChanges(); #endregion #region 初始化SKU ProductSku sku = null; foreach (Product p in context.Products.Where(p => p.Catagory.Name == "5#")) { //sku = ProductSku.Create(p, "6米*144条", "系统初始化"); sku = ProductSku.Create(p.ID, p.Name + " " + "6米*144条", "系统初始化", "", true, "", 3800, 2.3m, 0, 0); context.ProductSkus.Add(sku); } gcSkuID = sku.ID; foreach (Product p in context.Products.Where(p => p.Catagory.Name == "6.3#")) { sku = ProductSku.Create(p.ID, p.Name + " " + "6米*96条", "系统初始化", "", true, "", 3800, 2.3m, 0, 0); //sku = ProductSku.Create(p, "6米*96条", "系统初始化"); context.ProductSkus.Add(sku); } foreach (Product p in context.Products.Where(p => p.Catagory.Name == "8#")) { sku = ProductSku.Create(p.ID, p.Name + " " + "6米*84条", "系统初始化", "", true, "", 3800, 3.6m, 0, 0); //sku = ProductSku.Create(p, "6米*84条", "系统初始化"); context.ProductSkus.Add(sku); sku = ProductSku.Create(p.ID, p.Name + " " + "6米*64条", "系统初始化", "", true, "", 3800, 3.6m, 0, 0); //sku = ProductSku.Create(p, "9米*64条", "系统初始化"); context.ProductSkus.Add(sku); } // foreach (Product p in context.Products.Where(p => p.Catagory.Name == "连铸坯")) // { // sku = ProductSku.Create(p.ID, p.Name + " " + "6米", "系统初始化", "", false); // //sku = ProductSku.Create(p, "6米", "系统初始化"); // context.ProductSkus.Add(sku); // sku = ProductSku.Create(p.ID, p.Name + " " + "12米", "系统初始化", "", false); // //sku = ProductSku.Create(p, "12米", "系统初始化"); // context.ProductSkus.Add(sku); // } var gp = context.Products.FirstOrDefault(p => p.Name == "150*150"); var newSku = ProductSku.Create(gp.ID, "亿鑫150*150*12M", "", "9001", false); context.ProductSkus.Add(newSku); gpSkuID = newSku.ID; newSku = ProductSku.Create(gp.ID, "大东海150*150*12M", "", "9002", false); context.ProductSkus.Add(newSku); newSku = ProductSku.Create(gp.ID, "春兴150*150*12M", "", "9003", false); context.ProductSkus.Add(newSku); newSku = ProductSku.Create(gp.ID, "东华150*150*12M", "", "9003", false); context.ProductSkus.Add(newSku); context.SaveChanges(); #endregion }