Exemplo n.º 1
0
        public static List <Dock> GetAll()
        {
            var db    = new MarinaEntities();
            var docks = db.Docks.ToList();

            return(docks);
        }
Exemplo n.º 2
0
        public static Dock Find(int id)
        {
            var db   = new MarinaEntities();
            var dcks = db.Docks.SingleOrDefault(d => d.ID == id);

            return(dcks);
        }
        //Code written by Julie Tran
        //Last Modified Febuary 7 2021

        /// <summary>
        /// retrieves all Dock Name and Dock ID
        /// </summary>
        /// <returns></returns>
        public IList GetAllAsListItem()
        {
            var db       = new MarinaEntities();
            var dockName = db.Docks.Select(d => new { ID = d.ID, Name = d.Name }).ToList();

            return(dockName);
        }
        /// <summary>
        /// retrieves dock by ID
        /// </summary>
        /// <param name="dockID">dock ID</param>
        /// <returns></returns>
        public static Dock Find(int dockID)
        {
            var db   = new MarinaEntities();
            var dock = db.Docks.SingleOrDefault(d => d.ID == dockID);

            return(dock);
        }
Exemplo n.º 5
0
        public static void Add(Customer auth) //add new customer
        {
            var db = new MarinaEntities();

            db.Customers.Add(auth);
            db.SaveChanges();
        }
Exemplo n.º 6
0
        //select leased slips for the customer

        public static IList FindLeasedSlip(int customerId)
        {
            var db          = new MarinaEntities();
            var leasedSlips = db.Leases.Where(s => s.CustomerID == customerId).Select(s => new { SlipsLeased = s.SlipID }).ToList();

            return(leasedSlips);
        }
Exemplo n.º 7
0
        //add lease to db
        public static void Add(Lease lease)
        {
            var db = new MarinaEntities();

            db.Leases.Add(lease);
            db.SaveChanges();
        }
        /// <summary>
        /// find all slips that is associated to dockID
        /// </summary>
        /// <param name="dockID"> dock ID</param>
        /// <returns>a list of slips</returns>
        public static List <Slip> FindAvailableSlipByDock(int dockID)
        {
            var db             = new MarinaEntities(); //any data retrieval in .Data
            var availableSlips = db.Slips.Where(s => s.Leases.Count == 0 && s.DockID == dockID).ToList();

            return(availableSlips);
        }
        /// <summary>
        /// Find all slips that has not been leased
        /// </summary>
        /// <returns>a list of slips</returns>
        public static List <Slip> FindAvailableSlip()
        {
            var db        = new MarinaEntities();
            var availSlip = db.Slips.Where(s => s.Leases.Count == 0).ToList();

            return(availSlip);
        }
        /// <summary>
        /// This method takes user inputted login informatio and compares it against values stored in the database.
        /// If a match is found, the user is authenticated.
        /// </summary>
        /// <param name="FirstName">User inputted first name.</param>
        /// <param name="LastName">User inputted last name.</param>
        /// <param name="Phone">User inputted phone number.</param>
        /// <param name="City">User inputted city.</param>
        /// <returns>Authentication userDTO with the user's unique ID and full name.</returns>
        public static object Authenticate(string FirstName, string LastName, string Phone, string City)
        {
            userDTO dto = null;

            //Gets a reference to the database entity.
            var dbContext = new MarinaEntities();

            //Gets a reference to the object within the Customers table that matches the user specified input fields.
            var authObj = (from cust in dbContext.Customers
                           where cust.FirstName == FirstName && cust.LastName == LastName && cust.Phone == Phone && cust.City == City
                           select cust).SingleOrDefault();

            if (authObj is null)
            {
                //User is not authenticated.
            }

            else
            {
                //Sets parameters for the userDTO that will be used for authentication.
                //A direct reference to authObj might pass it by reference, so we'll create a new object.
                dto = new userDTO
                {
                    custID   = authObj.ID,
                    FullName = $"{authObj.FirstName} {authObj.LastName}"
                };
            }
            return(dto);
        }
        /// <summary>
        /// This method takes a Customer object (as defined by Entity Framework) and adds it to the DataContext.
        /// The changes are then saved to update the database with a new customer.
        /// </summary>
        /// <param name="newCust">Customer object. Can be user defined or generated from a registration control.</param>
        public static void Add(Customer newCust)
        {
            var dbContext = new MarinaEntities(); //Gets a reference to the database entity.

            dbContext.Customers.Add(newCust);     //Adds the new record to the DataContext.
            dbContext.SaveChanges();              //Saves all changes made in the DataContext to the database it is modelling.
        }
