Beispiel #1
0
        public async Task <int> SavePurchaseOrderRequest(PurchaseOrderRequestModel model)
        {
            if (model.Id == 0)
            {
                // var samples = model.Samples;
                // var quotation = model.Quotation;
                // model.Samples = null;
                // model.Quotation = null;
                // model.ReceivedFrom = null;
                // model.SubmittedBy = null;
                model.SubmittedById = 1;

                //add ModifiedPrice if missing from TestParameterMehtod reverting to the default price. and add PORId
                if (model.Samples != null)
                {
                    foreach (SampleModel sample in model.Samples)
                    {
                        //sample.PurchaseOrderRequestId = model.Id;
                        // var testParameters = sample.SampleTestParameters;
                        // sample.SampleTestParameters = null;
                        sample.ReceivedByUserId = 1;
                        // await db.Samples.AddAsync(sample);
                        // await db.SaveChangesAsync();

                        if (sample.SampleTestParameters == null)
                        {
                            continue;
                        }
                        foreach (SampleTestParameterModel testParameter in sample.SampleTestParameters)
                        {
                            testParameter.SampleId = sample.Id;
                            TestParameterMethodModel testParameterMethod = await db.TestParameterMethods.SingleAsync(t => t.TestParameterId == testParameter.TestParameterId && t.MethodId == testParameter.MethodId);

                            testParameter.TestParameterMethodId = testParameterMethod.Id;
                            if (testParameter.ModifiedPrice <= 0)
                            {
                                testParameter.ModifiedPrice = testParameterMethod.Price;
                            }
                        }

                        // await db.SampleTestParameters.AddRangeAsync(testParameters);
                        // await db.SaveChangesAsync();
                    }
                }

                db.PurchaseOrderRequests.Add(model);
                await db.SaveChangesAsync();
            }
            else
            {
                var origModel = await db.PurchaseOrderRequests.Include(p => p.Samples).Include(p => p.Quotation).SingleAsync(p => p.Id == model.Id);

                //what is this ??
                origModel = model;
            }
            //await db.SaveChangesAsync();
            return(model.Id);
        }
Beispiel #2
0
        public IActionResult Insert()
        {
            var testMethod = new TestParameterMethodModel()
            {
                Id            = 1,
                TestParameter = new TestParameterModel()
                {
                    Id          = 1,
                    Name        = "TestTest",
                    Description = "Just a test Test"
                },
                Method = new MethodModel()
                {
                    Id          = 1,
                    Name        = "TestMethod",
                    Description = "Just a test Method"
                }
            };

            db.Add(testMethod);
            db.SaveChanges();

            return(Ok());
        }
