Ejemplo n.º 1
0
        public async Task <IActionResult> ShareLockPost([FromRoute][Required] int lockId, [FromHeader][Required()] string token, [FromBody] Share body)
        {
            await Db.Connection.OpenAsync();

            AuthenticationHandler auth = new AuthenticationHandler(Db);
            var authToken = auth.CheckAuth(token);

            if (authToken.Result != null)
            {
                if (await auth.CheckLockOwner(lockId, authToken.Result.Id) == true)
                {
                    UserQuerry helper = new UserQuerry(Db);
                    // helper.
                    // Setup stuf to create the new rented
                    Rented rLock = new Rented(Db);
                    rLock.LockId    = lockId;
                    rLock.StartDate = body.StartDate;
                    rLock.EndDate   = body.EndDate;
                    rLock.UserId    = helper.GetUserByUsername(body.Username).Result.Id;

                    await rLock.InsertAsync();

                    Db.Dispose();
                    return(new OkObjectResult("Access Granted"));
                }

                Db.Dispose();
                return(new UnauthorizedResult());
            }
            Db.Dispose();
            return(new UnauthorizedResult());
        }
Ejemplo n.º 2
0
        public bool RentedBook(string JmbgUser, Rented rented)
        {
            List <User> usersRenting = null;
            int         br           = 0;

            foreach (var renter in GetAllBookRentedUsers())
            {
                usersRenting = renter.Item2.ToList();
            }

            foreach (var temp in usersRenting)
            {
                if (temp.JmbgUser.Equals(JmbgUser))
                {
                    br++;
                }
                if (br == 2)
                {
                    return(false);
                }
            }
            if (iBR.RentedBook(JmbgUser, rented))
            {
                return(iBR.DecrementQuantity(rented));
            }
            return(false);
        }
Ejemplo n.º 3
0
        public ActionResult RentBooks(RentBooksModel model)
        {
            Rented NewRented = new Rented();

            using (var d = new UserContext())
            {
                NewRented.UserProfile = d.UserProfiles.Find((int)WebSecurity.CurrentUserId);
                NewRented.Book        = d.Books.Find(model.NewRented.BookKey);
                NewRented.returned    = true;
                Rented comp = d.Rented.Where(x => x.UserProfile.UserId == (int)WebSecurity.CurrentUserId)
                              .Where(x => x.Book.BookKey == model.NewRented.BookKey)
                              .FirstOrDefault();
                if (comp == null)
                {
                    NewRented.returned = false;
                    d.Rented.Add(NewRented);
                }
                else
                {
                    comp.returned = false;
                }
                d.SaveChanges();
                addHistory(NewRented.UserProfile, NewRented.Book, (States)1);
            }
            return(RentBooks());
        }
Ejemplo n.º 4
0
            public override T[] Rent(int minimumLength)
            {
                var array = new T[minimumLength];

                Rented.Add(array);
                return(array);
            }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutRented(int id, Rented rented)
        {
            if (id != rented.Id)
            {
                return(BadRequest());
            }

            _context.Entry(rented).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentedExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        private void buttonIssue_Click(object sender, EventArgs e)
        {
            int row1 = dataGridViewUser.SelectedRows[0].Index;
            int row2 = dataGridViewBooks.SelectedRows[0].Index;

            string Jmbg = dataGridViewUser[0, row1].Value.ToString();

            Rented rented = new Rented();

            rented.IdBook = int.Parse(dataGridViewBooks[0, row2].Value.ToString());
            rented.Title  = dataGridViewBooks[1, row2].Value.ToString();

            rented.NameAuthor = dataGridViewBooks[3, row2].Value.ToString();

            rented.DateOfIssue = DateTime.Parse(dateTimePickerDateOfIssue.Value.ToString());

            rented.ReturnDate = DateTime.Parse(dateTimePickerReturnBooks.Value.ToString());



            if (this.bookBusiness.RentedBook(Jmbg, rented) == true)
            {
                MessageBox.Show("successfully");
                LoadTableBooks();
                LoadTableUser();
                SetTextBox();
            }
            else
            {
                MessageBox.Show("error");
            }
        }
 public bool RentedBook(string JmbgUser, Rented rented)
 {
     if (Quantity(rented) > 0)
     {
         string query = string.Format("INSERT INTO Rented VALUES('{0}',{1},'{2:u}','{3:u}')",
                                      JmbgUser, rented.IdBook, rented.DateOfIssue, rented.ReturnDate);
         return(BaseConnection.ExecuteNonQuerySqlCommand(query));
     }
     return(false);
 }
Ejemplo n.º 8
0
 public bool ApplyRent(Rent rent)
 {
     if (isValid(rent))
     {
         apply(rent);
         Rented?.Invoke(this, getRentedMessage());
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 public ActionResult ReturnBooks(ReturnBooksModel model)
 {
     using (var d = new UserContext())
     {
         Rented r = d.Rented.Where(x => x.UserProfile.UserId == model.NewReturned.UserId)
                    .Where(x => x.Book.BookKey == model.NewReturned.BookKey)
                    .FirstOrDefault();
         r.returned = true;
         d.SaveChanges();
         addHistory(r.UserProfile, r.Book, (States)2);
         return(ReturnBooks());
     }
 }
Ejemplo n.º 10
0
 public string[] ToArray()
 {
     return(new string[]
     {
         Customer,
         Title,
         Genre,
         Rented.ToString(),
         Returned == DateTime.MinValue ? String.Empty : Returned.ToString(),
         Cost.ToString(),
         BookingId.ToString(),
         CustomerId.ToString()
     });
 }
Ejemplo n.º 11
0
 public string[] ToArray()
 {
     return(new string[]
     {
         BookingId.ToString(),
         RegistrationNumber,
         VehicleType,
         Customer,
         Cost.ToString(),
         Rented.ToString(),
         Returned == DateTime.MinValue ?
         String.Empty : Returned.ToString()
     });
 }
Ejemplo n.º 12
0
        public async Task <ActionResult <Rented> > PostRented(Rented rented)
        {
            var amountRented = (from a in _context.Rented
                                select rented.movie).Count();

            if (amountRented < rented.movie.Stock)
            {
                _context.Rented.Add(rented);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetRented", new { id = rented.Id }, rented));
            }
            else
            {
                return(NoContent());
            }
        }
Ejemplo n.º 13
0
        public List <Tuple <List <Rented>, List <User> > > GetAllBookRentedUsers()
        {
            List <Rented> listBooksRented = new List <Rented>();
            List <User>   listUsers       = new List <User>();

            var listtuple = new List <Tuple <List <Rented>, List <User> > >();

            string query = "SELECT u.JMBGUser, u.Name, u.Surname,b.IdBook, b.Title,b.NameAuthor,b.Quantity ,CONVERT(DATE,r.DateOfIssue),CONVERT(DATE,r.ReturnDate)" +
                           " FROM Users u  INNER JOIN Rented r" +
                           " ON(u.JMBGUser = r.JMBGUser)" +
                           " INNER JOIN Books b ON b.IdBook = r.IdBook";


            using (SqlCommand sqlCommand = BaseConnection.GetSqlCommand(query))
            {
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        User   user   = new User();
                        Rented rented = new Rented();

                        user.JmbgUser      = sqlDataReader.GetString(0);
                        user.Name          = sqlDataReader.GetString(1);
                        user.Surname       = sqlDataReader.GetString(2);
                        rented.IdBook      = sqlDataReader.GetInt32(3);
                        rented.Title       = sqlDataReader.GetString(4);
                        rented.NameAuthor  = sqlDataReader.GetString(5);
                        rented.Quantity    = sqlDataReader.GetInt32(6);
                        rented.DateOfIssue = sqlDataReader.GetDateTime(7);
                        rented.ReturnDate  = sqlDataReader.GetDateTime(8);

                        listBooksRented.Add(rented);
                        listUsers.Add(user);
                    }
                }
            }
            var t = Tuple.Create(listBooksRented, listUsers);

            listtuple.Add(t);

            return(listtuple);
        }
Ejemplo n.º 14
0
        public void ReturnVehicle(IVehicle vehicle)
        {
            //// Record information:
            Returned         = DateTime.Now;
            OdometerReturned = vehicle.Odometer;

            // Calculate cost for time:
            int days = Rented.Duration(Returned);

            Cost = days * vehicle.CostDay;

            // Calculate cost for distance:
            double distance = OdometerReturned - OdometerRented;

            Cost += vehicle.CostKm * distance;

            // Make the vehicle available to rent again:
            vehicle.Status = VehicleStatuses.Available;
        }
Ejemplo n.º 15
0
        public async Task <Boolean> CheckLockUser(int lockId, int userId)
        {
            //check if user is owner
            LockQuerry lockQuerry = new LockQuerry(Db);
            Lock       lockOwned  = await lockQuerry.FindLocksByLockIdAsync(lockId);

            if (lockOwned.OwnerId == userId)
            {
                return(true);
            }

            //if not, check if user rented
            RentedQuerry rented = new RentedQuerry(Db);
            Rented       rent   = await rented.FindOneByLockUser(lockId, userId);

            if (rent != null)
            {
                return(true);
            }

            //if not, return false
            return(false);
        }
Ejemplo n.º 16
0
 public IHttpActionResult Save(NewRentalDto newRentalDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     foreach (var item in newRentalDto.MovieIds)
     {
         var movie = _context.Movies.SingleOrDefault(x => x.Id == item);
         if (movie.AvailableStock <= 0)
         {
             return(BadRequest());
         }
         movie.AvailableStock--;
         var rented = new Rented {
             CustomerId = newRentalDto.CustomerId,
             MovieId    = item,
             DateRented = DateTime.Today,
         };
         _context.Renteds.Add(rented);
     }
     _context.SaveChanges();
     return(Ok());
 }
        private void btnPayInvoice_Click(object sender, EventArgs e)
        {
            var customer = ddlCustomer.SelectedItem.DataBoundItem as Customer;

            if (customer == null)
            {
                MessageBox.Show("Please select a Customer to Rent!");
                return;
            }
            if (rentItemList.Count <= 0)
            {
                MessageBox.Show("Please add a product in Cart!");
                return;
            }

            try
            {
                using (var scope = _App.VgmsDb.Database.BeginTransaction())
                {
                    if (invoice == null)
                    {
                        invoice = new Invoice();
                    }

                    invoice.TotalItem         = totalInvoiceItem;
                    invoice.TotalSellingPrice = (float)totalInvoicePrice;
                    invoice.InRent            = true;
                    invoice.CreateById        = _App.CurrentUser.Id;
                    invoice.CreateDate        = DateTime.Now;
                    invoice.UpdateById        = _App.CurrentUser.Id;
                    invoice.UpdateDate        = DateTime.Now;
                    _App.VgmsDb.Invoice.Add(invoice);
                    _App.VgmsDb.SaveChanges();
                    var totalBuyPrice = 0.00;
                    foreach (var item in rentItemList)
                    {
                        var product = _App.VgmsDb.Product.SingleOrDefault(x => x.Id == item.Id);
                        if (product != null)
                        {
                            Rented rent = new Rented();
                            rent.CustomerId = customer.Id;
                            rent.InvoiceId  = invoice.Id;
                            rent.ProductId  = item.Id;
                            rent.Quantity   = item.Quantity;
                            rent.RentAmount = (float)item.Unit_Price;
                            //rent.TotalPrice = (float)item.Total_Price;
                            rent.RentDate   = DateTime.Now;
                            rent.ReturnDate = DateTime.Now.AddDays(product.AllowedRentDays);

                            _App.VgmsDb.Rented.Add(rent);
                            totalBuyPrice       += item.Quantity * product.BuyPrice;
                            product.TotalRented += item.Quantity;
                        }
                    }

                    _App.VgmsDb.SaveChanges();
                    scope.Commit();
                    NewInvoice();
                }


                //open a billing form pass invoice id
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error!" + ex.GetBaseException());
            }
        }
Ejemplo n.º 18
0
 protected virtual void OnRented(EventArgs e)
 {
     Rented?.Invoke(this, e);
 }
Ejemplo n.º 19
0
 public override void Return(T[] array, bool clearArray = false)
 {
     Rented.Remove(array);
 }