예제 #1
0
        //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));
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
 // GET api/CustomersTableView
 public HttpResponseMessage Get()
 {
     using (LoanDBContext db = new LoanDBContext())
     {
         return(Request.CreateResponse(HttpStatusCode.OK, db.customers.ToList()));
     }
 }
예제 #4
0
        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));
            }
        }
예제 #5
0
        // 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();
            });
        }
예제 #6
0
        // 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;
 }
예제 #8
0
 public LoanManagementRepository(LoanDBContext loanDBContext)
 {
     this._loanDBContext = loanDBContext;
 }
예제 #9
0
 public LoanManagementController(LoanDBContext loanDBContext)
 {
     _loanDBContext            = loanDBContext;
     _loanManagementRepository = new LoanManagementRepository(_loanDBContext);
 }