public async Task <IActionResult> Post2([FromForm] CalendarFileViewModel model) { //var CentralPolicyProvincedata = _context.CentralPolicyProvinces // .Where(m => m.Id == model.CentralPolicyProvinceId).FirstOrDefault(); var CentralPolicyProvincedata = _context.CentralPolicyProvinces.Find(model.CentralPolicyProvinceId); CentralPolicyProvincedata.Step = model.Step; _context.Entry(CentralPolicyProvincedata).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); if (!Directory.Exists(_environment.WebRootPath + "//Uploads//")) { Directory.CreateDirectory(_environment.WebRootPath + "//Uploads//"); //สร้าง Folder Upload ใน wwwroot } //var BaseUrl = url.ActionContext.HttpContext.Request.Scheme; // path ที่เก็บไฟล์ var filePath = _environment.WebRootPath + "//Uploads//"; System.Console.WriteLine("Start Upload 2"); foreach (var formFile in model.files.Select((value, index) => new { Value = value, Index = index })) //foreach (var formFile in data.files) { System.Console.WriteLine("Start Upload 3"); var random = RandomString(10); string filePath2 = formFile.Value.FileName; string filename = Path.GetFileName(filePath2); string ext = Path.GetExtension(filename); if (formFile.Value.Length > 0) { System.Console.WriteLine("Start Upload 4"); // using (var stream = System.IO.File.Create(filePath + formFile.Value.FileName)) using (var stream = System.IO.File.Create(filePath + random + filename)) { await formFile.Value.CopyToAsync(stream); } System.Console.WriteLine("Start Upload 4.1"); var ElectronicBookFile = new ElectronicBookFile { ElectronicBookId = model.ElectronicBookId, Name = random + filename, Type = "Calendar File" }; System.Console.WriteLine("Start Upload 4.2"); _context.ElectronicBookFiles.Add(ElectronicBookFile); _context.SaveChanges(); System.Console.WriteLine("Start Upload 4.3"); } System.Console.WriteLine("Start Upload 5"); } return(Ok(new { status = true })); }
public async Task <IActionResult> PostSignature([FromForm] ElectronicBookViewModel model) { if (!Directory.Exists(_environment.WebRootPath + "//Uploads//")) { Directory.CreateDirectory(_environment.WebRootPath + "//Uploads//"); //สร้าง Folder Upload ใน wwwroot } //var BaseUrl = url.ActionContext.HttpContext.Request.Scheme; // path ที่เก็บไฟล์ var filePath = _environment.WebRootPath + "//Uploads//"; System.Console.WriteLine("Start Upload 2"); foreach (var formFile in model.files.Select((value, index) => new { Value = value, Index = index })) //foreach (var formFile in data.files) { System.Console.WriteLine("Start Upload 3"); var random = RandomString(10); string filePath2 = formFile.Value.FileName; string filename = Path.GetFileName(filePath2); string ext = Path.GetExtension(filename); if (formFile.Value.Length > 0) { System.Console.WriteLine("Start Upload 4"); // using (var stream = System.IO.File.Create(filePath + formFile.Value.FileName)) using (var stream = System.IO.File.Create(filePath + random + filename)) { await formFile.Value.CopyToAsync(stream); } System.Console.WriteLine("Start Upload 4.1"); var ElectronicBookFile = new ElectronicBookFile { ElectronicBookId = model.ElectID, Name = random + filename, Type = "SignatureProvince File" }; System.Console.WriteLine("Start Upload 4.2"); _context.ElectronicBookFiles.Add(ElectronicBookFile); _context.SaveChanges(); System.Console.WriteLine("Start Upload 4.3"); } System.Console.WriteLine("Start Upload 5"); } return(Ok(new { status = true })); }
public async Task <IActionResult> Post([FromForm] ElectronicBookViewModel model) { var test1 = model.Detail; //var test2 = model.UserId; System.Console.WriteLine("Detail: " + test1); //System.Console.WriteLine("UserId: " + test2); var ElectronicBookdata = new ElectronicBook { Detail = model.Detail, Problem = model.Problem, Suggestion = model.Suggestion, CreatedBy = model.id, Status = model.Status }; System.Console.WriteLine("1"); _context.ElectronicBooks.Add(ElectronicBookdata); _context.SaveChanges(); System.Console.WriteLine("2"); //var CentralPolicyId = model.CentralPolicyId; //var ProvinceId = model.ProvinceId; //System.Console.WriteLine("CentralPolicyId" + CentralPolicyId); //System.Console.WriteLine("ProvinceId" + ProvinceId); //System.Console.WriteLine("3"); //var centralpolicyprovinceid = _context.CentralPolicyProvinces // .Where(m => m.CentralPolicyId == CentralPolicyId) // .Where(m => m.ProvinceId == ProvinceId) // .Select(m => m.Id).First(); //var SubjectCentralPolicyProvincesdatas = _context.SubjectCentralPolicyProvinces // .Where(m => m.CentralPolicyProvinceId == centralpolicyprovinceid).ToList(); //foreach (var itemProvincialDepartmentId in model.ProvincialDepartmentId) //{ // foreach (var SubjectCentralPolicyProvincesdata in SubjectCentralPolicyProvincesdatas) // { // var SubjectCentralPolicyProvinceGroupdata = new SubjectCentralPolicyProvinceGroup // { // ProvincialDepartmentId = itemProvincialDepartmentId, // SubjectCentralPolicyProvinceId = SubjectCentralPolicyProvincesdata.Id // }; // _context.SubjectCentralPolicyProvinceGroups.Add(SubjectCentralPolicyProvinceGroupdata); // _context.SaveChanges(); // } //} //System.Console.WriteLine("3.5" + centralpolicyprovinceid); var centralPolicyID = _context.CentralPolicyProvinces .Where(x => x.CentralPolicyId == model.CentralPolicyId) .Select(x => x.Id) .FirstOrDefault(); System.Console.WriteLine("CentralPolicyProvince: " + centralPolicyID); var ElectronicBookgroupdata = new ElectronicBookGroup { ElectronicBookId = ElectronicBookdata.Id, CentralPolicyProvinceId = centralPolicyID }; _context.ElectronicBookGroups.Add(ElectronicBookgroupdata); _context.SaveChanges(); //System.Console.WriteLine("3.8"); //foreach (var itemUserPeopleId in model.UserPeopleId) //{ // var CentralPolicyGroupdata = new CentralPolicyGroup // { // }; // _context.CentralPolicyGroups.Add(CentralPolicyGroupdata); // _context.SaveChanges(); // System.Console.WriteLine("3.9"); // System.Console.WriteLine("USERPeople: " + itemUserPeopleId); // var CentralPolicyUserdata = new CentralPolicyUser // { // CentralPolicyId = CentralPolicyId, // ProvinceId = ProvinceId, // ElectronicBookId = ElectronicBookdata.Id, // CentralPolicyGroupId = CentralPolicyGroupdata.Id, // UserId = itemUserPeopleId, // Status = "รอการตอบรับ", // DraftStatus = model.Status // }; // _context.CentralPolicyUsers.Add(CentralPolicyUserdata); // _context.SaveChanges(); //} //System.Console.WriteLine("4"); //foreach (var itemUserMinistryId in model.UserMinistryId) //{ // var CentralPolicyGroupdata2 = new CentralPolicyGroup // { // }; // _context.CentralPolicyGroups.Add(CentralPolicyGroupdata2); // _context.SaveChanges(); // System.Console.WriteLine("5"); // var CentralPolicyUserdata2 = new CentralPolicyUser // { // CentralPolicyId = CentralPolicyId, // ProvinceId = ProvinceId, // ElectronicBookId = ElectronicBookdata.Id, // CentralPolicyGroupId = CentralPolicyGroupdata2.Id, // UserId = itemUserMinistryId, // Status = "รอการตอบรับ", // DraftStatus = model.Status // }; // _context.CentralPolicyUsers.Add(CentralPolicyUserdata2); // _context.SaveChanges(); // System.Console.WriteLine("6"); //} System.Console.WriteLine("Start Upload"); if (!Directory.Exists(_environment.WebRootPath + "//Uploads//")) { Directory.CreateDirectory(_environment.WebRootPath + "//Uploads//"); //สร้าง Folder Upload ใน wwwroot } //var BaseUrl = url.ActionContext.HttpContext.Request.Scheme; // path ที่เก็บไฟล์ var filePath = _environment.WebRootPath + "//Uploads//"; if (model.files != null) { System.Console.WriteLine("Start Upload 2"); foreach (var formFile in model.files.Select((value, index) => new { Value = value, Index = index })) //foreach (var formFile in data.files) { System.Console.WriteLine("Start Upload 3"); var random = RandomString(10); string filePath2 = formFile.Value.FileName; string filename = Path.GetFileName(filePath2); string ext = Path.GetExtension(filename); if (formFile.Value.Length > 0) { System.Console.WriteLine("Start Upload 4"); // using (var stream = System.IO.File.Create(filePath + formFile.Value.FileName)) using (var stream = System.IO.File.Create(filePath + random + filename)) { await formFile.Value.CopyToAsync(stream); } System.Console.WriteLine("Start Upload 4.1"); var ElectronicBookFile = new ElectronicBookFile { ElectronicBookId = ElectronicBookdata.Id, Name = random + filename, }; System.Console.WriteLine("Start Upload 4.2"); _context.ElectronicBookFiles.Add(ElectronicBookFile); _context.SaveChanges(); System.Console.WriteLine("Start Upload 4.3"); } System.Console.WriteLine("Start Upload 5"); } } return(Ok(new { status = true })); }
public async Task <IActionResult> Put([FromForm] ElectronicBookViewModel model, long id) { var test = model.Detail; System.Console.WriteLine("detail ja: " + test); var electronicBookDetail = _context.ElectronicBooks.Find(id); { //electronicBookDetail.Detail = model.Detail; electronicBookDetail.Status = model.Status; } _context.Entry(electronicBookDetail).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); System.Console.WriteLine("1: "); var provinceId = _context.ElectronicBookGroups .Where(x => x.ElectronicBookId == id) .Select(x => x.CentralPolicyProvinceId) .First(); System.Console.WriteLine("2: "); var centralPolicyId = _context.CentralPolicyProvinces .Where(x => x.Id == provinceId) .Select(x => x.CentralPolicyId) .First(); System.Console.WriteLine("3: "); //ตรวจสอบว่ามี Folder Upload ใน wwwroot มั้ย if (!Directory.Exists(_environment.WebRootPath + "//Uploads//")) { System.Console.WriteLine("in2"); Directory.CreateDirectory(_environment.WebRootPath + "//Uploads//"); //สร้าง Folder Upload ใน wwwroot } //var BaseUrl = url.ActionContext.HttpContext.Request.Scheme; // path ที่เก็บไฟล์ var filePath = _environment.WebRootPath + "//Uploads//"; System.Console.WriteLine("testJa: " + model.files); if (model.files != null) { foreach (var formFile in model.files.Select((value, index) => new { Value = value, Index = index })) //foreach (var formFile in data.files) { var random = RandomString(10); System.Console.WriteLine("in3"); string filePath2 = formFile.Value.FileName; string filename = Path.GetFileName(filePath2); string ext = Path.GetExtension(filename); if (formFile.Value.Length > 0) { System.Console.WriteLine("in4"); // using (var stream = System.IO.File.Create(filePath + formFile.Value.FileName)) using (var stream = System.IO.File.Create(filePath + random + filename)) { await formFile.Value.CopyToAsync(stream); } var ElectronicBookFileData = new ElectronicBookFile { ElectronicBookId = id, Name = random + filename, Type = "ElectronicBook File" }; _context.ElectronicBookFiles.Add(ElectronicBookFileData); System.Console.WriteLine("in5"); _context.SaveChanges(); System.Console.WriteLine("in6"); //_context.Entry(CentralPolicyFile).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } } } return(Ok(new { status = true })); }