public async Task <SpinningSalesContractModel> CustomCodeGenerator(SpinningSalesContractModel Model)
        {
            string type = Model.BuyerType.ToLower() == "export" ? "SPE" : "SPL";

            var lastData = await this.DbSet.Where(w => w.BuyerType == Model.BuyerType).OrderByDescending(o => o.CreatedUtc).FirstOrDefaultAsync();

            DateTime Now   = DateTime.Now;
            string   Year  = Now.ToString("yy");
            string   month = Now.ToString("mm");

            if (lastData == null)
            {
                Model.AutoIncrementNumber = 1;
                string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                Model.SalesContractNo = $"{Number}{type}{Number}{month}{Year}";
            }
            else
            {
                if (lastData.CreatedUtc.Year < Now.Year)
                {
                    Model.AutoIncrementNumber = 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.SalesContractNo = $"{Number}{type}{Number}{month}{Year}";
                }
                else
                {
                    Model.AutoIncrementNumber = lastData.AutoIncrementNumber + 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.SalesContractNo = $"{Number}{type}{Number}{month}{Year}";
                }
            }
            return(Model);
        }
コード例 #2
0
        public async Task <SpinningSalesContractModel> CustomCodeGenerator(SpinningSalesContractModel Model)
        {
            string type = Model.BuyerType.ToLower().Equals("ekspor") || Model.BuyerType.ToLower().Equals("export") ? "SPE" : "SPL";

            var lastData = await this.DbSet.IgnoreQueryFilters().Where(w => w.BuyerType.Equals(Model.BuyerType, StringComparison.OrdinalIgnoreCase) && w.IsDeleted == false).OrderByDescending(o => o.CreatedUtc).FirstOrDefaultAsync();

            DateTime Now   = DateTime.Now;
            string   Year  = Now.ToString("yyyy");
            string   month = Now.ToString("MM");

            if (lastData == null)
            {
                Model.AutoIncrementNumber = 1;
                string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                Model.SalesContractNo = $"{Number}/{type}/{month}.{Year}";
            }
            else
            {
                if (lastData.CreatedUtc.Year < Now.Year)
                {
                    Model.AutoIncrementNumber = 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.SalesContractNo = $"{Number}/{type}/{month}.{Year}";
                }
                else
                {
                    Model.AutoIncrementNumber = lastData.AutoIncrementNumber + 1;
                    string Number = Model.AutoIncrementNumber.ToString().PadLeft(4, '0');
                    Model.SalesContractNo = $"{Number}/{type}/{month}.{Year}";
                }
            }
            return(Model);
        }
        public async Task <int> CreateAsync(SpinningSalesContractModel model)
        {
            do
            {
                model.Code = CodeGenerator.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(model.Code)));

            var data = await CustomCodeGenerator(model);

            SpinningSalesContractLogic.Create(data);

            return(await DbContext.SaveChangesAsync());
        }
コード例 #4
0
        public void should_Success_Clone()
        {
            //Setup
            SpinningSalesContractModel model = new  SpinningSalesContractModel();

            //Act
            var dataObj    = JsonConvert.SerializeObject(model);
            var resultCopy = dataObj.Clone <string>();

            //Assert
            Assert.Equal(dataObj, resultCopy);
            Assert.NotSame(dataObj, resultCopy);
        }
 public async Task <int> UpdateAsync(int id, SpinningSalesContractModel model)
 {
     SpinningSalesContractLogic.UpdateAsync(id, model);
     return(await DbContext.SaveChangesAsync());
 }