Example #1
0
        public IHttpActionResult PutCustomBill(int id, CustomBill customBill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customBill.CustomBillId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public CustomBill GetCustomBill(int billid)
        {
            CustomBill item = null;

            using (var context = new PBEntities())
            {
                item = context.CustomBills.Where(s => s.BillId == billid).FirstOrDefault();
            }
            return(item);
        }
 public void DeleteCustomBill(CustomBill custombill)
 {
     if (custombill == null)
     {
         throw new ArgumentException("custombill is null.");
     }
     if (ModelState.IsValid)
     {
         this.context.AddUpdateDeleteCustomBill(null, null, custombill);
     }
 }
Example #4
0
        public IHttpActionResult DeleteCustomBill(int id)
        {
            CustomBill customBill = db.CustomBills.Find(id);

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

            db.CustomBills.Remove(customBill);
            db.SaveChanges();

            return(Ok(customBill));
        }
 public HttpResponseMessage UpdateCustomBill(CustomBill custombill)
 {
     if (custombill == null)
     {
         throw new ArgumentException("custombill is null.");
     }
     if (ModelState.IsValid)
     {
         this.context.AddUpdateDeleteCustomBill(null, custombill, null);
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
        public HttpResponseMessage CreateCustomBill(CustomBill custombill)
        {
            CustomBill tempItem = new CustomBill();

            if (custombill == null)
            {
                throw new ArgumentException("custombill is null.");
            }

            if (ModelState.IsValid)
            {
                tempItem = this.context.AddUpdateDeleteCustomBill(custombill, null, null);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, tempItem);
                //response.Headers.Location = new Uri(this.Request.RequestUri.AbsoluteUri + "/" + tempItem.Id);
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
        public CustomBill AddUpdateDeleteCustomBill(CustomBill AddItem, CustomBill UpdateItem, CustomBill DeleteItem)
        {
            if (AddItem != null)
            {
                CustomBill newItem = this.uow.CustomBillRepository.Insert(AddItem);
                this.uow.Save();
                return(newItem);
            }

            if (UpdateItem != null)
            {
                this.uow.CustomBillRepository.Update(UpdateItem);
            }

            if (DeleteItem != null)
            {
                this.uow.CustomBillRepository.Delete(DeleteItem);
            }

            this.uow.Save();

            return(null);
        }
Example #8
0
        public IHttpActionResult PostCustomBill(CustomBillModel customBillModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customBill = new CustomBill
            {
                BillName        = customBillModel.BillName,
                EstimatedAmount = customBillModel.EstimatedAmount,
                UserId          = customBillModel.UserId,
                WebsiteUrl      = customBillModel.WebsiteUrl
            };

            db.CustomBills.Add(customBill);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CustomBillExists(customBill.CustomBillId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            customBillModel.CustomBillId = customBill.CustomBillId;

            return(Ok(customBillModel));
        }