Esempio n. 1
0
        public ActionResult Create(loans loans)
        {
            if (ModelState.IsValid)
            {
                var existingLoans = db.loans.Where(l => l.LoanOriginatedBy == loans.LoanOriginatedBy &&
                                                   l.IsInactive == false).ToList();

                if (existingLoans.Count > 0)
                {
                    var number = existingLoans.Select(l => new { name = l.CustomerForeName + " " + l.CustomerSurName }).Distinct().ToList();
                    if (number.Count() > 10)
                    {
                        TempData["LoansCreation"] = "An error occured while creating the loan. Managers are not allowed to create loans if more than 10 active customer loans already exists.";
                        return(RedirectToAction("Index"));
                    }
                }

                loans.LoanID = Guid.NewGuid();
                db.loans.Add(loans);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loans));
        }
        //- -----  Create the Loan details with bases of Role "Admin",models are loan Holder%details both
        public void PosttheLoandata(int roleid, LoanHolder loanHolder)
        {
            var x = loanDBContext.RoleDescriptions.Where(x => x.Roleid == roleid).Select(x => x.RoleType).FirstOrDefault();

            if (x == "Admin")
            {
                loanDBContext.loanHolders.Add(loanHolder);
                loanDBContext.SaveChanges();
            }
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "CustomerID,Title,ForeName,MiddleInitial,SurName,DateofBirth,Status")] customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.CustomerID = Guid.NewGuid();
                db.customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Esempio n. 4
0
 public bool AddLoan(LoanDetail loanDetail)
 {
     try
     {
         _loanDBContext.LoanDetails.Add(loanDetail);
         _loanDBContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 5
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));
            }
        }
Esempio n. 6
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));
            }
        }
Esempio n. 7
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));
            }
        }