public async Task <IActionResult> Edit(int id, [Bind("ID,OwnerID,text")] BlurbModel blurbModel)
        {
            if (id != blurbModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blurbModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlurbModelExists(blurbModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blurbModel));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] BlurbModel blurb)
        {
            if (blurb == null)
            {
                return(BadRequest("Required data was not supplied."));
            }

            if (!await Exists(id))
            {
                return(NotFound());
            }

            var record = await db.Blurbs.FindAsync(id);

            if (blurb.Name != null && record.Name != blurb.Name)
            {
                record.Name = blurb.Name;
            }

            if (blurb.Blurb != null && record.Blurb != blurb.Blurb)
            {
                record.Blurb = blurb.Blurb;
            }

            return(await SaveChanges(record, ActionType.Put));
        }
        public async Task <IActionResult> Create([Bind("ID,OwnerID,text")] BlurbModel blurbModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blurbModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blurbModel));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> Post([FromBody] BlurbModel record)
        {
            if (record == null)
            {
                return(BadRequest("Required data was not supplied."));
            }

            if (await Exists(record.Name))
            {
                return(Conflict());
            }

            db.Blurbs.Add(record);

            return(await SaveChanges(record, ActionType.Post));
        }