public ResponseModel Post([FromBody] Customer value) { try { using (UKABEntities objContext = new UKABEntities()) { ResponseModel objResponse = new ResponseModel(); if (value != null) { objContext.Customers.Add(value); objContext.SaveChanges(); } objResponse.Data = JsonConvert.SerializeObject(value); objResponse.Status = true; objResponse.Message = "Data Posted Succesfully"; return(objResponse); } } catch (Exception ex) { throw ex; // Currently I am throwing the error. In real scenario we can log it which helps in debugging the issue. } }
// GET api/values public ResponseModel Get() { try { using (UKABEntities objContext = new UKABEntities()) { ResponseModel objResponse = new ResponseModel(); List <Customer> customers = objContext.Customers.AsEnumerable <Customer>().ToList <Customer>(); objResponse.Data = JsonConvert.SerializeObject(customers); objResponse.Status = true; objResponse.Message = "Data Received Succesfully"; return(objResponse); } } catch (Exception ex) { throw ex; // Currently I am throwing the error. In real scenario we can log it which helps in debugging the issue. } }