コード例 #1
0
ファイル: Create.cshtml.cs プロジェクト: CusterN/Crisis
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //Check and make sure all the fields are filled in. Also make sure you aren't adding a duplicate.
            if (!ModelState.IsValid || _context.Supplier.Any(s => s.SupplierNo.Equals(Supplier.SupplierNo)) || Comment is null)
            {
                return(RedirectToPage("./Index"));
            }


            _context.Supplier.Add(Supplier);
            await _context.SaveChangesAsync();

            Comment newComment = new Comment
            {
                Id         = 0,
                SupplierId = Supplier.Id,
                Supplier   = Supplier,
                CreateDate = Supplier.CreateDate,
                Creator    = Supplier.Creator,
                Body       = Comment,
            };

            _context.Comment.Add(newComment);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
ファイル: Index.cshtml.cs プロジェクト: CusterN/Crisis
        public async Task OnPostEditAsync()
        {
            Supplier ExistingRecord = await _context.Supplier.FirstOrDefaultAsync(m => m.Id == Supplier.Id);

            if (ExistingRecord == null)
            {
                //If the supplier doesn't exist I want to add it, but this isn't working quite yet.
                //_context.Supplier.Add(Supplier);
            }
            else
            {
                ExistingRecord.SupplierNo   = Supplier.SupplierNo;
                ExistingRecord.CreateDate   = Supplier.CreateDate;
                ExistingRecord.Creator      = Supplier.Creator;
                ExistingRecord.ReopenDate   = Supplier.ReopenDate;
                ExistingRecord.StatusId     = Supplier.StatusId;
                ExistingRecord.CategoryId   = Supplier.CategoryId;
                ExistingRecord.EscalationId = Supplier.EscalationId;

                _context.Attach(ExistingRecord).State = EntityState.Modified;
            }
            await _context.SaveChangesAsync();

            StatusMessage = "Saved!";
            await OnGetAsync();
        }
コード例 #3
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(Comment.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("../Index"));
        }