Esempio n. 1
0
        public IHttpActionResult PutAccessoryCategory(int id, AccessoryCategory accessoryCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != accessoryCategory.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccessoryCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult GetAccessoryCategory(int id)
        {
            AccessoryCategory accessoryCategory = db.AccessoryCategories.Find(id);

            if (accessoryCategory == null)
            {
                return(NotFound());
            }

            return(Ok(accessoryCategory));
        }
Esempio n. 3
0
        public IHttpActionResult PostAccessoryCategory(AccessoryCategory accessoryCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AccessoryCategories.Add(accessoryCategory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = accessoryCategory.ID }, accessoryCategory));
        }
Esempio n. 4
0
        public IHttpActionResult DeleteAccessoryCategory(int id)
        {
            AccessoryCategory accessoryCategory = db.AccessoryCategories.Find(id);

            if (accessoryCategory == null)
            {
                return(NotFound());
            }

            db.AccessoryCategories.Remove(accessoryCategory);
            db.SaveChanges();

            return(Ok(accessoryCategory));
        }
Esempio n. 5
0
        public static bool TryToGetSelectedItem(AccessoryCategory category, out Accessory accessory)
        {
            foreach (var tagName in Character.Current.SelectedAccessories)
            {
                if (!Enum.TryParse(tagName, out AccessoryTag accessoryTag))
                {
                    continue;
                }
                accessory = accessoryTag.ToAccessory();
                if (accessory.category == category)
                {
                    return(true);
                }
            }

            accessory = null;
            return(false);
        }
Esempio n. 6
0
        public IActionResult InsertAccCat([FromBody] DTO.AccessoryCategory accCat)
        {
            AccessoryCategoryDAO dao = new AccessoryCategoryDAO(_context);
            AccessoryCategory    dto = new AccessoryCategory
            {
                AccCatId   = accCat.AccCatId,
                AccCatName = accCat.AccCatName,
                PetCatId   = accCat.PetCatId
            };
            string msg;

            if (dao.Insert(dto))
            {
                msg = "Insert accessory category success";
            }
            else
            {
                msg = "Insert accessory category failed";
            }
            return(new JsonResult(msg));
        }
Esempio n. 7
0
 public bool Delete(AccessoryCategory dto)
 {
     _context.AccessoryCategory.Remove(dto);
     return(_context.SaveChanges() != 0);
 }
Esempio n. 8
0
 public bool Update(AccessoryCategory dto)
 {
     _context.AccessoryCategory.Update(dto);
     return(_context.SaveChanges() != 0);
 }
Esempio n. 9
0
 public bool Insert(AccessoryCategory dto)
 {
     _context.AccessoryCategory.Add(dto);
     return(_context.SaveChanges() != 0);
 }