Exemplo n.º 12
0
        public static Dock FindDock(int id)
        {
            var db   = new MarinaEntities();
            var dock = db.Docks.SingleOrDefault(c => c.ID == id);

            return(dock);
        }
Exemplo n.º 13
0
        public static AuthenticationDTO AuthenticateCustomer(string username, string password)
        {
            //declare a dto object
            AuthenticationDTO dto = null;

            //creating the session to the database (called a context or DbContext)
            var db = new MarinaEntities();

            //find the authentication object based on credentials passed in
            var auth = db.Customers.
                       SingleOrDefault(a => a.FirstName == username && a.LastName == password); // pseudo login

            if (auth != null)
            {
                //authentication passed, so instantiate the dto object
                dto = new AuthenticationDTO
                {
                    Id        = auth.ID.ToString(),
                    FirstName = auth.FirstName,
                    LastName  = auth.LastName,
                    Phone     = auth.Phone,
                    City      = auth.City,
                    Username  = $"{auth.FirstName}",                      // pseudo login
                    Password  = $"{auth.LastName}"                        // pseudo login
                };
            }
            //return the dto object
            return(dto);
        }
Exemplo n.º 14
0
 // Add a newly registered customer to DB
 public static void Add(Customer cust)
 {
     using (var db = new MarinaEntities())
     {
         db.Customers.Add(cust);
         db.SaveChanges();
     }
 }
Exemplo n.º 15
0
        public static IList FindSlip(int id)
        {
            var db = new MarinaEntities();

            var availableSlips = db.Slips.Where(s => s.Leases.Count == 0 && s.DockID == id).Select(a => new { a.ID }).ToList();

            return(availableSlips);
        }
Exemplo n.º 16
0
        public IList GetAllAsListDocks()
        {
            var db    = new MarinaEntities();
            var docks = db.Docks.Select(dks => new
                                        { ID = dks.ID, Name = dks.Name }).ToList();

            return(docks);
        }
Exemplo n.º 17
0
        public static Customer Find(int custId) //find the customer if exists in db
        {
            var db   = new MarinaEntities();
            var auth = db.Customers.
                       SingleOrDefault(a => a.ID == custId);

            return(auth);
        }
Exemplo n.º 18
0
 public void LeaseSlip(Lease newLease)
 {
     using (var db = new MarinaEntities())
     {
         db.Leases.Add(newLease);
         db.SaveChanges();
     }
 }
        /// <summary>
        /// Finds all lease associated to customer that is logged in
        /// </summary>
        /// <param name="custID">customer ID</param>
        /// Code written by Julie Tran
        //Last Modified Febuary 8 2021
        public static List <Lease> Find(int custID)
        {
            var db = new MarinaEntities();

            List <Lease> leases           = db.Leases.ToList();
            var          previouslyLeased = (from pl in leases where pl.CustomerID == custID select pl).ToList();

            return(previouslyLeased);
        }
Exemplo n.º 20
0
 // find a single customer based on ID.
 public static Customer Find(int id)
 {
     using (var db = new MarinaEntities())
     {
         var cust = db.Customers.SingleOrDefault(c => c.ID == id);
         if (cust != null) // if customer is found
         {
             return(cust);
         }
         return(cust);
     }
 }
Exemplo n.º 21
0
 // update customer in db.
 public static void Update(Customer cust)
 {
     using (var db = new MarinaEntities())
     {
         var custFromContext = db.Customers
                               .SingleOrDefault(c => c.ID == cust.ID);
         custFromContext.FirstName = cust.FirstName;
         custFromContext.LastName  = cust.LastName;
         custFromContext.City      = cust.City;
         custFromContext.Phone     = cust.Phone;
         db.SaveChanges();
     }
 }
Exemplo n.º 22
0
        public static void EnrollService(LeaseDTO LeaseToDB)
        {
            var db = new MarinaEntities();

            var sc = new Lease
            {
                SlipID     = int.Parse(LeaseToDB.SlipID),
                CustomerID = int.Parse(LeaseToDB.CustomerID)
            };

            //add lease object to the context and save changes in the database
            db.Leases.Add(sc);
            db.SaveChanges();
        }
Exemplo n.º 23
0
 public List <LeaseDTO> GetLeasesByCustomer(int custID)
 {
     using (var db = new MarinaEntities())
     {
         var leases = (from l in db.Leases
                       where l.CustomerID == custID
                       select new LeaseDTO
         {
             LeaseID = l.ID,
             SlipID = l.SlipID
         }).ToList();
         return(leases);
     }
 }
Exemplo n.º 24
0
        public static List <LeaseOnBoardDTO> GetCustomerLeaseEnrollment(int id)
        {
            var db = new MarinaEntities();
            //get the list of leases registered by the customer
            var leaseList = db.Leases.Where(cs => cs.CustomerID == id).
                            Select(s => new LeaseOnBoardDTO
            {
                CustomerName = s.Customer.FirstName + " " + s.Customer.LastName,
                DockName     = s.Slip.Dock.Name.ToString(),
                SlipID       = s.SlipID.ToString()
            }).ToList();

            return(leaseList);
        }
Exemplo n.º 25
0
 public List <DockDTO> GetDocks()
 {
     // get all docks.
     using (var db = new MarinaEntities())
     {
         var docks = db.Docks.Select(d => new DockDTO
         {
             ID                = d.ID,
             Name              = d.Name,
             WaterService      = d.WaterService,
             ElectricalService = d.ElectricalService
         }).ToList();
         return(docks);
     }
 }
Exemplo n.º 26
0
        public static List <SlipDTO> GetAllSlipsByDockId(int id)
        {
            var db = new MarinaEntities();
            //get the filtered data using Where and transform to dto objects using Select
            var slips = db.Slips.
                        Where(cs => cs.DockID == id && cs.Leases.Count == 0).
                        Select(s => new SlipDTO
            {
                ID     = s.ID.ToString(),
                Width  = s.Width.ToString(),
                Length = s.Length.ToString(),
                DockID = s.DockID.ToString()
            }).ToList();

            return(slips);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Static method handles adding a new authentication object to the DB
        /// </summary>
        /// <param name="auth">The authentication object is a DTO object</param>
        public static void AddAuthentication(AuthenticationDTO auth)
        {
            //use the context to add a new authentication object
            var db = new MarinaEntities();

            //assign from dto object to the entity object
            var authFromContext = new Customer
            {
                FirstName = auth.FirstName,
                LastName  = auth.LastName,
                Phone     = auth.Phone,
                City      = auth.City
            };

            db.Customers.Add(authFromContext);
            db.SaveChanges();
        }
Exemplo n.º 28
0
        public static CustomerDTO Authenticate(string fname, string lname) //autheticate the user
        {
            CustomerDTO dto  = null;
            var         db   = new MarinaEntities();
            var         auth = db.Customers.
                               SingleOrDefault(a => a.FirstName == fname && a.LastName == lname);

            if (auth != null) // authentication passsed
            {
                dto = new CustomerDTO
                {
                    ID       = auth.ID,
                    FullName = $"{auth.FirstName} {auth.LastName}"
                };
            }
            return(dto);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Static method handles the update of an existing authentication object
        /// </summary>
        /// <param name="auth">The authentication object as a DTO</param>
        public static void UpdateAuthentication(AuthenticationDTO auth)
        {
            //use the context to update an existing record
            var id = Convert.ToInt32(auth.Id);
            var db = new MarinaEntities();

            //we need to get an authentication object from the context
            //so that we can update it with values from the dto passed in
            var authFromContext = db.Customers.SingleOrDefault(a => a.ID == id);

            authFromContext.FirstName = auth.FirstName;
            authFromContext.Phone     = auth.Phone;
            authFromContext.City      = auth.City;

            //save changes--no need to add the object back to the context as the context
            //already has it
            db.SaveChanges();
        }
Exemplo n.º 30
0
 public DockDTO GetSingleDock(int dockID)
 {
     using (var db = new MarinaEntities())
     {
         DockDTO dto  = null;
         var     dock = db.Docks.SingleOrDefault(d => d.ID == dockID);
         if (dock != null)
         {
             dto = new DockDTO
             {
                 ID                = dock.ID,
                 Name              = dock.Name,
                 WaterService      = dock.WaterService,
                 ElectricalService = dock.ElectricalService
             };
         }
         return(dto);
     }
 }