Ejemplo n.º 1
0
 public MyAccountController(
     ExtendedIdentityDbContext <User, Role> dbContext,
     ExtendedUserManager <User> userManager,
     IConfiguration configuration,
     IdentityServerApiEndpointsOptions identityServerApiEndpointsOptions,
     IEmailService emailService,
     IPlatformEventService eventService,
     IOptions <GeneralSettings> generalSettings,
     IOptionsSnapshot <IdentityOptions> identityOptions,
     ISmsServiceFactory smsServiceFactory,
     ExtendedConfigurationDbContext configurationDbContext,
     IPersistedGrantStore persistedGrantStore,
     IPersistentGrantSerializer serializer
     )
 {
     _configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _dbContext       = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _emailService    = emailService;
     _eventService    = eventService ?? throw new ArgumentNullException(nameof(eventService));
     _generalSettings = generalSettings?.Value ?? throw new ArgumentNullException(nameof(generalSettings));
     _identityOptions = identityOptions?.Value ?? throw new ArgumentNullException(nameof(identityOptions));
     _identityServerApiEndpointsOptions = identityServerApiEndpointsOptions ?? throw new ArgumentNullException(nameof(identityServerApiEndpointsOptions));
     _smsServiceFactory      = smsServiceFactory ?? throw new ArgumentNullException(nameof(smsServiceFactory));
     _userManager            = userManager ?? throw new ArgumentNullException(nameof(userManager));
     _configurationDbContext = configurationDbContext ?? throw new ArgumentNullException(nameof(configurationDbContext));
     _persistedGrantStore    = persistedGrantStore ?? throw new ArgumentNullException(nameof(persistedGrantStore));
     _serializer             = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
        BuildQueryableCore(ExtendedIdentityDbContext db, IQueryable <OrderContract> sourceQuery)
        {
            var noTrackingDbQuery = sourceQuery;

            if (noTrackingDbQuery == null)
            {
                noTrackingDbQuery = db.OrderContracts.Include("OrderProducts").AsNoTracking();
            }

            try
            {
                IQueryable <OrderContract> tempDbQuery = noTrackingDbQuery;

                if (!this.IsEmptySupplier())
                {
                    tempDbQuery = tempDbQuery.Where(m => m.SupplierId == this.SupplierId.Value);
                }

                tempDbQuery = AddTimeConditions(tempDbQuery);

                tempDbQuery = AddLiteralConditions(db, tempDbQuery);

                tempDbQuery = AddEntityPrivilegeControlConditions(db,
                                                                  tempDbQuery, EntityControlType.OrderContract, this.UserName);

                return(tempDbQuery);
            }
            catch (Exception ee)
            {
                LogHelper.Error("OrderContractPrivilegeFilter创建过滤条件出错。", ee);
            }

            return(noTrackingDbQuery);
        }
        private void FindCreateAssignRole(ApplicationUserManager userManager,
                                          ApplicationRoleManager roleManager, SysUser user,
                                          string password, string roleName, ExtendedIdentityDbContext context)
        {
            int userid = userManager.Users.AsNoTracking().Where(
                c => c.UserName == user.UserName).Select(u => u.Id).FirstOrDefault();

            if (userid < 1)
            {
                user.CTIME = DateTime.Now;
                var result1 = userManager.Create(user, password);
                if (result1.Succeeded)
                {
                    userid = userManager.Users.AsNoTracking().Where(
                        c => c.UserName == user.UserName).Select(u => u.Id).FirstOrDefault();
                }
            }

            var result2 = userManager.AddToRole(userid, roleName);

            OutputInitError(result2);
            //using (var tran = context.Database.BeginTransaction())
            //{
            //    context.Database.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction,
            //        string.Format("UPDATE aspnetusers SET Id = -{0} WHERE Id = {0}", userid));
            //    context.Database.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction,
            //        string.Format("UPDATE aspnetuserroles SET UserId = -{0} WHERE UserId = {0}", userid));
            //    tran.Commit();
            //}
        }
        private void AddDecendants(XElement element, SysMenu menu, ExtendedIdentityDbContext context)
        {
            if (element == null || menu == null || context == null)
            {
                return;
            }
            var items = element.Elements("item");

            if (items == null || items.Count() <= 0)
            {
                return;
            }

            int counter2 = 1;

            foreach (var item in items)
            {
                SysMenu child = ToMenu(item);
                if (item != null)
                {
                    child.IsShowInNavTree = counter2;
                    counter2++;
                    child.ParentId = menu.SysMenuId;
                    //context.SysMenus.AddOrUpdate<SysMenu>(m =>
                    //new { m.Area, m.Controller, m.Action }, child);
                    context.SysMenus.AddOrUpdate(m => m.MenuName, child);
                }
            }
            UtilityFramework.DbUpdateConcurrencyExceptionResolver
            .SaveAndResolveExceptionServerWin(context);
        }
        private void InitUsers(ExtendedIdentityDbContext context)
        {
            IdentityManager manager     = new IdentityManager(context);
            var             userManager = manager.UserManager;
            var             roleManager = manager.RoleManager;

            this.InitRoles(roleManager, context);
#if DEBUG
            var user = new SysUser()
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                Name        = "梁达文",
                PhoneNumber = "13826403668",
            };
            FindCreateAssignRole(userManager, roleManager, user, "Admin@12345",
                                 "系统管理员", context);
#else
            var user = new SysUser()
            {
                UserName    = "******",
                Email       = "*****@*****.**",
                Name        = "Administrator",
                PhoneNumber = "13826403668",
            };
            FindCreateAssignRole(userManager, roleManager, user,
                                 "Admin@12345", "系统管理员", context);
#endif
        }
Ejemplo n.º 6
0
        private IQueryable <SaleContract> BuildQueryableCore(ExtendedIdentityDbContext db,
                                                             IQueryable <SaleContract> sourceQuery)
        {
            var noTrackingDbQuery = sourceQuery;

            if (noTrackingDbQuery == null)
            {
                noTrackingDbQuery = db.SaleContracts.AsNoTracking();
            }

            try
            {
                IQueryable <SaleContract> tempDbQuery = noTrackingDbQuery;

                tempDbQuery = AddTimeConditions(tempDbQuery);

                tempDbQuery = AddLiteralConditions(db, tempDbQuery);

                tempDbQuery = AddEntityPrivilegeControlConditions(db,
                                                                  tempDbQuery, EntityControlType.SaleContract, this.UserName);

                return(tempDbQuery);
            }
            catch (Exception ee)
            {
                LogHelper.Error("SaleContractPrivilegeFilter创建过滤条件出错。", ee);
            }

            return(noTrackingDbQuery);
        }
        internal string UpdateSaleContractStatusCore(ExtendedIdentityDbContext dbContext,
                                                     SaleContract contract, ContractStatus contractStatus, string userName)
        {
            if (contract == null)
            {
                return("SaleContract model为空。");
            }

            try
            {
                contract.ContractStatus = contractStatus;

                string errorMessage2 = AddOrUpdateSaleContractFinancialObjsSecond(
                    dbContext, userName, contract);
                if (!string.IsNullOrWhiteSpace(errorMessage2))
                {
                    return(errorMessage2);
                }

                int effectedRows = dbContext.SaveChanges();

                if (effectedRows < 1)
                {
                    return("修改SaleContract审核状态失败。");
                }
            }
            catch (Exception ee)
            {
                LogHelper.Error("修改SaleContract审核状态失败。", ee);
                return(ee.Message);
            }

            return(string.Empty);
        }
Ejemplo n.º 8
0
        private void InitOneOrderContractType1(ExtendedIdentityDbContext context, int counter)
        {
            string key = "DEMO10" + counter;

            if (context.OrderContracts.Any(m => m.OrderContractKey == key))
            {
                return;
            }

            OrderContract contract = context.OrderContracts.Create();

            contract.OrderContractKey = key;// "DEMO10" + counter;
            contract.OrderCreateTime  = DateTime.Now;
            contract.OrderSysUserKey  = (counter % 2 == 0) ? "user" : "manager";
            contract.OrderType        = 1;
            contract.SupplierId       = context.Suppliers.Max(m => m.SupplierId);
            //contract.Destination = context.Harbors.FirstOrDefault();
            contract.HarborId              = context.Harbors.Min(m => m.HarborId);
            contract.Payment               = "unknown";
            contract.ImportDeposite        = 10000;
            contract.ImportBalancedPayment = 5000;
            contract.ShipmentPeriod        = "DEMO_SHIP_" + counter;
            //contract.SalesGuidePrice = 15000;
            contract.ContractStatus     = ContractStatus.AuditPassed;
            contract.ContainerSerial    = "DEMO_SERIAL_" + counter;
            contract.Comments           = "DEMO_COMMENT_" + counter;
            contract.DeliveryBillSerial = "DEMO_DELIVERY_" + counter;
            contract.OrderProducts      = this.GenerateOrderProducts(context, counter);

            context.OrderContracts.AddOrUpdate(p => p.OrderContractKey, (contract));
        }