Beispiel #3
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <SampleModel>().HasKey(s => s.Id);
            builder.Entity <SampleModel>().HasMany(s => s.SampleTestParameters).WithOne(t => t.Sample).HasForeignKey(t => t.SampleId).OnDelete(DeleteBehavior.Cascade);
            builder.Entity <SampleModel>().HasOne(s => s.ReceivedBy).WithMany(u => u.Samples).HasForeignKey(s => s.ReceivedByUserId);

            builder.Entity <QuotationModel>().HasKey(q => q.PurchaseOrderRequestId);
            builder.Entity <PurchaseOrderRequestModel>().HasKey(p => p.Id);
            builder.Entity <PurchaseOrderRequestModel>().HasOne <QuotationModel>(p => p.Quotation).WithOne(q => q.PurchaseOrderRequest).OnDelete(DeleteBehavior.Cascade);
            builder.Entity <PurchaseOrderRequestModel>().HasMany <SampleModel>(p => p.Samples).WithOne(s => s.PurchaseOrderRequest).HasForeignKey(s => s.PurchaseOrderRequestId).OnDelete(DeleteBehavior.Cascade);

            builder.Entity <IdentityUserRole <int> >().HasKey(r => new { r.UserId, r.RoleId });

            builder.Entity <TestParameterMatrixModel>().HasKey(t => t.Id);
            builder.Entity <TestParameterMatrixModel>().HasAlternateKey(t => new { t.MatrixId, t.TestParameterId });

            builder.Entity <TestParameterMethodModel>().HasKey(t => t.Id);
            builder.Entity <TestParameterMethodModel>().HasAlternateKey(t => new { t.MethodId, t.TestParameterId });

            builder.Entity <SampleTestParameterModel>().HasKey(s => s.Id);
            // builder.Entity<SampleTestParameterModel>().HasAlternateKey( s => new { s.SampleId, s.TestParameterId, s.MethodId } );
            // builder.Entity<SampleTestParameterModel>().HasAlternateKey( s => new { s.SampleId, s.TestParameterMethodId } );
            builder.Entity <SampleTestParameterModel>().HasMany(s => s.SampleTestParameterResults).WithOne(r => r.SampleTestParameter).OnDelete(DeleteBehavior.Cascade);

            builder.Entity <SampleTestParameterResultModel>().HasKey(r => r.Id);
            builder.Entity <SampleTestParameterResultModel>().HasAlternateKey(r => new { r.SampleTestParameterId, r.Revision });

            LimsUser user = new LimsUser()
            {
                Id = 1, UserName = "******", NormalizedUserName = "******", Email = "*****@*****.**", NormalizedEmail = "*****@*****.**".ToUpper(), EmailConfirmed = true, SecurityStamp = "lol"
            };
            PasswordHasher <LimsUser> hasher = new PasswordHasher <LimsUser>();

            user.PasswordHash = hasher.HashPassword(user, "maa");
            builder.Entity <LimsUser>().HasData(user);

            var userIdClaim = new IdentityUserClaim <int> {
                UserId = 1, Id = 1, ClaimType = "Claim1", ClaimValue = "1"
            };
            var userNameClaim = new IdentityUserClaim <int> {
                UserId = 1, Id = 2, ClaimType = "Claim2", ClaimValue = "moa995"
            };
            var userRoleClaim = new IdentityUserClaim <int> {
                UserId = 1, Id = 3, ClaimType = "Claim3", ClaimValue = "admin"
            };

            builder.Entity <IdentityUserClaim <int> >().HasData(userIdClaim, userNameClaim, userRoleClaim);

            var customer = new CustomerModel {
                Id = 1, Name = "KNPC", PhoneNumber = "+965-999999", Address = "Salmyia"
            };
            var contact = new ContactModel {
                Id = 1, Name = "Mohammad Abdullah", PhoneNumber = "+965-99828764", CustomerId = 1
            };
            var contact2 = new ContactModel {
                Id = 2, Name = "Ibrahim Al-Hajeri", PhoneNumber = "+965-0017235", CustomerId = 1
            };

            var customer1 = new CustomerModel {
                Id = 2, Name = "Architecture", PhoneNumber = "+965-999999", Address = "Salmyia"
            };
            var contact11 = new ContactModel {
                Id = 3, Name = "Hiba Abdulqader", PhoneNumber = "+965-99828764", CustomerId = 2
            };
            var contact12 = new ContactModel {
                Id = 4, Name = "Khalil", PhoneNumber = "+965-63273627", CustomerId = 2
            };
            var contact13 = new ContactModel {
                Id = 5, Name = "Mohammad", PhoneNumber = "+965-8273928", CustomerId = 2
            };

            var customer2 = new CustomerModel {
                Id = 3, Name = "Kindergarten", PhoneNumber = "+965-999999", Address = "Salmyia"
            };
            var contact21 = new ContactModel {
                Id = 6, Name = "Yousef Abdullah", PhoneNumber = "+965-1234567", CustomerId = 3
            };
            var contact22 = new ContactModel {
                Id = 7, Name = "Celen", PhoneNumber = "+965-7654321", CustomerId = 3
            };

            builder.Entity <CustomerModel>().HasData(customer, customer1, customer2);
            builder.Entity <ContactModel>().HasData(contact, contact2, contact11, contact12, contact13, contact21, contact22);


            var matrixSolid = new MatrixModel {
                Id = 1, Name = "Solid", Code = MatrixModel.Codes.Solid
            };
            var matrixLiquid = new MatrixModel {
                Id = 2, Name = "Liquid", Code = MatrixModel.Codes.Liquid
            };
            var matrixGas = new MatrixModel {
                Id = 3, Name = "Gas", Code = MatrixModel.Codes.Gas
            };

            builder.Entity <MatrixModel>().HasData(matrixSolid, matrixLiquid, matrixGas);

            var method = new MethodModel {
                Id = 1, Name = "Method1", Description = "a generic test method", UnitOfMeasurement = "cm^2", Code = "MTD"
            };
            var sulphurMethod1 = new MethodModel {
                Id = 2, Name = "Sulphur Method", Description = "a test method for sulphur", UnitOfMeasurement = "p.cm^2", Code = "SLPRTST"
            };
            var carbonMethod2 = new MethodModel {
                Id = 3, Name = "Carbon Method", Description = "a test method for carbon", UnitOfMeasurement = "cm^2", Code = "CBNTST"
            };

            builder.Entity <MethodModel>().HasData(method, sulphurMethod1, carbonMethod2);

            var sulphurTest = new TestParameterModel {
                Id = 1, Name = "Sulphur Test", Code = "SLPTST", Description = "Test for Sulphur 'S'"
            };
            var carbonTest = new TestParameterModel {
                Id = 2, Name = "Carbon Test", Code = "CBNTST", Description = "Test for carbon 'C'"
            };
            var waterTest = new TestParameterModel {
                Id = 3, Name = "Water Test", Code = "WTRTST", Description = "Test for water 'H2O'"
            };
            var clorideTest = new TestParameterModel {
                Id = 4, Name = "Cloride Test", Code = "CLTST", Description = "Test for Cloride 'CL2'"
            };
            //builder.Entity<TestParameterModel>().HasData(sulphurTest, carbonTest, waterTest, clorideTest);

            var genericTestMethodforSulphur = new TestParameterMethodModel {
                Id = 1, MethodId = 1, TestParameterId = 1, Price = 50.250d
            };
            var genericTestMethodforCarbon = new TestParameterMethodModel {
                Id = 2, MethodId = 1, TestParameterId = 2, Price = 23.200d
            };
            var sulpherTestMethod = new TestParameterMethodModel {
                Id = 3, MethodId = 2, TestParameterId = 1, Price = 30.400d
            };
            var carbonTestMethod = new TestParameterMethodModel {
                Id = 4, MethodId = 3, TestParameterId = 2, Price = 10.850d
            };
            //builder.Entity<TestParameterMethodModel>().HasData(genericTestMethodforCarbon, genericTestMethodforSulphur, sulpherTestMethod, carbonTestMethod);

            var carbonSolidMatrixTest = new TestParameterMatrixModel {
                Id = 1, TestParameterId = 1, MatrixId = 1
            };
            var sulphurSolidMatrixTest = new TestParameterMatrixModel {
                Id = 2, TestParameterId = 2, MatrixId = 1
            };
            var waterLiquidMatrixTest = new TestParameterMatrixModel {
                Id = 3, TestParameterId = 3, MatrixId = 2
            };
            var clorideGasMatrixTest = new TestParameterMatrixModel {
                Id = 4, TestParameterId = 4, MatrixId = 3
            };
            //builder.Entity<TestParameterMatrixModel>().HasData(carbonSolidMatrixTest, sulphurSolidMatrixTest, waterLiquidMatrixTest, clorideGasMatrixTest);


            var por = new PurchaseOrderRequestModel { //Id = 1,
                ContactId = 1, Code = PurchaseOrderRequestService.GeneratePORCode(1, 1), ReceivedDate = DateTime.Now
            };
            // builder.Entity<PurchaseOrderRequestModel>().HasData(por);

            var sulphurSample = new SampleModel { //Id = 1,
                Locked                 = false,
                Location               = "Ahmadi",
                Remarks                = "No Remarks",
                ReceivedByUserId       = 1,
                SamplingPoint          = "Salmyia",
                SamplingBy             = "Mohammad",
                MatrixId               = matrixSolid.Id,
                PurchaseOrderRequestId = 1,
                ReceivedDate           = DateTime.Now,
                SamplingDate           = DateTime.Now.AddDays(-3), Code = SampleService.GenerateSampleCode(matrixSolid.Name, 1, 1)
            };


            var carbonSample = new SampleModel { //Id = 2,
                Locked                 = false,
                Location               = "Sabhan",
                Remarks                = "Carbon Sample",
                ReceivedByUserId       = 1,
                SamplingPoint          = "Salmyia",
                SamplingBy             = "Yousef",
                MatrixId               = matrixSolid.Id,
                PurchaseOrderRequestId = 1,
                ReceivedDate           = DateTime.Now,
                SamplingDate           = DateTime.Now.AddDays(-6), Code = SampleService.GenerateSampleCode(matrixSolid.Name, 1, 1)
            };
            // builder.Entity<SampleModel>().HasData(sulphurSample, carbonSample);

            var sulphurSampleTestParameter = new SampleTestParameterModel { //Id = 1,
                MethodId = 2, TestParameterId = 1, TestParameterMethodId = 3, SampleId = 1, ModifiedPrice = 8
            };
            var sulphurGenericSampleTestParameter = new SampleTestParameterModel { //Id = 2,
                MethodId = 1, TestParameterId = 1, TestParameterMethodId = 1, SampleId = 1, ModifiedPrice = 8
            };

            var carbonSampleTestParameter = new SampleTestParameterModel { //Id = 3,
                MethodId = 3, TestParameterId = 2, TestParameterMethodId = 4, SampleId = 2, ModifiedPrice = 8
            };
            var carbonGenericSampleTestParameter = new SampleTestParameterModel { //Id = 4,
                MethodId = 1, TestParameterId = 2, TestParameterMethodId = 2, SampleId = 2, ModifiedPrice = 8
            };
            // builder.Entity<SampleTestParameterModel>().HasData(sulphurSampleTestParameter, sulphurGenericSampleTestParameter, carbonSampleTestParameter, carbonGenericSampleTestParameter);
        }