예제 #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Price,Name,BaoZhiQi,Weight,Seller")] Cai cai)
        {
            if (id != cai.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cai);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CaiExists(cai.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cai));
        }
        public async Task <ActionResult <Cai> > PostCai(Cai cai)
        {
            _context.Cai.Add(cai);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCai", new { id = cai.Id }, cai));
        }
        public async Task <IActionResult> PutCai(Guid id, Cai cai)
        {
            if (id != cai.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cai).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CaiExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Price,Name,BaoZhiQi,Weight,Seller")] Cai cai)
        {
            if (ModelState.IsValid)
            {
                cai.Id = Guid.NewGuid();
                _context.Add(cai);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cai));
        }