Ejemplo n.º 9
0
        public CustomMigrationResult CustomMigrationSeed(
            ExtendedIdentityDbContext context, bool isExternalSeeding,
            string customMigrationKey)
        {
            try
            {
                InitProducts(context);
                InitSuppliers(context);
                InitHKLogis(context);
                InitMainlandLogis(context);
                InitDeclarationCompanies(context);
                InitHarbors(context);
                InitStoreHouses(context);
                InitSaleClients(context);
            }
            catch (Exception e)
            {
                LogHelper.Error("初始化基础数据项出错。", e);
                //return new CustomMigrationResult(MigrationKey, false)
                //{
                //    ErrorMessage = "初始化基础数据项出错。",
                //    HappenedException = e,
                //};
            }

            try
            {
                InitUsers(context);
            }
            catch (Exception e)
            {
                LogHelper.Error("初始化用户出错。", e);
                //return new CustomMigrationResult(MigrationKey, false)
                //{
                //    ErrorMessage = "初始化用户出错。",
                //    HappenedException = e,
                //};
            }

            try
            {
                InitOrderContracts(context);
                InitStockItems(context);
            }
            catch (Exception e)
            {
                LogHelper.Error("初始化Demo数据出错。", e);
                //return new CustomMigrationResult(MigrationKey, false)
                //{
                //    ErrorMessage = "初始化Demo数据出错。",
                //    HappenedException = e,
                //    GoToNextWhenExceptionHappend = true,
                //};
            }

            return(new CustomMigrationResult(MigrationKey, true));
        }
        BuildQueryable(ExtendedIdentityDbContext db, IQueryable <OrderContract> sourceQuery)
        {
            if (!this.IsEmptyFilter())
            {
                return(this.BuildQueryableCore(db, sourceQuery));
            }

            return(sourceQuery != null ? sourceQuery : db.OrderContracts.AsNoTracking());
        }
        /*
         * internal string AddOrUpdateSaleContractBargainCore(ExtendedIdentityDbContext dbContext,
         *  SaleBargain bargain)
         * {
         *  if (bargain == null || bargain.BargainItems == null || bargain.SaleContractId < 1)
         *      return "还价信息不正确,请核对还价的销售合同及其对应的货品项数目是否与还价的货品项一致。";
         *
         *  try
         *  {
         *      SaleContract contract = dbContext.SaleContracts.Find(bargain.SaleContractId);
         *      if (contract == null || contract.SaleProducts.Count != bargain.BargainItems.Count)
         *          return "还价信息不正确,请核对还价的销售合同及其对应的货品项数目是否与还价的货品项一致。";
         *
         *      SaleBargain saleItem = dbContext.SaleBargains.FirstOrDefault(
         *          m => m.SaleContractId == bargain.SaleContractId &&
         *          m.BargainSysUserKey == bargain.BargainSysUserKey);
         *
         *      if (saleItem == null)
         *      {//Add
         *          saleItem = AddSaleContractBargainCore(dbContext, bargain, saleItem);
         *      }
         *      else
         *      {//Update
         *          UpdateSaleContractBargainCore(dbContext, bargain, saleItem);
         *      }
         *
         *      dbContext.SaveChanges();
         *  }
         *  catch (Exception e)
         *  {
         *      LogHelper.Error("添加销售还价失败。", e);
         *      return "添加销售还价失败。\t\t" + e.Message + "\t\t" + e.StackTrace;
         *  }
         *
         *  //TODO:
         *  return string.Empty;
         * }
         *
         * private SaleBargain AddSaleContractBargainCore(ExtendedIdentityDbContext dbContext,
         *  SaleBargain bargain, SaleBargain saleItem)
         * {
         *  saleItem = dbContext.SaleBargains.Create();
         *  saleItem.BargainSysUserKey = bargain.BargainSysUserKey;
         *  saleItem.OperationState = bargain.OperationState;
         *  saleItem.SaleContractId = bargain.SaleContractId;
         *  var items = from one in bargain.BargainItems
         *              select this.CreateNewOne(dbContext, one);
         *  //foreach (var i in bargain.BargainItems) {
         *  saleItem.BargainItems = items.ToList();
         *  SaleBargainChangeRecord record = dbContext.SaleBargainChangeRecords.Create();
         *  record.CTIME = DateTime.Now;
         *  record.SaleBargin = saleItem;
         *  record.CurrentTotal = saleItem.Total;
         *  record.Comments = string.Format("{1}创建还价,还价为:{0}。", saleItem.Total, record.CTIME.ToString("yyyyMMdd HH:mm:ss"));
         *  dbContext.SaleBargainChangeRecords.Add(record);
         *  dbContext.SaleBargains.Add(saleItem);
         *  return saleItem;
         * }
         *
         * private void UpdateSaleContractBargainCore(ExtendedIdentityDbContext dbContext,
         *  SaleBargain bargain, SaleBargain saleItem)
         * {
         *  saleItem.BargainSysUserKey = bargain.BargainSysUserKey;
         *  saleItem.OperationState = bargain.OperationState;
         *  saleItem.SaleContractId = bargain.SaleContractId;
         *  var items = from one in saleItem.BargainItems
         *              from two in bargain.BargainItems
         *              where one.SaleProductItemId == two.SaleProductItemId
         *              select new { one, two };
         *  foreach (var gp in items)
         *  {
         *      gp.one.BargainUnitPrice = gp.two.BargainUnitPrice;
         *  }
         *
         *  SaleBargainChangeRecord record = dbContext.SaleBargainChangeRecords.Create();
         *  record.CTIME = DateTime.Now;
         *  record.SaleBargin = saleItem;
         *  record.PrevTotal = bargain.Total;
         *  record.CurrentTotal = saleItem.Total;
         *  record.Comments = string.Format("{2}修改还价,还价从 {1} 调整为:{0}。",
         *      saleItem.Total, bargain.Total, record.CTIME.ToString("yyyyMMdd HH:mm:ss"));
         *  dbContext.SaleBargainChangeRecords.Add(record);
         * }*/
        #endregion

        private SaleBargainItem CreateNewOne(
            ExtendedIdentityDbContext dbContext, SaleBargainItem one)
        {
            var newItem = dbContext.SaleBargainItems.Create();

            newItem.BargainUnitPrice  = one.BargainUnitPrice;
            newItem.SaleProductItemId = one.SaleProductItemId;
            return(newItem);
        }
Ejemplo n.º 12
0
        private void InitStoreHouses(ExtendedIdentityDbContext context)
        {
            YuShang.ERP.Entities.ResMgr.StoreHouse house =
                new YuShang.ERP.Entities.ResMgr.StoreHouse()
            {
                Address        = "",
                Email          = "*****@*****.**",
                FAX            = "FAX1234567",
                MobilePhone    = "13650886886",
                Name           = "仓管人员A",
                Telephone      = "02025163223",
                StorageVolume  = "50000平方米",
                StoreHouseName = "新仓一",
            };
            context.StoreHouses.AddOrUpdate(m => m.StoreHouseName, house);

            house = new YuShang.ERP.Entities.ResMgr.StoreHouse()
            {
                Address        = "",
                Email          = "*****@*****.**",
                FAX            = "FAX2345671",
                MobilePhone    = "13650226886",
                Name           = "仓管人员B",
                Telephone      = "02025163663",
                StorageVolume  = "60000平方米",
                StoreHouseName = "新仓二",
            };
            context.StoreHouses.AddOrUpdate(m => m.StoreHouseName, house);

            house = new YuShang.ERP.Entities.ResMgr.StoreHouse()
            {
                Address        = "",
                Email          = "*****@*****.**",
                FAX            = "FAX3456712",
                MobilePhone    = "13650886886",
                Name           = "仓管人员c",
                Telephone      = "02025169873",
                StorageVolume  = "6000平方米",
                StoreHouseName = "山顶",
            };
            context.StoreHouses.AddOrUpdate(m => m.StoreHouseName, house);

            house = new YuShang.ERP.Entities.ResMgr.StoreHouse()
            {
                Address        = "",
                Email          = "*****@*****.**",
                FAX            = "FAX4567123",
                MobilePhone    = "13650886995",
                Name           = "仓管人员d",
                Telephone      = "02020303223",
                StorageVolume  = "25000平方米",
                StoreHouseName = "城东A",
            };
            context.StoreHouses.AddOrUpdate(m => m.StoreHouseName, house);
            SaveChangesResolvingConcurrencyException(context);
        }
