public IActionResult Post([FromBody] InspectionPlanViewModel model)
        {
            var userdata = _context.Users
                           .Where(m => m.Id == model.UserID)
                           //.Select(m => m.Role_id)
                           .FirstOrDefault();

            System.Console.WriteLine("FiscalYearId" + model.FiscalYearId);
            var year = _context.FiscalYearNew
                       .Where(m => m.Year == model.FiscalYearId).FirstOrDefault();

            System.Console.WriteLine("year" + year.Id);
            //if(year == null)
            //{

            //}
            //var test = model.UserID;
            //System.Console.WriteLine(test);
            System.Console.WriteLine("111");
            var date = DateTime.Now;

            System.Console.WriteLine("222" + model.Type);
            var centralpolicydata = new CentralPolicy
            {
                Title = model.Title,
                TypeexaminationplanId = 3,
                FiscalYearNewId       = year.Id,
                StartDate             = model.StartDate,
                EndDate   = model.EndDate,
                Status    = model.Status,
                CreatedAt = date,
                CreatedBy = model.UserID,
                Class     = "แผนการตรวจ",
            };

            System.Console.WriteLine("3");
            _context.CentralPolicies.Add(centralpolicydata);
            _context.SaveChanges();
            System.Console.WriteLine("4");
            //foreach (var id in model.ProvinceId)
            //{
            var centralpolicyprovincedata = new CentralPolicyProvince
            {
                ProvinceId      = model.ProvinceId,
                CentralPolicyId = centralpolicydata.Id,
                Step            = "มอบหมายหน่วยงาน",
                Status          = "ร่างกำหนดการ"
            };

            _context.CentralPolicyProvinces.Add(centralpolicyprovincedata);
            _context.SaveChanges();

            ///////////////////////////////
            var SubjectGroupdata = new SubjectGroup
            {
                CentralPolicyId  = centralpolicydata.Id,
                ProvinceId       = model.ProvinceId,
                Type             = "Master",
                Land             = "Master",
                Status           = "Master",
                StatusSuggestion = "ร่างกำหนดการ",

                ProvincialDepartmentIdCreatedBy = userdata.ProvincialDepartmentId,
                CreatedBy     = userdata.Id,
                RoleCreatedBy = userdata.Role_id,
            };

            _context.SubjectGroups.Add(SubjectGroupdata);
            _context.SaveChanges();
            ///////////////////////////////
            ///
            var subjectdata = new SubjectCentralPolicyProvince
            {
                Name = model.Title,
                CentralPolicyProvinceId = centralpolicyprovincedata.Id,
                Type           = "Master",
                Status         = "ใช้งานจริง",
                SubjectGroupId = SubjectGroupdata.Id,
                CreatedBy      = model.UserID,
            };

            _context.SubjectCentralPolicyProvinces.Add(subjectdata);
            _context.SaveChanges();

            //var inspectionplaneventdata = new InspectionPlanEvent
            //{
            //    StartDate = model.StartDate,
            //    EndDate = model.EndDate,
            //    ProvinceId = model.ProvinceId,
            //    CreatedAt = date,
            //    CreatedBy = model.UserID,
            //};
            //_context.InspectionPlanEvents.Add(inspectionplaneventdata);
            //_context.SaveChanges();

            //var ElectronicBookdata = new ElectronicBook
            //{
            //    CreatedBy = model.UserID,
            //    Status = "ร่างกำหนดการ",
            //};
            //_context.ElectronicBooks.Add(ElectronicBookdata);
            //_context.SaveChanges();
            //System.Console.WriteLine("3");

            //var ElectronicBookGroupdata = new ElectronicBookGroup
            //{
            //    // CentralPolicyProvinceId = centralpolicyprovincedata.Id,
            //    ElectronicBookId = ElectronicBookdata.Id,
            //};
            //_context.ElectronicBookGroups.Add(ElectronicBookGroupdata);
            //_context.SaveChanges();

            var centralpolicyeventdata = new CentralPolicyEvent
            {
                CentralPolicyId       = centralpolicydata.Id,
                InspectionPlanEventId = model.InspectionPlanEventId,
                HaveSubject           = 0,
                StartDate             = model.StartDate,
                EndDate = model.EndDate,
                //ElectronicBookId = ElectronicBookdata.Id,
            };

            _context.CentralPolicyEvents.Add(centralpolicyeventdata);
            _context.SaveChanges();

            var logdata = new Log
            {
                UserId       = model.UserID,
                DatabaseName = "CentralPolicyEvent",
                EventType    = "เพิ่ม",
                EventDate    = date,
                Detail       = "เพิ่มแผนตรวจราชการในกำหนดการตรวจราชการ",
                Allid        = centralpolicyeventdata.Id,
            };

            _context.Logs.Add(logdata);
            _context.SaveChanges();
            //}
            return(Ok(new { status = true }));
        }
Beispiel #2
0
        public void Post([FromBody] InspectionPlanViewModel model)
        {
            //var test = model.UserID;
            //System.Console.WriteLine(test);
            System.Console.WriteLine("1" + model.Title);
            var date = DateTime.Now;

            System.Console.WriteLine("2" + model.Type);
            var centralpolicydata = new CentralPolicy
            {
                Title        = model.Title,
                Type         = model.Type,
                FiscalYearId = model.FiscalYearId,
                StartDate    = model.StartDate,
                EndDate      = model.EndDate,
                Status       = model.Status,
                CreatedAt    = date,
                CreatedBy    = model.UserID,
                Class        = "แผนการตรวจ",
            };

            System.Console.WriteLine("3");
            _context.CentralPolicies.Add(centralpolicydata);
            _context.SaveChanges();
            System.Console.WriteLine("4");
            //foreach (var id in model.ProvinceId)
            //{
            var centralpolicyprovincedata = new CentralPolicyProvince
            {
                ProvinceId      = model.ProvinceId,
                CentralPolicyId = centralpolicydata.Id,
            };

            _context.CentralPolicyProvinces.Add(centralpolicyprovincedata);
            _context.SaveChanges();

            //var inspectionplaneventdata = new InspectionPlanEvent
            //{
            //    StartDate = model.StartDate,
            //    EndDate = model.EndDate,
            //    ProvinceId = model.ProvinceId,
            //    CreatedAt = date,
            //    CreatedBy = model.UserID,
            //};
            //_context.InspectionPlanEvents.Add(inspectionplaneventdata);
            //_context.SaveChanges();
            var ElectronicBookdata = new ElectronicBook
            {
                CreatedBy = model.UserID,
                Status    = "ร่างกำหนดการ",
            };

            _context.ElectronicBooks.Add(ElectronicBookdata);
            _context.SaveChanges();
            System.Console.WriteLine("3");

            var ElectronicBookGroupdata = new ElectronicBookGroup
            {
                CentralPolicyProvinceId = centralpolicyprovincedata.Id,
                ElectronicBookId        = ElectronicBookdata.Id,
            };

            _context.ElectronicBookGroups.Add(ElectronicBookGroupdata);
            _context.SaveChanges();

            var centralpolicyeventdata = new CentralPolicyEvent
            {
                CentralPolicyId       = centralpolicydata.Id,
                InspectionPlanEventId = model.InspectionPlanEventId,
                ElectronicBookId      = ElectronicBookdata.Id,
            };

            _context.CentralPolicyEvents.Add(centralpolicyeventdata);
            _context.SaveChanges();
            //}
        }