Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Department).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(Department.DepartmentID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?Id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var ParentBoard = _context.mBoards.AsNoTracking().FirstOrDefault(m => m.ID == Id);

            var newBoard = new mBoard();


            //newBoard.Name = "ImsiName";
            //newBoard.WriterID = "ImsiID";



            if (await TryUpdateModelAsync <mBoard>(
                    newBoard, "mboard", b => b.WriterID, b => b.Name, b => b.Password,
                    b => b.Password, b => b.Title, b => b.Content, b => b.Category, b => b.Encoing))
            {
                newBoard.PosteDate     = DateTime.Now;
                newBoard.PostIp        = HttpContext.Connection.RemoteIpAddress.ToString();
                newBoard.ReadCount     = 0;
                newBoard.ReplySubCount = 0;

                newBoard.Ref      = ParentBoard.Ref;
                newBoard.Step     = ParentBoard.Step + 1;
                newBoard.RefOrder = ParentBoard.RefOrder + 1;
                newBoard.DelFlag  = false;

                _context.mBoards.Add(newBoard);

                var mBoardsToUpdate = _context.mBoards.Where(m => m.Ref == ParentBoard.Ref && m.RefOrder >= newBoard.RefOrder);
                await mBoardsToUpdate.ForEachAsync(m => m.RefOrder = m.RefOrder + 1);


                _context.Attach(ParentBoard).State = EntityState.Modified;

                ParentBoard.ReplySubCount++;

                await _context.SaveChangesAsync();

                var aa = Request.Query["Path"].ToString();
                //return RedirectToPage("./Index");
                return(Redirect("../mBoards" + Request.Query["Path"].ToString()));
            }

            return(Page());
        }