Пример #1
0
        public RentalItemDto GetRentalItemById(int id)
        {
            DVDRentalEntities db = new DVDRentalEntities();

            var ri = db.RentalItems.FirstOrDefault(x => x.ID == id);
            return new RentalItemDto { ID = ri.ID.ToString(), Name = ri.Name, Price = ri.Price.ToString(), Type = ri.Type.ToString() };
        }
Пример #2
0
        public NotificationDto GetNotificationById(int id)
        {
            DVDRentalEntities db = new DVDRentalEntities();

            var n = db.Notifications.FirstOrDefault(x => x.ID == id);
            return new NotificationDto { ID = n.ID.ToString(), Date = n.Date.ToString(), CustomerID = n.CustomerID.ToString() };
        }
Пример #3
0
 public void updateBalance(int customerID, int rentalID)
 {
     DVDRentalEntities db = new DVDRentalEntities();
      var customer = db.Users.FirstOrDefault(x => x.ID == customerID);
      customer.Balance += Convert.ToDecimal(new RentalItemBLL().GetRentalItemById(rentalID).Price);
      db.SaveChanges();
 }
Пример #4
0
 //Add notifications that use the getUserFines method in the user class.
 public void AddNotification(int cid)
 {
     var db = new DVDRentalEntities();
     var n = new Notification
     {
         Date = DateTime.Now,
         CustomerID = cid,
     };
     db.Notifications.Add(n);
     db.SaveChanges();
 }
Пример #5
0
 //Add a sale into the database.
 public void AddSales(int rid,int cid,int eid)
 {
     var db = new DVDRentalEntities();
      var s = new Sale
      {
          Date= DateTime.Now,
          RentalItemID=rid,
          CustomerID=cid,
          EmployeeID=eid,
      };
      db.Sales.Add(s);
      db.SaveChanges();
 }
Пример #6
0
 public List<NotificationDto> GetAllNotificationsByDate(string date)
 {
     DVDRentalEntities db = new DVDRentalEntities();
     List<NotificationDto> LRI = new List<NotificationDto>();
     DateTime dtstring = Convert.ToDateTime(date);
     foreach (var n in db.Notifications.Where(x => x.Date == dtstring))
     {
         LRI.Add(new NotificationDto
         {
             ID = n.ID.ToString(),
             Date = n.Date.ToString(),
             CustomerID = n.CustomerID.ToString(),
         });
     }
     return LRI;
 }
Пример #7
0
        public List<NotificationDto> GetAllNotifications()
        {
            DVDRentalEntities db = new DVDRentalEntities();
            List<NotificationDto> LRI = new List<NotificationDto>();

            foreach (var n in db.Notifications)
            {
                LRI.Add(new NotificationDto
                {
                    ID = n.ID.ToString(),
                    Date = n.Date.ToString("dd MMM yyyy H:mm"),
                    CustomerID = n.CustomerID.ToString(),
                    FName = n.User.Name + " " + n.User.Surname,
                });
            }
            return LRI;
        }
Пример #8
0
        public List<RentalItemDto> GetAllRentalItemsByType(string type)
        {
            DVDRentalEntities db = new DVDRentalEntities();
            List<RentalItemDto> LRI = new List<RentalItemDto>();

            foreach (var ri in db.RentalItems.Where( x => x.Type == type))
            {
                LRI.Add(new RentalItemDto
                {
                    ID = ri.ID.ToString(),
                    Name = ri.Name,
                    Type = ri.Type,
                    Price = ri.Price.ToString()
                });
            }
            return LRI;
        }
Пример #9
0
 public UserDto getCustomer(int id)
 {
     DVDRentalEntities db = new DVDRentalEntities();
     var c = db.Users.FirstOrDefault(x => x.Role.Equals("Customer", StringComparison.InvariantCultureIgnoreCase) && x.ID == id);
     var customer = new UserDto()
     {
         Name = c.Name,
         Surname = c.Surname,
         IDNumber = c.IDNumber,
         Address = c.Address,
         ContactNumber = c.ContactNumber,
         Email = c.Email,
         Balance = c.Balance.ToString(),
         Fine = c.Fine.ToString(),
         Username = c.Username
     };
     return customer;
 }
Пример #10
0
        public void AddUser(string name, string surname, string idnumber, string address, string contactNumber, string email, string role, string username, string password)
        {
            DVDRentalEntities db = new DVDRentalEntities();
            string hashPass = new HashBLL().CreateHash(password);
            User u = new User
            {
                Name = name,
                Surname = surname,
                IDNumber = idnumber,
                Address = address,
                ContactNumber = contactNumber,
                Email = email,
                Role = role,
                Username = username,
                Password = hashPass
            };

            db.Users.Add(u);
            db.SaveChanges();
        }
Пример #11
0
 public List<UserDto> getAllClerks()
 {
     DVDRentalEntities db = new DVDRentalEntities();
     var customers = db.Users.Where(x => x.Role.Equals(x.Role.Equals("Clerk", StringComparison.InvariantCultureIgnoreCase)));
     List<UserDto> LU = new List<UserDto>();
     foreach (var c in customers)
     {
         LU.Add(new UserDto
         {
             Name = c.Name,
             Surname = c.Surname,
             IDNumber = c.IDNumber,
             Address = c.Address,
             ContactNumber = c.ContactNumber,
             Email = c.Email,
             Balance = c.Balance.ToString(),
             Fine = c.Fine.ToString(),
             Username = c.Username
         });
     }
     return LU;
 }
Пример #12
0
        //Get user fines for sending notifications page.Fines with a balance more then 0
        public List<UserDto> getUserFines()
        {
            DVDRentalEntities db = new DVDRentalEntities();
            var fines = db.Users.Where(x => x.Fine > 0);
            List<UserDto> FU = new List<UserDto>();

            foreach (var f in fines)
            {
                FU.Add(new UserDto
                {
                    ID=f.ID.ToString(),
                    Name = f.Name,
                    Surname = f.Surname,
                    IDNumber = f.IDNumber,
                    Address = f.Address,
                    ContactNumber = f.ContactNumber,
                    Email = f.Email,
                    Balance=f.Balance.ToString(),
                    Fine = f.Fine.ToString(),
                });
            }
            return FU;
        }
Пример #13
0
 public UserDto getUserCredentials(string username)
 {
     DVDRentalEntities db = new DVDRentalEntities();
     var u = db.Users.FirstOrDefault(x => x.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
     if (u != null)
     {
         return new UserDto()
         {
             ID = u.ID.ToString(),
             Username = u.Username,
             Password = u.Password,
             Role = u.Role
         };
     }
     else
         return null;
 }