//Put public HttpResponseMessage Put(Guid?id, [FromBody] customer customer) { try { using (LoanDBContext db = new LoanDBContext()) { var entity = db.customers.Find(id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer with Id =" + id.ToString() + " not found to Update")); } else { entity.Title = customer.Title; entity.ForeName = customer.ForeName; entity.MiddleInitial = customer.MiddleInitial; entity.SurName = customer.SurName; entity.DateofBirth = customer.DateofBirth; entity.Status = customer.Status; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, customer)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage deleteCustomerRecord(Guid?id) { try { using (LoanDBContext db = new LoanDBContext()) { customer customer = db.customers.Find(id); if (customer == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer with Id =" + id.ToString() + " not found to delete")); } else { db.customers.Remove(customer); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, customer)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// GET api/CustomersTableView public HttpResponseMessage Get() { using (LoanDBContext db = new LoanDBContext()) { return(Request.CreateResponse(HttpStatusCode.OK, db.customers.ToList())); } }
public HttpResponseMessage updateCustomerDetails([FromBody] customer customer) { try { using (LoanDBContext db = new LoanDBContext()) { customer.CustomerID = Guid.NewGuid(); db.customers.Add(customer); db.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, customer); message.Headers.Location = new Uri(Request.RequestUri + customer.CustomerID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, LoanDBContext loanDBContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //loanDBContext.Database.Migrate(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// GET api/CustomersTableView/id public HttpResponseMessage Get(Guid?id) { try { using (LoanDBContext db = new LoanDBContext()) { var entity = db.customers.Find(id); if (entity != null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer with Id =" + id.ToString() + " not found")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public LoanDataRepository(LoanDBContext _loanDB) { loanDBContext = _loanDB; }
public LoanManagementRepository(LoanDBContext loanDBContext) { this._loanDBContext = loanDBContext; }
public LoanManagementController(LoanDBContext loanDBContext) { _loanDBContext = loanDBContext; _loanManagementRepository = new LoanManagementRepository(_loanDBContext); }