Example #1
0
        // PUT api/Product/5
        //PUT thant means Update the recored.
        public HttpResponseMessage PutMst_Product(int id, Mst_Product mst_product)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != mst_product.PID)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Example #2
0
        // GET api/Product/5
        public Mst_Product GetMst_Product(int id)
        {
            Mst_Product mst_product = db.Mst_Product.Find(id);

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

            return(mst_product);
        }
Example #3
0
        // POST api/Product
        //Post thant means Inset recored.
        public HttpResponseMessage PostMst_Product(Mst_Product mst_product)
        {
            if (ModelState.IsValid)
            {
                db.Mst_Product.Add(mst_product);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, mst_product);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = mst_product.PID }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Example #4
0
        // DELETE api/Product/5
        public HttpResponseMessage DeleteMst_Product(int id)
        {
            Mst_Product mst_product = db.Mst_Product.Find(id);

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

            db.Mst_Product.Remove(mst_product);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, mst_product));
        }
        public JsonResult SaveAndUpdateProduct(int PID, string Name, string Description, float Price)
        {
            var result = new jsonMessage();

            try
            {
                //define the model
                Mst_Product _Mst_Product = new Mst_Product();
                _Mst_Product.PID         = PID;
                _Mst_Product.Name        = Name;
                _Mst_Product.Description = Description;
                _Mst_Product.Price       = Price;


                //for insert recored..
                if (_Mst_Product.PID == 0)
                {
                    context.Mst_Product.Add(_Mst_Product);
                    result.Message = "your product has been saved success..";
                    result.Status  = true;
                }
                else  //for update recored..
                {
                    context.Entry(_Mst_Product).State = EntityState.Modified;
                    result.Message = "your product has been updated successfully..";
                    result.Status  = true;
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                ErrorLogers.ErrorLog(ex);
                result.Message = "We are unable to process your request at this time. Please try again later.";
                result.Status  = false;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult DeleteProduct(int id)
        {
            var result = new jsonMessage();

            try
            {
                var product = new Mst_Product {
                    PID = id
                };
                context.Entry(product).State = EntityState.Deleted;
                context.SaveChanges();


                result.Message = "your product has been deleted successfully..";
                result.Status  = true;
            }
            catch (Exception ex)
            {
                ErrorLogers.ErrorLog(ex);
                result.Message = "We are unable to process your request at this time. Please try again later.";
                result.Status  = false;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }