/// <summary>
        /// Método responsável por definir a data de devolução de um livro
        /// O modificador estático foi usado para otimizar o espaço de memória quando for chamado
        /// </summary>
        /// <param name="lending"></param>
        /// <returns></returns>
        private static DateTime CalculateDateDevolution(Lending lending)
        {
            DateTime dateDevolution = lending.dateLending.AddDays(totalDaysWeek);

            lending.dateDevolution = dateDevolution;
            return(lending.dateDevolution);
        }
Exemple #2
0
        public Lending newLending(Lending lending)
        {
            return(lending);

            int idGame1 = 0;
            int idGame2 = 0;
            int idGame3 = 0;

            if (lending.Games.Count > 0)
            {
                idGame1 = lending.Games[0].Id;
            }
            if (lending.Games.Count > 1)
            {
                idGame2 = lending.Games[1].Id;
            }
            if (lending.Games.Count > 2)
            {
                idGame3 = lending.Games[2].Id;
            }
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "EXEC new_lending " + lending.Number + ", '" + lending.Customer.Email + "', '" + lending.From.ToString("yyyy-MM-dd") + "', '" + lending.To.ToString("yyyy-MM-dd") + "', " + idGame1 + ", " + idGame2 + ", " + idGame3;;
            cmd.Connection  = dbHelper.connection;
            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();
            lending.Number = Convert.ToInt32(reader["Number"]);
            reader.Close();
            return(lending);
        }
Exemple #3
0
        public IActionResult CreateLending(int?id)
        {
            var model = new LendingCreateViewModel();

            model.Client       = clientService.GetClientById(id.Value);
            model.SelectClient = clientService.GetClients().Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            });
            model.SelectBook = bookService.GetBooks().Select(b => new SelectListItem
            {
                Text  = b.Title,
                Value = b.Id.ToString()
            });
            model.SelectLibrary = libraryService.GetLibraries().Select(l => new SelectListItem
            {
                Text  = l.Name,
                Value = l.Id.ToString()
            });


            var lending = new Lending();

            lending.ClientId = id.Value;
            model.Lending    = lending;

            return(View(model));
        }
Exemple #4
0
        public IActionResult OnGet(int?id)
        {
            Lending = new Lending();
            Lending.DatumZajmuvanje = DateTime.Now;

            if (id.HasValue)
            {
                Lending.ClientId = id.Value;
            }
            Client = clientService.GetClientById(id.Value);

            SelectBook = bookService.GetBooks().Select(b => new SelectListItem
            {
                Text  = b.Title,
                Value = b.Id.ToString()
            });
            SelectClient = clientService.GetClients().Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            });
            SelectLibrary = libraryService.GetLibraries().Select(l => new SelectListItem
            {
                Text  = l.Name,
                Value = l.Id.ToString()
            });


            return(Page());
        }
        public void FindLendingReceiptByCaseNumber()
        {
            DateTime start = new DateTime(2017, 11, 30);
            DateTime s**t  = new DateTime(2017, 12, 3);

            Device        device      = new Device("22", "Pelle");
            List <Device> listdevice5 = new List <Device>();

            listdevice5.Add(device);

            lr.CreateLoan(start, s**t, listdevice5);
            Lending loan       = lr.GetLoan();
            string  casenumber = "Søren-1234";
            string  loanerinfo = "Søren";

            LendingReceiptRepository.Instance.CreateLendingReceipt(loanerinfo, casenumber, loan, "Pelle");

            string         Casenumber     = "Søren-1234";
            LendingReceipt lendingreceipt = LendingReceiptRepository.Instance.FindReceiptByCasenumber(Casenumber);


            DateTime startdate = new DateTime(2017, 11, 30);

            Assert.AreEqual(startdate, lendingreceipt.Loan.StartDate);
        }
        public void LendBook(ObjectId userId, ObjectId bookId, DateTime startDateUtc, DateTime endDateUtc)
        {
            // Check if dates are logical.
            if (startDateUtc > endDateUtc)
            {
                return;
            }

            // Check if lending time is not exceeding maximum.
            var lendTime = endDateUtc.Subtract(startDateUtc);

            if (lendTime.TotalDays > _maximumLendingTimeInDays)
            {
                return;
            }

            // Check if book exists.
            if (_database.FindOneById <Book>(Book.CollectionName, bookId) == null)
            {
                return;
            }

            // Check if book is currently lent out.
            if (GetCurrentLendingBook(bookId) != null)
            {
                return;
            }

            // Create a new lending.
            var lending = new Lending(userId, bookId, startDateUtc, endDateUtc);

            _database.Create(lending, Lending.CollectionName);
        }
Exemple #7
0
        public async void RefreshSelectedClient()
        {
            var selectedClient = SelectedClient;

            await Task.Run(async() =>
            {
                if (SelectedClient == null || selectedClient != SelectedClient)
                {
                    return;
                }

                int id         = SelectedClient.Id;
                int lendingId  = SelectedLending != null ? SelectedLending.Id : -1;
                SelectedClient = null;

                using (var dbService = _dbServiceManager.GetService())
                {
                    Client newClient = dbService.Clients.Get(id);
                    ReplaceClient(AllClients, id, newClient);
                    ReplaceClient(Clients, id, newClient);

                    _selectedClient = newClient;
                    NotifyOfPropertyChange(() => SelectedClient);
                    await LoadLendings();

                    SelectedLending = SelectedClient.Lendings.FirstOrDefault(l => l.Id == lendingId);
                }
            });
        }
Exemple #8
0
        public bool InsertLending(LendingModel lending)
        {
            try
            {
                var dbLending = new Lending()
                {
                    LendingDate = lending.LendingDate,
                    ReturnDate  = lending.ReturnDate,
                    BookId      = lending.BookId,
                    ClientId    = lending.ClientId,
                    LibraryId   = lending.LibraryId
                };

                db.Lendings.Add(dbLending);

                var bookCopy = db.BookCopies.FirstOrDefault(
                    x => x.BookId == lending.BookId &&
                    x.LibraryId == lending.LibraryId);

                bookCopy.NumberOfCopies = bookCopy.NumberOfCopies - 1;

                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #9
0
 public ActionResult Index()
 {
     ViewData["Games"]   = Games.FindAllGames();
     ViewData["Friends"] = Friend.FindAllFriendsWithLending();
     ViewData["Lendies"] = Lending.FindLendingOpened();
     return(View());
 }
Exemple #10
0
 static void PrintLending(Lending lending)
 {
     Console.WriteLine("Requested amount: £{0}", lending.Amount);
     Console.WriteLine("Rate: {0:0.0}%", lending.Rate * 100);
     Console.WriteLine("Monthly repayment: £{0:0.00}", lending.MonthlyAmount);
     Console.WriteLine("Total repayment: £{0:0.00}", lending.TotalAmount);
 }
        public async Task <IActionResult> Edit(int id, [Bind("LendingId,Name,Date,RecordId")] Lending lending)
        {
            if (id != lending.LendingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lending);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LendingExists(lending.LendingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RecordId"] = new SelectList(_context.Records, "RecordId", "Name", lending.RecordId);
            return(View(lending));
        }
Exemple #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id_Lending,DateLending,CodeEquipment,DescriptionMantenaince,UserId,EquipmentId,UbicationId")] Lending lending)
        {
            if (id != lending.Id_Lending)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lending);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LendingExists(lending.Id_Lending))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EquipmentId"] = new SelectList(_context.Equipments, "Id_Equipment", "Equipement_Internal_Code", lending.EquipmentId);
            ViewData["UbicationId"] = new SelectList(_context.Ubications, "Id_Ubication", "UbicationName", lending.UbicationId);
            return(View(lending));
        }
        // GET: /Book/Edit/5
        public ActionResult Lend(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Book book = bookService.FindBookById(id);

            if (book == null)
            {
                return(HttpNotFound());
            }
            else
            {
                Lending lending = new Lending();
                lending.Book        = book;
                lending.UserName    = User.Identity.Name;
                lending.LendingDate = DateTime.Now;

                bookService.Lend(lending);
            }


            return(RedirectToAction("Index"));
        }
Exemple #14
0
        public Lending CastDB(LendingViewModel model)
        {
            Lending bc = new Lending();

            Com.HSJF.Infrastructure.ExtendTools.ObjectExtend.CopyTo(model, bc);
            return(bc);
        }
        public async Task <Borrower> Lend(Lending lending)
        {
            Friend friend = await _dbContext.Friends.FirstOrDefaultAsync(f => f.Id == lending.Friend);

            if (friend == null)
            {
                return(null);
            }


            List <Game> games = await _dbContext.Games.Where(g => lending.Games.Contains(g.Id)).ToListAsync();

            DateTime lendingDate = DateTime.Now;

            foreach (var game in games)
            {
                game.LendingDate = lendingDate;
                game.FriendId    = friend.Id;

                _dbContext.Entry(game).State = EntityState.Modified;
            }


            await SaveAsync();


            friend.Games = default;
            games.ForEach(game => game.Friend = default);
Exemple #16
0
        // PUT api/Lending/5
        public IHttpActionResult PutLending(int id, Lending lending)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != lending.ID)
            {
                return(BadRequest());
            }

            db.Entry(lending).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LendingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult UpdateLending(Lending lending)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Entry(lending).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LendingExists(lending.LendingID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok("Success"));
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (AccountId != null)
         {
             hashCode = hashCode * 59 + AccountId.GetHashCode();
         }
         if (BalanceUType != null)
         {
             hashCode = hashCode * 59 + BalanceUType.GetHashCode();
         }
         if (Deposit != null)
         {
             hashCode = hashCode * 59 + Deposit.GetHashCode();
         }
         if (Lending != null)
         {
             hashCode = hashCode * 59 + Lending.GetHashCode();
         }
         if (Purses != null)
         {
             hashCode = hashCode * 59 + Purses.GetHashCode();
         }
         return(hashCode);
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Lending lending = db.Lendings.Find(id);

            db.Lendings.Remove(lending);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #20
0
        public void deleteLending(Lending lending)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "EXEC delete_lending " + lending.Number;
            cmd.Connection  = dbHelper.connection;
            cmd.ExecuteNonQuery();
        }
Exemple #21
0
        public Lending ReturnLentBook(Lending lending)
        {
            var bookCopy = dbContext.BookCopies.SingleOrDefault(bc => bc.BookId == lending.BookId && bc.LibraryId == lending.LibraryId);

            bookCopy.NumberOfCopies       += 1;
            dbContext.Entry(lending).State = EntityState.Modified;

            return(lending);
        }
Exemple #22
0
 public IActionResult NuevaLending(Lending lending)
 {
     lending.DtLend  = DateTime.Now;
     ViewBag.Context = _context;
     _context.Lendings.Add(lending);
     _context.SaveChanges();
     RegistraBitacora("Lendings", "Inserción");
     return(View("ListaDeLendings", _context.Lendings.ToList()));
 }
        public async ValueTask <IObjectLending <T> > LendAsync(CancellationToken cancellationToken = default)
        {
            var lendingDisposedTaskHandle = CreateTaskHandle <Unit>();
            var lendingData = await _matchingQueue.MatchAsync(lendingDisposedTaskHandle.Task, cancellationToken).ConfigureAwait(false);

            var lending = new Lending(lendingData, lendingDisposedTaskHandle);

            return(lending);
        }
Exemple #24
0
        public IHttpActionResult GetLending(int id)
        {
            Lending lending = db.Lendings.Find(id);

            if (lending == null)
            {
                return(NotFound());
            }

            return(Ok(lending));
        }
        public void Lend_NoneObjectPassed_ReturnsBadRequestResult()
        {
            // Arrange
            Lending item = null;

            // Act
            var result = _controller.Lend(item).Result;

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
 public ActionResult Edit(Lending lending)
 {
     if (ModelState.IsValid)
     {
         Lending.UpdateLendingItem(lending);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(lending));
     }
 }
 public ActionResult Create(Lending lending)
 {
     if (ModelState.IsValid)
     {
         Lending.InsertLending(lending);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(lending));
     }
 }
Exemple #28
0
 public static newLendingDitaile GetLendingItems()
 {
     using (libraryEntities db = new libraryEntities())
     {
         Lending l = db.Lendings.ToList().Last();
         List <LendingItemDTO> s  = Converters.LendingItemConverter.ConvertLendingItemListToDTO(db.LendingItems.ToList());
         newLendingDitaile     le = new newLendingDitaile();
         le.code = l.codeLending;
         le.lendingItemsToSub = (s.Where(x => x.idSUB == l.idSubscribers && x.returnDate == null).ToList());
         return(le);
     }
 }
        public IHttpActionResult DeleteLending(Lending lending)
        {
            Lending len = db.Lendings.Find(lending.LendingID);

            if (len == null)
            {
                return(NotFound());
            }
            db.Lendings.Remove(len);
            db.SaveChanges();
            return(Ok("Success"));
        }
        public async Task <IActionResult> Create([Bind("LendingId,Name,Date,RecordId")] Lending lending)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lending);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RecordId"] = new SelectList(_context.Records, "RecordId", "Name", lending.RecordId);
            return(View(lending));
        }