Beispiel #1
0
 public void UpdateSubCategoryTerm(SubCategoryTerm subCategoryTerm)
 {
     using (var context = new DataContext())
     {
         context.Entry(subCategoryTerm).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #2
0
 public SubCategoryTerm InsertSubCategoryTerm(SubCategoryTerm subCategoryTerm)
 {
     using (var context = new DataContext())
     {
         SubCategoryTerm newSubCategoryTemp = context.SubCategoryTerms.Add(subCategoryTerm);
         context.SaveChanges();
         return(newSubCategoryTemp);
     }
 }
Beispiel #3
0
 public void RemoveSubCategoryTerm(int id)
 {
     using (var context = new DataContext())
     {
         SubCategoryTerm subCategoryTerm = context.SubCategoryTerms.FirstOrDefault(c => c.ID == id);
         if (subCategoryTerm != null)
         {
             context.SubCategoryTerms.Remove(subCategoryTerm);
             context.SaveChanges();
         }
     }
 }
        // PUT api/<controller>/5
        public IHttpActionResult Put(SubCategoryTerm subCategoryTerm)
        {
            IHttpActionResult      result  = null;
            SubCategoryTermService service = new SubCategoryTermService();

            if (service.GetSubCategoryTerm(subCategoryTerm.ID) != null)
            {
                service.UpdateSubCategoryTerm(subCategoryTerm);
                result = Ok(subCategoryTerm);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
        public IHttpActionResult Post(SubCategoryTerm subCategoryTerm)
        {
            IHttpActionResult      result             = null;
            SubCategoryTermService service            = new SubCategoryTermService();
            SubCategoryTerm        newSubCategoryTerm = service.InsertSubCategoryTerm(subCategoryTerm);

            if (newSubCategoryTerm != null)
            {
                result = Created <SubCategoryTerm>(Request.RequestUri + newSubCategoryTerm.ID.ToString(), newSubCategoryTerm);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
        // GET api/<controller>/5
        public IHttpActionResult Get(int id)
        {
            IHttpActionResult result = null;

            SubCategoryTermService service = new SubCategoryTermService();

            SubCategoryTerm subCategoryTerm = service.GetSubCategoryTerm(id);

            if (subCategoryTerm != null)
            {
                result = Ok(subCategoryTerm);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
        // DELETE api/<controller>/5
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult      result  = null;
            SubCategoryTermService service = new SubCategoryTermService();

            SubCategoryTerm subCategoryTerm = service.GetSubCategoryTerm(id);

            if (subCategoryTerm != null)
            {
                service.RemoveSubCategoryTerm(id);

                result = Ok(true);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }