protected void Page_Load(object sender, EventArgs e) { // Disable the ones which cannot be updated disableFields(); if (!IsPostBack) { // Get the loanId to update loanId = Convert.ToInt32(Request.QueryString["loanId"]); // Get the record LoanDTO loanDTO = new LoanDTO(); loanDTO = DataLibrary.Loan.getLoanDTOById(loanId); // Loan section drop down list ddlSection.DataSource = Section.getAll(); ddlSection.DataTextField = "Name"; ddlSection.DataValueField = "SectionId"; ddlSection.DataBind(); // Fill the textBoxes boxCopyId.Text = loanDTO.CopyId.ToString(); boxLoanId.Text = loanDTO.LoanId.ToString(); boxName.Text = loanDTO.Name; boxLastName.Text = loanDTO.LastName; boxDni.Text = loanDTO.Dni.ToString(); boxTitle.Text = loanDTO.Title; boxAuthor.Text = loanDTO.Author; ddlSection.Text = loanDTO.Section; boxDelivery.Text = loanDTO.DeliveryDate.ToString("dd/MM/yyyy"); boxLoanDate.Text = loanDTO.LoanDate.ToString("dd/MM/yyyy"); } }
public static LoanDTO DALtoDTO(Loan loan) { LoanDTO loanDTO = new LoanDTO() { amount = loan.Amount, date_start = loan.RepaymentStart, month = loan.Months, id_user = loan.UserId, loan_status = loan.NameManagement_status, //management_status = loan.management_status, //guarantee1 = loan.guarantee_1, //guarantee2 = loan.guaantee_2, //payments = loan.payments, remark = loan.remark, Score = (int)loan.Score, status = Management_statusBL.GetByName(loan.NameManagement_status), // BeginningRepayment = loan.BeginningRepayment, EntryDate = loan.EnteryDate, id_loan = loan.LoanId, // management_Status=loan.management_status, NumRepayment = loan.Num_payments, // paid= loan.paid }; using (SuperGmachEntities db = new SuperGmachEntities()) { User user = db.Users.FirstOrDefault(u => u.UserId == loan.UserId); loanDTO.UserName = user.firstName + " " + user.lastname; } return(loanDTO); }
public static void Add(LoanDTO loan) { SetScore(loan); db Sgmach = new db(); //if its Approved Loan loanDAL = LoanConvert.DTOtoDAL(loan); loanDAL = Sgmach.Loans.Add(loanDAL).Entity; Sgmach.SaveChanges(); if (loan.management_Status == "Approved") { int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start); if (FutureBalance < loan.amount) { loanDAL.remark += " יתרת הגמח ביום התחלת הלוואה קטנה מסכום ההלוואה"; loanDAL.NameManagement_status = "Invalid"; } else { SetRepayment(loanDAL); if (loan.NameStatus == "active") { FundBL.Subtract_Balance(loan.amount); } Sgmach.SaveChanges(); } loan.paid = false; // Loan loanDAL = LoanConvert.DTOtoDAL(loan); // loanDAL = Sgmach.Loans.Add(loanDAL).Entity; Sgmach.SaveChanges(); } }
public async Task <IActionResult> Edit(int id, [Bind("LoanID,BookID,StudentID,DateLoan")] LoanDTO loanDTO) { if (id != loanDTO.LoanID) { return(NotFound()); } if (ModelState.IsValid) { try { var loan = mapper.Map <Loan>(loanDTO); _context.Update(loan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoanExists(loanDTO.LoanID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookID"] = new SelectList(_context.Books, "BookID", "BookID", loanDTO.BookID); ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", loanDTO.StudentID); return(View(loanDTO)); }
public static Loan DTOtoDAL(LoanDTO loan) { Loan loanDAL = new Loan() { Amount = loan.amount, RepaymentStart = loan.date_start, Months = loan.month, UserId = loan.id_user, NameManagement_status = loan.management_Status, NameStatus = loan.NameStatus, //management_status=loan.management_status, //guarantee_1=loan.guarantee1, //guaantee_2=loan.guarantee2, //payments=loan.payments, remark = loan.remark, Score = loan.Score, // BeginningRepayment = loan.BeginningRepayment, EnteryDate = loan.EntryDate, LoanId = loan.id_loan, Num_payments = loan.NumRepayment, // paid = loan.paid }; return(loanDAL); }
public IActionResult PutLoan([FromBody] LoanDTO loanDTO) { try { Loan loan = _context.Loans.FirstOrDefault(b => b.Id == loanDTO.Id); if (loan == null) { return(NotFound()); } loan.TomeId = loanDTO.TomeId; loan.FirstDay = loanDTO.FirstDay; loan.LastDay = loanDTO.LastDay; loan.IsActive = loanDTO.IsActive; _context.SaveChanges(); return(Ok()); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public static void Update(LoanDTO loan) { db Sgmach = new db(); Loan loanDAL = Sgmach.Loans.FirstOrDefault(l => l.LoanId == loan.id_loan); if (loanDAL == null) { throw new Exception("loan not found"); } //if it became Approved if (loanDAL.NameManagement_status != "Approved" && loan.loan_status == "Approved") { int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start); if (FutureBalance - 2000 < loan.amount) { throw new Exception("you can loanding :balance<loan.amount"); } if (FundBL.GetById("0").balance < loan.amount) { throw new Exception("you can loanding :balance<loan.amount"); } else { SetRepayment(loanDAL); } } // loanDAL.loan_status = loan.loan_status; loanDAL.Months = loan.month; loanDAL.RepaymentStart = loan.date_start; // loanDAL.paid = loan.paid; loanDAL.remark = loan.remark; Sgmach.SaveChanges(); }
public IActionResult AddLoanByUsername(string name, [FromBody] LoanDTO loan) { _logger.LogInformation("Entering AddLoanByUsername"); if (loan == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } User user = _repository.GetUser(name); if (user == null) { string message = $"AddLoanByUsername. Could not find user by name [{name}]."; _logger.LogError(message); return(BadRequest(message)); } Loan newLoan = new Loan() { Account = user.Account, Ammount = loan.Ammount, Borrow = loan.Borrow, Description = loan.Description, Payed = loan.Payed }; LoanDTO loanAdded = new LoanDTO(_repository.AddLoan(newLoan)); _logger.LogInformation($"Exiting AddLoanByUsername"); return(Ok(loanAdded)); }
public async Task <IActionResult> Put(int id, [FromBody] LoanDTO loan) { logger.LogInformation("{username} executed Put({id}, {loan}).", User.Identity.Name, id, loan); return(await TryOrError(logger, async() => { await service.UpdateLoanAsync(id, loan); return new NoContentResult(); })); }
public override Loan CalculateLoan(LoanDTO loanDTO) { Loan loan = new Loan(); loan.LoanType = loanDTO.LoanType; loan.InterestRate = rateParser.GetRateByLoanType(loanDTO.LoanType); // do other processing return(loan); }
public bool HasRead(int user_id, int book_id) { LoanDTO loan = _repo.GetLoan(user_id, book_id); if (loan == null) { return(false); } return(true); }
public async Task Update(Guid loanId, [FromBody] LoanDTO loanToUpdate)//לבדוק שהמיפוי אכן עובד ולראות אם לקבל יד { LoanModel loanModel = _mapper.Map <LoanModel>(loanToUpdate); Guid _loanId = await _loansService.Update(loanId, loanModel);//האם צריך שיחזור היד CheckLoanValid loanToCheck = _mapper.Map <CheckLoanValid>(loanModel); loanToCheck.LoanDetails.LoanId = loanId;//לבדוק שאכן מאותחל בערך await _messageSession.Send(loanToCheck) .ConfigureAwait(false); }
public async Task <ActionResult> Post([FromBody] LoanDTO newLoan) { if (newLoan == null) { return(BadRequest("Invalid data")); } return(Ok(await _mediator.Send(new CreateLoanCommand { Loan = newLoan }))); }
public async Task <ActionResult> Get(int id) { if (id < 0) { return(BadRequest("Invalid data")); } LoanDTO response = await _mediator.Send(new GetLoanQuery { Id = id }); return(response == null?NotFound("Entry not found") : Ok(response)); }
public async Task <ActionResult> Put(int loanId, [FromBody] LoanDTO updatedLoan) { if (loanId < 0 || updatedLoan == null) { return(BadRequest("Invalid data")); } return(Ok(await _mediator.Send(new UpdateLoanCommand { LoanId = loanId, Loan = updatedLoan }))); }
public async Task Update(Guid loanId, [FromBody] LoanDTO loanToUpdate) { LoanModel loanModel = _mapper.Map <LoanModel>(loanToUpdate); await _loansService.Update(loanId, loanModel); CheckLoanValid loanToCheck = new CheckLoanValid(); LoanDetails loanDetails = _mapper.Map <LoanDetails>(loanModel); loanDetails.LoanId = loanId; loanToCheck.LoanDetails = loanDetails; await _messageSession.Send(loanToCheck); }
/// <summary> /// Delete a loan /// </summary> /// <param name="entity"></param> public void Remove(LoanDTO entity) { try { // call repository method to delete loan var selectedLoan = _mapper.Map <LoanDTO, Loan>(entity); _repository.Remove(selectedLoan); } catch (Exception ex) { throw ex; } }
private AccountTransfer CreateTransfer(PaymentDTO payment, LoanDTO loan) { var title = loan != null?CreateLoanTitle(loan) : $"Transaction of payment {payment.Id}"; return(new AccountTransfer { AccountId = payment.AccountId, PaymentId = payment.Id, Amount = payment.Amount, Recipient = payment.Recipient, Title = title }); }
/// <summary> /// Add a loan to the system /// </summary> /// <param name="entity"></param> public async Task <int> Add(LoanDTO entity) { try { // call repository method to save loan var test = _mapper.Map <LoanDTO, Loan>(entity); return(await _repository.Add(test)); } catch (Exception ex) { throw ex; } }
private LoanDTO CopyLoan(LoanDTO loan) => new LoanDTO { Id = loan.Id, Active = loan.Active, DateFrom = loan.DateFrom, DateTo = loan.DateTo, EmployeeId = loan.EmployeeId, Note = loan.Note, RecipientId = loan.RecipientId, ItemLines = loan.ItemLines.ToList(), GenericItemLines = loan.GenericItemLines.ToList() };
public static LoanDTO GetByID(int LoanId) { db Sgmach = new db(); Loan loan = Sgmach.Loans.FirstOrDefault(l => l.LoanId == LoanId); LoanDTO loanDTO = LoanConvert.DALtoDTO(loan); List <Repayments> Repayments = Sgmach.Repayments.Where(r => r.LoanId == LoanId).ToList(); foreach (var Repayment in Repayments) { loanDTO.Repayments.Add(RepaymentConvert.DALtoDTO(Repayment)); } return(loanDTO); }
// POST api/values public IHttpActionResult CreateNew([FromBody] LoanDTO value) { //foreach(var book in value.Loans) { book.Autor = value; } value.StartDate = DateTime.UtcNow; var insert = Mapper.Map <Loan>(value); using (var db = new LibraryExampleEntities()) { db.Loans.Add(insert); db.SaveChanges(); } return(Ok(insert.Id)); }
public async Task <IActionResult> Create([Bind("LoanID,BookID,StudentID,DateLoan")] LoanDTO loanDTO) { if (ModelState.IsValid) { var loan = mapper.Map <Loan>(loanDTO); _context.Add(loan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookID"] = new SelectList(_context.Books, "BookID", "BookID", loanDTO.BookID); ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", loanDTO.StudentID); return(View(loanDTO)); }
private void ReturnLoanButton(object sender, RoutedEventArgs e) { LoanDTO loanDTO = (LoanDTO)loanTable.SelectedItem; if (loanDTO != null) { loanService.returnBook(loanDTO); } else { MessageBox.Show("Wybierz pozycję zwracaną!", "Zwrot ksiązki"); } this.loadLoans(); }
public static void Update(LoanDTO loan) { db Sgmach = new db(); Loan loanDAL = Sgmach.Loans.FirstOrDefault(l => l.LoanId == loan.id_loan); loanDAL.Months = loan.month; loanDAL.remark = loan.remark; loanDAL.NameStatus = loan.NameStatus; loanDAL.RepaymentStart = loan.date_start; loanDAL.NameManagement_status = loan.management_Status; if (loanDAL == null) { throw new Exception("loan not found"); } //if it became Approved if (loanDAL.NameManagement_status != "Approved" && loan.management_Status == "Approved" && loanDAL.NameStatus != "active") { if (loan.NameStatus == "future") { int FutureBalance = FundBL.GetFutureBalance("1", loan.date_start); if (FutureBalance - 2000 < loan.amount) { loanDAL.remark = "סכום ההלוואה גדול מיתרת הגמח"; loanDAL.NameManagement_status = "Invalid"; } else { SetRepayment(loanDAL); loanDAL.NameManagement_status = "Approved"; } } } else if (loanDAL.NameManagement_status != "Approved" && loan.management_Status == "Approved" && loan.NameStatus == "active") { loanDAL.NameManagement_status = "Approved"; loanDAL.NameStatus = "active"; loanDAL.RepaymentStart = DateTime.Today; SetRepayment(loanDAL); } // if the loan become active (the friend get the money) the fund Balance have to Subtract if (loan.NameStatus == "active" && loanDAL.NameStatus != "active") { loanDAL.NameStatus = "active"; loan.management_Status = "Proper"; FundBL.Subtract_Balance(loan.amount); } Sgmach.SaveChanges(); }
public async Task <Guid> Create([FromBody] LoanDTO loan) { LoanModel loanModel = _mapper.Map <LoanModel>(loan); Guid loanId = await _loansService.Create(loanModel); CheckLoanValid loanToCheck = new CheckLoanValid(); LoanDetails loanDetails = _mapper.Map <LoanDetails>(loanModel); loanDetails.LoanId = loanId; loanToCheck.LoanDetails = loanDetails; await _messageSession.Send(loanToCheck); return(loanId); //Ok($"Your loan created successfully. Loan Id:{loanId}"); }
public bool AddNewLoan(string ReqID, string BookID) { LoanDTO loan = new LoanDTO { LoanID = getNewLoan(), ReqID = ReqID, BookID = BookID, BorrowedDate = DateTime.Today, ExpiredDate = DateTime.Today.AddDays(15), Status = 0 }; bool result = dao.AddNewLoan(loan); return(result); }
public LoanDTO GetLoan(int user_id, int book_id) { LoanDTO loan = (from l in _db.Loans where l.UserId == user_id && l.BookId == user_id select new LoanDTO { Id = l.Id, BookId = l.BookId, UserId = l.UserId, DateOfLoan = l.DateOfLoan, IsReturned = l.IsReturned }).FirstOrDefault(); return(loan); }
public async Task <Guid> Create([FromBody] LoanDTO loan)//לבדוק שהמיפוי אכן עובד ולראות אם לקבל יד { LoanModel loanModel = _mapper.Map <LoanModel>(loan); Guid loanId = await _loansService.Create(loanModel); CheckLoanValid loanToCheck = new CheckLoanValid(); LoanDetails loanDetails = _mapper.Map <LoanDetails>(loanModel); loanDetails.LoanId = loanId; loanToCheck.LoanDetails = loanDetails; await _messageSession.Send(loanToCheck) .ConfigureAwait(false); //del api return(loanId); }
public IActionResult GetLoanById(int id) { _logger.LogInformation("Entering GetLoanById"); Loan loan = _repository.GetLoanById(id); if (loan == null) { string message = $"GetLoanById. Could not find Loan by Id [{id}]."; _logger.LogError(message); return(NotFound(message)); } LoanDTO res = new LoanDTO(loan); _logger.LogInformation("Exiting GetLoanById"); return(Ok(res)); }