Ejemplo n.º 13
0
        public IQueryable <YuShang.ERP.Entities.Sale.SaleContract> BuildQueryable(
            ExtendedIdentityDbContext db, IQueryable <SaleContract> sourceQuery)
        {
            if (!this.IsEmptyFilter())
            {
                return(this.BuildQueryableCore(db, sourceQuery));
            }

            return(sourceQuery != null ? sourceQuery : db.SaleContracts.AsNoTracking());
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructs a new <see cref="DeveloperTotpService"/>.
 /// </summary>
 /// <param name="totpService">Used to generate, send and verify time based one time passwords.</param>
 /// <param name="identityDbContext"><see cref="Microsoft.EntityFrameworkCore.DbContext"/> for the Identity Framework.</param>
 /// <param name="userManager">Provides the APIs for managing user in a persistence store.</param>
 public DeveloperTotpService(
     TotpService totpService,
     ExtendedIdentityDbContext <User, Role> identityDbContext,
     UserManager <User> userManager
     )
 {
     _totpService = totpService ?? throw new ArgumentNullException(nameof(totpService));
     _dbContext   = identityDbContext ?? throw new ArgumentNullException(nameof(identityDbContext));
     _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
 }
        private IQueryable <SaleContract> GetIndexListSaleContract(
            ExtendedIdentityDbContext dbContext, ISaleContractQueryBuilder builder)
        {
            IQueryable <SaleContract> contractQuery = builder.BuildQueryable(dbContext,
                                                                             dbContext.SaleContracts.Include("SaleProducts.OrderProductItem.Product")
                                                                             .Include("SaleBargins.BargainItems")
                                                                             .AsNoTracking());

            return(contractQuery);
        }
        private IQueryable <OrderContract> AddLiteralConditions(ExtendedIdentityDbContext db,
                                                                IQueryable <OrderContract> tempDbQuery)
        {
            // var products = ResBusinessManager.Instance.GetProducts();
            //通过找出OrderContractKey,寻找OrderContract对象
            //string[] tempKeys = null;

            //IEnumerable<string> tempKey1 = null;
            //if (!this.IsEmptyProductKeys(ref tempKeys))
            //{
            //    tempKey1 = (from one in db.Products//products
            //                where tempKeys.Contains(one.ProductKey)
            //                select one.ProductKey);
            //}

            IEnumerable <int> tempKey2 = null;

            if (!this.IsEmptyProductFullNameFilterValue())
            {
                var filterValue = this.ProductFullNameFilterValue.Trim().ToLowerInvariant();

                tempKey2 = (from one in db.Products
                            where
                            one.ProductName.ToLowerInvariant().Contains(filterValue) ||
                            one.MadeInFactory.ToLowerInvariant().Contains(filterValue) ||
                            one.MadeInCountry.ToLowerInvariant().Contains(filterValue) ||
                            one.Brand.ToLowerInvariant().Contains(filterValue) ||
                            one.ProductNameENG.ToLowerInvariant().Contains(filterValue)
                            select one.ProductId);
            }

            List <int> listTemp = new List <int>();

            //if (tempKey1 != null && tempKey1.Count() > 0)
            //    listTemp.AddRange(tempKey1);
            if (tempKey2 != null && tempKey2.Count() > 0)
            {
                listTemp.AddRange(tempKey2);
            }
            //tempKeys = listTemp.Distinct().ToArray();

            if (listTemp != null && listTemp.Count > 0) //必须是有字符串过滤条件才加入这个Query
            {
                tempDbQuery = tempDbQuery.Where(
                    m1 => m1.OrderProducts.Any(m2 => listTemp.Contains(m2.ProductId)));

                //var productOrderContractKeys = listTemp.Join(db.ProductItems,
                //                productKey => productKey, item => item.ProductId,
                //                (product, item) => item.OrderContractKey).Distinct();

                //tempDbQuery = tempDbQuery.Where(m2 => productOrderContractKeys.Contains(m2.OrderContractKey));
            }

            return(tempDbQuery);
        }
Ejemplo n.º 17
0
        private void InitHarbors(ExtendedIdentityDbContext context)
        {
            YuShang.ERP.Entities.ResMgr.Harbor
                harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "HKHKG",
                HarborName    = "中国香港",
                HarborNameENG = "Hongkong"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "CNQIN",
                HarborName    = "中国青岛",
                HarborNameENG = "QINGDAO"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "CNQUA",
                HarborName    = "中国泉州",
                HarborNameENG = "QUANZHOU"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "CNHPU",
                HarborName    = "中国黄埔",
                HarborNameENG = "HUANGPU"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "CNLYG",
                HarborName    = "中国连云港",
                HarborNameENG = "LIANYUNGANG"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            harbor = new YuShang.ERP.Entities.ResMgr.Harbor()
            {
                HarborKey     = "CNSHA",
                HarborName    = "中国上海",
                HarborNameENG = "SHANGHAI"
            };
            context.Harbors.AddOrUpdate(m => m.HarborKey, harbor);

            SaveChangesResolvingConcurrencyException(context);
        }
        private IQueryable <OrderContract> AddEntityPrivilegeControlConditions(
            ExtendedIdentityDbContext db, IQueryable <OrderContract> tempDbQuery,
            EntityControlType entityControlType, string userName)
        {
            var temp1 = PrivilegeManager.Instance.BuildQueryWithEntityControl(OwinContext,
                                                                              db, tempDbQuery, entityControlType, userName);

            if (temp1 != null && temp1 is IQueryable <OrderContract> )
            {
                tempDbQuery = temp1 as IQueryable <OrderContract>;
            }
            return(tempDbQuery);
        }
Ejemplo n.º 19
0
        GenerateOrderProducts(ExtendedIdentityDbContext context, int p)
        {
            List <ProductItem> items = new List <ProductItem>();

            ProductItem item = context.ProductItems.Create();

            item.ProductId = context.Products.Max(m => m.ProductId);// 1;
            item.Quantity  = 400;
            item.UnitPrice = 200;
            item.NetWeight = 0.15;
            item.Units     = "吨";
            item.Comments  = "DEMO_PRODUCT_COMMENT_" + p;
            //item.SalesGuidePrice = 1000;
            items.Add(item);
            context.ProductItems.Add(item);

            item           = context.ProductItems.Create();
            item.ProductId = context.Products.Max(m => m.ProductId) - 1;// 2;
            item.Quantity  = 300;
            item.UnitPrice = 200;
            item.NetWeight = 0.15;
            item.Units     = "吨";
            item.Comments  = "DEMO_PRODUCT_COMMENT_" + p;
            //item.SalesGuidePrice = 1000;
            items.Add(item);
            context.ProductItems.Add(item);

            item           = context.ProductItems.Create();
            item.ProductId = context.Products.Max(m => m.ProductId) - 2;
            item.Quantity  = 200;
            item.UnitPrice = 200;
            item.NetWeight = 0.15;
            item.Units     = "吨";
            item.Comments  = "DEMO_PRODUCT_COMMENT_" + p;
            //item.SalesGuidePrice = 1000;
            items.Add(item);
            context.ProductItems.Add(item);

            item           = context.ProductItems.Create();
            item.ProductId = context.Products.Max(m => m.ProductId) - 3;
            item.Quantity  = 100;
            item.UnitPrice = 200;
            item.NetWeight = 0.15;
            item.Units     = "吨";
            item.Comments  = "DEMO_PRODUCT_COMMENT_" + p;
            //item.SalesGuidePrice = 1000;
            items.Add(item);
            context.ProductItems.Add(item);

            return(items);
        }
        public string UpdateSaleContractCore(ExtendedIdentityDbContext dbContext,
                                             ContractInfo model, string userName)
        {
            if (model == null)
            {
                return("SaleContract model为空。");
            }

            try
            {
                SaleContract contract = null;
                if (model.ContractId > 0)
                {
                    contract = dbContext.SaleContracts.Find(model.ContractId);
                }

                if (contract == null)
                {
                    contract = dbContext.SaleContracts.Create();
                }

                string errorMessage1 = this.UpdateSaleContractFirst(dbContext, model,
                                                                    userName, contract);
                if (!string.IsNullOrWhiteSpace(errorMessage1))
                {
                    return(errorMessage1);
                }

                string errorMessage2 = AddOrUpdateSaleContractFinancialObjsSecond(
                    dbContext, userName, contract);
                if (!string.IsNullOrWhiteSpace(errorMessage2))
                {
                    return(errorMessage2);
                }

                int effectedRows = dbContext.SaveChanges();

                if (effectedRows < 1)
                {
                    return("修改SaleContract失败。");
                }
            }
            catch (Exception ee)
            {
                LogHelper.Error("修改SaleContract失败。", ee);
                return(ee.Message);
            }

            return(string.Empty);
        }
Ejemplo n.º 21
0
 public DevicesController(
     ExtendedUserManager <User> userManager,
     IPushNotificationService pushNotificationService,
     ExtendedIdentityDbContext <User, Role> dbContext,
     IPlatformEventService eventService,
     ILogger <DevicesController> logger
     )
 {
     UserManager             = userManager ?? throw new ArgumentNullException(nameof(userManager));
     PushNotificationService = pushNotificationService ?? throw new ArgumentNullException(nameof(pushNotificationService));
     DbContext    = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     EventService = eventService ?? throw new ArgumentNullException(nameof(eventService));
     Logger       = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Ejemplo n.º 22
0
        private void InitStockItems(ExtendedIdentityDbContext context)
        {
            StockItem stockItem = context.StockItems.Create();

            stockItem.Quantity              = 50;
            stockItem.StockInDate           = DateTime.Now;
            stockItem.StockWeight           = 100;
            stockItem.StoreHouseId          = context.StoreHouses.Max(m => m.StoreHouseId);                                     // 1;
            stockItem.StoreHouseMountNumber = "DEMO_MOUNT_1";
            stockItem.ProductItemId         = context.ProductItems.OrderBy(s => s.ProductItemId).Skip(0).First().ProductItemId; // 1;
            context.StockItems.AddOrUpdate(
                i => new { i.ProductItemId, i.StoreHouseId, i.StoreHouseMountNumber },
                stockItem);

            stockItem                       = context.StockItems.Create();
            stockItem.Quantity              = 60;
            stockItem.StockInDate           = DateTime.Now;
            stockItem.StockWeight           = 90;
            stockItem.StoreHouseId          = context.StoreHouses.Max(m => m.StoreHouseId) - 1;
            stockItem.StoreHouseMountNumber = "DEMO_MOUNT_2";
            stockItem.ProductItemId         = context.ProductItems.OrderBy(s => s.ProductItemId).Skip(1).First().ProductItemId;//2;
            context.StockItems.AddOrUpdate(
                i => new { i.ProductItemId, i.StoreHouseId, i.StoreHouseMountNumber },
                stockItem);

            stockItem                       = context.StockItems.Create();
            stockItem.Quantity              = 70;
            stockItem.StockInDate           = DateTime.Now;
            stockItem.StockWeight           = 80;
            stockItem.StoreHouseId          = context.StoreHouses.Max(m => m.StoreHouseId) - 2;
            stockItem.StoreHouseMountNumber = "DEMO_MOUNT_3";
            stockItem.ProductItemId         = context.ProductItems.OrderBy(s => s.ProductItemId).Skip(2).First().ProductItemId;//3;
            context.StockItems.AddOrUpdate(
                i => new { i.ProductItemId, i.StoreHouseId, i.StoreHouseMountNumber },
                stockItem);

            stockItem                       = context.StockItems.Create();
            stockItem.Quantity              = 80;
            stockItem.StockInDate           = DateTime.Now;
            stockItem.StockWeight           = 70;
            stockItem.StoreHouseId          = context.StoreHouses.Max(m => m.StoreHouseId) - 3;
            stockItem.StoreHouseMountNumber = "DEMO_MOUNT_4";
            stockItem.ProductItemId         = context.ProductItems.OrderBy(s => s.ProductItemId).Skip(3).First().ProductItemId;// 4;
            context.StockItems.AddOrUpdate(
                i => new { i.ProductItemId, i.StoreHouseId, i.StoreHouseMountNumber },
                stockItem);

            SaveChangesResolvingConcurrencyException(context);
        }
        /// <summary>
        /// 简单一点,只对权限数据加入数据Level的限制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="entityControlType"></param>
        /// <param name="tempDbQuery"></param>
        /// <param name="userName"></param>
        /// <param name="roles"></param>
        /// <returns></returns>
        internal IQueryable <SaleContract> AddEntityControlCondition(
            ExtendedIdentityDbContext db, EntityControlType entityControlType,
            IQueryable <SaleContract> tempDbQuery, string userName, IList <string> roles)
        {
            //int level = PrivilegeLevelByEntityControlType.GetDefaultPrivilegeLevelByEntityControlType(entityControlType);
            int selfLevel = PrivilegeManager.GetSelfPrivilegeLevelByEntityControlType(
                entityControlType, userName, roles, db);

            tempDbQuery = tempDbQuery.Where(m => ((m.OperatorSysUser == userName && m.EntityPrivLevRequired <= selfLevel) ||
                                                  m.EntityPrivLevRequired < selfLevel));
            //简单的规则就是:一般的用户只能看到小于自己数据权限级别的数据;
            //或者自己录入的数据但是权限小于等于自己的

            return(tempDbQuery);
        }
Ejemplo n.º 24
0
        InvokeCustomMigrations(ExtendedIdentityDbContext context, string customMigrationKey)
        {
            IEnumerable <ICustomMigrationHandler> handler =
                GetMigrationHandlers(customMigrationKey);

            List <CustomMigrationResult> results = new List <CustomMigrationResult>();

            foreach (var h in handler)
            {
                var res = h.CustomMigrationSeed(context, true, customMigrationKey);
                results.Add(res);
                if (res.Succeed == false && res.GoToNextWhenExceptionHappend == false)
                {
                    break;
                }
            }
            return(results);
        }
Ejemplo n.º 25
0
        private void InitOrderContracts(ExtendedIdentityDbContext context)
        {
            int counter = 1;

            InitOneOrderContractType1(context, counter);
            InitOneOrderContractType0(context, counter);
            counter = 2;
            InitOneOrderContractType1(context, counter);
            InitOneOrderContractType0(context, counter);
            counter = 3;
            InitOneOrderContractType1(context, counter);
            InitOneOrderContractType0(context, counter);
            counter = 4;
            InitOneOrderContractType1(context, counter);
            InitOneOrderContractType0(context, counter);

            SaveChangesResolvingConcurrencyException(context);
        }
        private string AddOrUpdateSaleContractFinancialObjsSecond(
            ExtendedIdentityDbContext db, //SaleContract model,
            string userName, SaleContract contract)
        {
            if (contract.ContractStatus == ContractStatus.AuditPassed)//已经审核
            {
                if (contract.SaleContractId < 1)
                {//Add
                    AddSaleContractFinancialObjsSecond(db, contract);
                }
                else
                {//exists
                    UpdateSaleContractFinancialObjsSecond(db, contract);
                }
            }

            return(string.Empty);
        }
        private string HandleStockItemMove(ExtendedIdentityDbContext dbContext,
                                           SaleContract contract, SaleProductItem saleItem, string userName)
        {
            if (contract.ContractStatus != ContractStatus.AuditPassed ||
                contract.OrderType == 0)
            {
                return(string.Empty);
            }

            StockItem stockItem = dbContext.StockItems.FirstOrDefault(
                p => saleItem.StockItemId.HasValue && p.StockItemId == saleItem.StockItemId.Value && p.IsAllSold == false);

            if (stockItem == null)
            {
                return("找不到对应的库存商品项,或者对应的商品项已经被销售完毕。");
            }

            if (stockItem.Quantity <= saleItem.Quantity)
            {
                stockItem.IsAllSold   = true;
                stockItem.StockStatus = StockStatus.InStockSelling;
            }
            else
            {//stockItem.Quantity > saleItem.Quantity
                //销售只卖掉一部分的情况
                StockItem newItem = dbContext.StockItems.Create();
                newItem.ProductItemId         = stockItem.ProductItemId;
                newItem.StockInDate           = stockItem.StockInDate;
                newItem.StockStatus           = StockStatus.InStock;
                newItem.StockWeight           = stockItem.StockWeight;
                newItem.StoreHouseId          = stockItem.StoreHouseId;
                newItem.StoreHouseMountNumber = stockItem.StoreHouseMountNumber;
                newItem.Quantity = stockItem.Quantity - saleItem.Quantity;

                dbContext.StockItems.Add(newItem);

                stockItem.Quantity    = saleItem.Quantity;
                stockItem.StockStatus = StockStatus.InStockSelling;
                stockItem.IsAllSold   = true;
            }

            return(string.Empty);
        }
        private void UpdateSaleContractFinancialObjsSecond(ExtendedIdentityDbContext db, SaleContract contract)
        {
            var receive1 = db.AccountsReceivables.FirstOrDefault(
                m => m.EventType == AccountingEventType.SalesDeposite &&
                m.SaleContractId.HasValue &&
                m.SaleContractId.Value == contract.SaleContractId);

            var receive2 = db.AccountsReceivables.FirstOrDefault(
                m => m.EventType == AccountingEventType.SalesBalancedPayment &&
                m.SaleContractId.HasValue &&
                m.SaleContractId.Value == contract.SaleContractId);

            if (receive1 == null)
            {
                receive1 = db.AccountsReceivables.Create();
                receive1.SaleContractId = contract.SaleContractId;
                receive1.PayStatus      = 0;
                receive1.EventType      = AccountingEventType.SalesDeposite;
                receive1.CTIME          = DateTime.Now;
                receive1.Amount         = contract.SaleDeposite;
                db.AccountsReceivables.Add(receive1);
            }
            else
            {
                receive1.Amount = contract.SaleDeposite;
            }

            if (receive2 == null)
            {
                receive2 = db.AccountsReceivables.Create();
                receive2.SaleContractId = contract.SaleContractId;
                receive2.PayStatus      = 0;
                receive2.EventType      = AccountingEventType.SalesBalancedPayment;
                receive2.CTIME          = DateTime.Now;
                receive2.Amount         = contract.SaleBalancedPayment;
                db.AccountsReceivables.Add(receive2);
            }
            else
            {
                receive2.Amount = contract.SaleBalancedPayment;
            }
        }
        private void AddSaleContractFinancialObjsSecond(ExtendedIdentityDbContext db, SaleContract contract)
        {
            var receive1 = db.AccountsReceivables.Create();

            receive1.SaleContract = contract;
            receive1.PayStatus    = 0;
            receive1.EventType    = AccountingEventType.SalesDeposite;
            receive1.CTIME        = DateTime.Now;
            receive1.Amount       = contract.SaleDeposite;
            db.AccountsReceivables.Add(receive1);

            var receive2 = db.AccountsReceivables.Create();

            receive2.SaleContract = contract;
            receive2.PayStatus    = 0;
            receive2.EventType    = AccountingEventType.SalesBalancedPayment;
            receive2.CTIME        = DateTime.Now;
            receive2.Amount       = contract.SaleBalancedPayment;
            db.AccountsReceivables.Add(receive2);
        }
        public IQueryable <YuShang.ERP.Entities.Sale.SaleContract> GetIndexListSaleContract(
            ExtendedIdentityDbContext dbContext, int?orderType, DateTime?DateFrom, DateTime?DateTo,
            string filterValue, string userName, out int count)
        {
            try
            {
                //double temp1 = -1;
                //double temp2 = -1;

                SaleContractPrivilegeFilter filter = new SaleContractPrivilegeFilter()
                {
                    SerialOrSupplierFilterValue = filterValue,
                    SaleCreateTimeFrom          = DateFrom,
                    SaleCreateTimeTo            = DateTo,
                    UserName = userName,
                };

                IQueryable <SaleContract> contractsQuery = this.GetIndexListSaleContract(
                    dbContext, filter); //out temp1, out temp2);

                if (orderType.HasValue)
                {
                    var query = contractsQuery.Where(m => m.OrderType == orderType.GetValueOrDefault() &&
                                                     m.ContractStatus != ContractStatus.Closed);

                    count = query.Count();
                    return(query);
                }

                var query2 = contractsQuery.Where(m => m.ContractStatus != ContractStatus.Closed);

                count = query2.Count();
                return(query2);
            }
            catch (Exception ee)
            {
                LogHelper.Error("获取SaleContract列表失败。", ee);
                count = -1;
                return(null);
            }
        }