public IHttpActionResult PutLoanMaster(int id, LoanMaster loanMaster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loanMaster.LoanID) { return(BadRequest()); } db.Entry(loanMaster).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LoanMasterExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private bool ValidateRequest( string httpMethod, LoanMaster value, object param1, out List <string> validationFailureMessages) { bool result = true; validationFailureMessages = new List <string>(); if (HttpMethods.IsPost(httpMethod)) { if (value.Id != 0) { result = false; validationFailureMessages.Add(Constants.Message.ValidationFailedIdShouldBeNull); } } if (HttpMethods.IsPut(httpMethod)) { if (value.Id.ToString() != param1.ToString()) { result = false; validationFailureMessages.Add(Constants.Message.ValidationFailedIdsShouldMatch); } } _appLogger.LogError($"LoanMasterController::Validate(httpMethod: {httpMethod}, <value>, param1: {param1}) >> Result = {result}."); return(result); }
public ActionResult Create([Bind(Include = "LoanID,LoanName,LoanDescription,LoanAmount,FromDate,InterestPercentage,CustomerID,AddedDate,AddedUser")] LoanMaster loanMaster) { if (ModelState.IsValid) { LoanPaymentDetail londet = new LoanPaymentDetail(); londet.FromDate = loanMaster.FromDate; londet.BalanceAmount = loanMaster.LoanAmount; londet.IsCurrent = true; londet.InterestPercentage = loanMaster.InterestPercentage; loanMaster.LoanPaymentDetails.Add(londet); db.LoanMasters.Add(loanMaster); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", loanMaster.CustomerID); return(View(loanMaster)); }
public static string loanmasterClre(string name, string add) { LoanMaster lonmas = new LoanMaster(); lonmas.clr(); name = string.Empty; return(name); }
public ActionResult DeleteConfirmed(int id) { LoanMaster loanMaster = db.LoanMasters.Find(id); db.LoanMasters.Remove(loanMaster); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "LoanID,LoanName,LoanDescription,LoanAmount,FromDate,InterestPercentage,CustomerID,AddedDate,AddedUser")] LoanMaster loanMaster) { if (ModelState.IsValid) { db.Entry(loanMaster).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", loanMaster.CustomerID); return(View(loanMaster)); }
public void GetLoanDataofToday(int loanid) { using (WebAppContext cntxt = new WebAppContext()) { LoanMaster lnmodel = cntxt.LoanMasters.Find(loanid); if (lnmodel != null) { } } }
public void CreateRenewedLoan(LoansClientsInventoryDTO loanSubmission) { using (var context = new SingularityDBContext()) { var loanNumIncrement = LoanIncrement(); var newLoan = new LoanMaster { ClientId = loanSubmission.ClientId, DateCreated = DateTime.Now, LoanNumber = loanNumIncrement, IsActive = true, IsDeleted = false }; context.LoanMasters.Add(newLoan); context.SaveChanges(); LoanDetail[] itemsListed = new LoanDetail[loanSubmission.InventoryItems.Count]; for (int i = 0; i < itemsListed.Length; i++) { foreach (var itemId in loanSubmission.InventoryItems) { //if (loanSubmission.Availability) //{ itemsListed[i] = new LoanDetail { InventoryItemId = itemId.InventoryItemId, LoanMasterId = newLoan.LoanMasterId, Purpose = loanSubmission.Purpose, PurposeType = loanSubmission.PurposeType }; i++; //}; } ; //break; } List <LoanDetail> loanDetailsList = itemsListed.ToList(); //now we can add a range of loan details to the loan details table context.LoanDetails.AddRange(loanDetailsList); context.SaveChanges(); //Update Inventory Items' Availability var itemIds = GetInventoryItemIdsByLoanNumber(newLoan.LoanNumber); MarkInventoryItemsAsNotAvailable(context, itemIds); } }
public IHttpActionResult DeleteLoanMaster(int id) { LoanMaster loanMaster = db.LoanMasters.Find(id); if (loanMaster == null) { return(NotFound()); } db.LoanMasters.Remove(loanMaster); db.SaveChanges(); return(Ok(loanMaster)); }
// GET: CustomerLoans/LoanMasters/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LoanMaster loanMaster = db.LoanMasters.Find(id); if (loanMaster == null) { return(HttpNotFound()); } return(View(loanMaster)); }
// GET: CustomerLoans/LoanMasters/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LoanMaster loanMaster = db.LoanMasters.Find(id); if (loanMaster == null) { return(HttpNotFound()); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", loanMaster.CustomerID); return(View(loanMaster)); }
public ActionResult <LoanMaster> Create([FromBody] LoanMaster value) { string methodName = nameof(Create), title = Constants.Message.TitleCreateObject; List <string> validationFailureMessages; try { var isValid = ValidateRequest(HttpMethods.Post, value, null, out validationFailureMessages); if (isValid) { return(_loanMasterRepository.Add(value)); } else { var errorMessage = GetFlattenedMessage(validationFailureMessages, Constants.Message.ValidationFailed); return(BadRequestError(methodName, title, null, errorMessage)); } } catch (System.Exception ex) { return(InternalServerError(methodName, title, ex)); } }
public void CreateLoan(LoanSubmission loanSubmission) { //have client id using (var context = new SingularityDBContext()) { var loanNumIncrement = LoanIncrement(); var newLoan = new LoanMaster { ClientId = loanSubmission.ClientId, DateCreated = DateTime.Now, //can go into the constructor of LoanMaster -- haven't done this yet //IsActive = loanSubmission.IsActive //can probably be defaulted LoanNumber = loanNumIncrement, //we can create a utility class that auto increments this - see above IsActive = true }; context.LoanMasters.Add(newLoan); context.SaveChanges(); //this line actually writes the record to the db //after writing the record the newLoan object will have a populated Id that matches the db //in this way we can add LoanDetails that reference the correct LoanMaster //have item Ids //we can map over the itemIds enumerable and map a new list of LoanDetails -- functional! //LINQ query syntax //Create new LoanDetail for each item in InventoryItemIds list IEnumerable <LoanDetail> query = from itemId in loanSubmission.InventoryItemIds select new LoanDetail { InventoryItemId = itemId, LoanMasterId = newLoan.LoanMasterId, Purpose = loanSubmission.Purpose, PurposeType = loanSubmission.PurposeType }; //LINQ method syntax - would be same outcome as above query //IEnumerable<LoanDetail> methodQuery = // loanSubmission.InventoryItemIds.Select(id => new LoanDetail // { // InventoryItemId = id, // LoanMasterId = newLoan.LoanMasterId // }); //both are viable, sometimes query syntax feels more natural on joins and such //while method syntax can output some nice oneliners. //the point is that we use each item in a collection to create new LoanDetail //entities, mapping the properties we want over to the newly created object. //regardless, these queries have only returned something respects IEnumerable contract //we need concrete objects List <LoanDetail> loanDetailsList = query.ToList(); //now we can add a range of loan details to the loan details table context.LoanDetails.AddRange(loanDetailsList); context.SaveChanges(); ////Update Inventory Items' Availability var itemIds = GetInventoryItemIdsByLoanNumber(newLoan.LoanNumber); MarkInventoryItemsAsNotAvailable(context, itemIds); //or does this need to be like context.LoanDetails.AddRange(loanDetailsList); } }
public LoanViewModelMaster GetLoanMaster(int id) { LoanViewModelMaster mdl = new LoanViewModelMaster(); LoanMaster mstr = db.LoanMasters.Find(id); mdl.LoanID = mstr.LoanID; mdl.LoanName = mstr.LoanName.ToString(); mdl.LoanDescription = mstr.LoanDescription.ToString(); mdl.LoanAmount = mstr.LoanAmount; mdl.FromDate = mstr.FromDate; mdl.InterestPercentage = mstr.InterestPercentage; mdl.CustomerID = mstr.CustomerID; mdl.AddedDate = mstr.AddedDate ?? DateTime.Now; mdl.AddedUser = mstr.AddedUser; mdl.InOrOut = mstr.InOrOut.ToString(); mdl.InterestType = mstr.InterestType.ToString(); mdl.CustomerName = mstr.Customer.CustomerName; mdl.PhoneNumber = mstr.Customer.PhoneNumber; mdl.CustomerDetails = mstr.Customer.CustomerDetails; mdl.LastPaymentDate = null; mdl.LaystpaymentAmount = 0; mdl.BalanceAmount = 0; mdl.LoanPaymentDetailViewmodallist = new List <LoanPaymentDetailViewmodal>(); DateTime?lastdate = null; Decimal lastpaymentamount = 0; Decimal Latbalance = 0; foreach (var element in mstr.LoanPaymentDetails.OrderBy(u => u.LoanPayDate)) { LoanPaymentDetailViewmodal loandetview = new LoanPaymentDetailViewmodal(); loandetview.LoanPayDate = element.LoanPayDate; loandetview.FromDate = element.FromDate; loandetview.ToDate = DateTime.Parse(element.ToDate.ToString());; loandetview.Days = element.Days; loandetview.InterestPercentage = element.InterestPercentage; loandetview.Interest = element.Interest; loandetview.TotalAmount = element.TotalAmount; loandetview.PaidAmount = element.PaidAmount; loandetview.BalanceAmount = element.BalanceAmount; lastdate = element.LoanPayDate; lastpaymentamount = element.PaidAmount; Latbalance = element.BalanceAmount; mdl.LoanPaymentDetailViewmodallist.Add(loandetview); } if (mdl.LoanPaymentDetailViewmodallist.Count == 0) { mdl.LaystpaymentAmount = 0; mdl.BalanceAmount = mstr.LoanAmount; } else { mdl.LaystpaymentAmount = lastpaymentamount.ZeroIfNullorEmpty(); mdl.BalanceAmount = Latbalance.ZeroIfNullorEmpty(); mdl.LastPaymentDate = lastdate; } //mdl.LoanMaster. mdl.LoanPaymentDetailViewmodal = new LoanPaymentDetailViewmodal(); return(mdl); }