public async Task <IActionResult> PutPTHThread(int id, PTHThread pTHThread) { if (id != pTHThread.Id) { return(BadRequest()); } _context.Entry(pTHThread).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PTHThreadExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Title,CreatTime,ModifyTime,OP,ThreadCategory,ToolOrTech")] PTHThread pTHThread) { if (ModelState.IsValid) { _context.Add(pTHThread); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), controllerName: "PTHThreads", routeValues: new { ThreadCategory = pTHThread.ThreadCategory, ToolOrTech = pTHThread.ToolOrTech } )); } return(View(pTHThread)); }
public async Task <IActionResult> Create([Bind("Id,Subject,OP")] PTHPost pTHPost, string editordata, string ThreadId, string ThreadCategory, string ToolOrTech) { //System.Diagnostics.Debug.WriteLine(editordata); if (ModelState.IsValid) { pTHPost.PostTime = DateTime.Now; //generate the random prefix for file name var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[10]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var fileNamePrefix = new String(stringChars); pTHPost.PostFileName = fileNamePrefix + "-" + pTHPost.Subject; //All files are named with the subject prefixed with random string //create txt file and then write the file var postFile = System.IO.File.Create("Posts/" + pTHPost.PostFileName + ".txt"); var postFileWriter = new System.IO.StreamWriter(postFile); postFileWriter.WriteLine(editordata); postFileWriter.Dispose(); pTHPost.PTHThreadId = int.Parse(ThreadId); _context.Add(pTHPost); await _context.SaveChangesAsync(); //fixed empty list after creation through passing ThreadId for redirection return(RedirectToAction(nameof(Index), new { ThreadId = pTHPost.PTHThreadId, ThreadCategory, ToolOrTech })); } ViewData["PTHThreadId"] = new SelectList(_context.PTHThreads, "Id", "Id", pTHPost.PTHThreadId); return(View(pTHPost)); }
public async Task <IActionResult> CreateAsync([Bind("FirstName,LastName,Address,City,Province,PostalCode,Phone,Email")] Models.Order order, string Total) { order.CustomerID = User.FindFirstValue(ClaimTypes.NameIdentifier); order.OrderDate = DateTime.Now; order.Total = int.Parse(Total); //if (ModelState.IsValid) //{ //HttpContext.Session.SetObject("order", order); _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Payment))); //} //return View(order); }