Exemplo n.º 1
0
        public async Task<IHttpActionResult> PutCategory(int id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != category.Id)
            {
                return BadRequest();
            }

            db.Entry(category).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
        public void ListViewCategories_InsertItem()
        {
            var item = new Category();
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                this.dbContext.Categories.Add(item);
                this.dbContext.SaveChanges();

            }
        }
Exemplo n.º 3
0
        public async Task<IHttpActionResult> PostCategory(Category category)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Category.Add(category);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = category.Id }, category);
        }
        private bool CreateCategori()
        {
            int affectedRows = 0;

            using (LibraryEntities db = new LibraryEntities())
            {
                Models.Category newcategori = new Models.Category
                {
                    Name = txtNameCategori.Text
                };
                db.Categories.Add(newcategori);

                db.SaveChanges();
            }
            if (affectedRows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }