Beispiel #1
0
        // GET api/EmployeeBenefit/5
        public EBenefit GetEmployeeBenefit(int id)
        {
            EBenefit employeebenefit = db.EmployeeBenefits.Find(id);

            if (employeebenefit == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(employeebenefit);
        }
Beispiel #2
0
        // POST api/EmployeeBenefit
        public HttpResponseMessage PostEmployeeBenefit(EBenefit employeebenefit)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeBenefits.Add(employeebenefit);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, employeebenefit);
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Beispiel #3
0
        // DELETE api/EmployeeBenefit/5
        public HttpResponseMessage DeleteEmployeeBenefit(int id)
        {
            EBenefit employeebenefit = db.EmployeeBenefits.Find(id);

            if (employeebenefit == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.EmployeeBenefits.Remove(employeebenefit);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, employeebenefit));
        }
Beispiel #4
0
        // PUT api/EmployeeBenefit/5
        public HttpResponseMessage PutEmployeeBenefit(int id, EBenefit employeebenefit)
        {
            if (ModelState.IsValid && id == employeebenefit.EmployeeBenefitId)
            {
                db.Entry(employeebenefit).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }