Esempio n. 1
0
        public Employees CreateEmployee(string email, string name, string role, int salary)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(email));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(name));
            }

            if (string.IsNullOrWhiteSpace(role))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(role));
            }

            if (salary < 0)
            {
                throw new ArgumentException("The parameter cannot be negative or empty.", nameof(salary));
            }

            var d = new CreateEmployeeDataDelegate(email, name, role, salary);

            return(executor.ExecuteNonQuery(d));
        }
        /// <summary>
        /// Add the customer to database if valid inputs when the user clicks "Add Customer" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddCustomer_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string name   = Check.FormatName(uxFirstName.Text) + " " + Check.FormatName(uxLastName.Text);
                float  budget = float.Parse(uxBudget.Text);
                int    age    = int.Parse(uxAge.Text);
                string sex    = (bool)uxMale.IsChecked ? "Male" : "Female";

                string address = uxAddress.Text + "\n" + Check.FormatName(uxCity.Text) + ", " + uxZipcode.Text;
                string phone   = uxAreaCode.Text + uxFirst3PhoneDigits.Text + uxLast4PhoneDigits.Text;
                string email   = uxEmail.Text;

                string city    = Check.FormatName(uxCity.Text);
                string region  = Check.FormatName(uxRegion.Text);
                string country = Check.FormatName(uxCountry.Text);

                // CONNNECT
                SqlCommandExecutor      executor = new SqlCommandExecutor(connectionString);
                LocationGetCityDelegate getCity  = new LocationGetCityDelegate(city, country, region);
                int cityID = 0;

                // Lookup city using city, region, country
                // if city == null
                //      create city
                //      cityID = newly created city
                // else
                //      cityID = found city
                City c = executor.ExecuteReader(getCity);
                if (c == null)
                {
                    LocationCreateCityDelegate createsCity = new LocationCreateCityDelegate(city, region, country);
                    c      = executor.ExecuteNonQuery(createsCity);
                    cityID = c.CityID;
                }
                else
                {
                    cityID = c.CityID;
                }
                // CONNECT
                int contactID  = 0;
                int customerID = 0;
                // Create new contact info using address, phone, email, cityID
                AgencyCreateContactInfoDelegate saveInfo = new AgencyCreateContactInfoDelegate(address, phone, email, cityID);
                // contactID = newly created contact
                ContactInfo contactId = (ContactInfo)executor.ExecuteNonQuery(saveInfo);
                // CONNECT
                contactID = contactId.ContactID;
                AgencyCreateCustomerDelegate cd = new AgencyCreateCustomerDelegate(name, budget, age, sex, contactID);
                // Create new customer using budget, name, age, sex, contactID
                // customerID = newly created customer
                Customer customer = executor.ExecuteNonQuery(cd);
                customerID = customer.CustomerID;
                MessageBox.Show("Customer " + name + " has been successfully added. CustomerID = " + customerID);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a MenuItem into the database
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="description">Description</param>
        /// <param name="price">Price</param>
        /// <param name="ingredients">List of Ingredients of the MenuItems</param>
        /// <returns></returns>
        public MenuItem AddMenuItem(string name, string description, decimal price, IReadOnlyList <Ingredient> ingredients)
        {
            MenuItem mi = executor.ExecuteNonQuery(new AddMenuItemDelegate(name, description, price));

            foreach (Ingredient i in ingredients)
            {
                executor.ExecuteNonQuery(new AddMenuItemIngredientDelegate(mi.Name, i.Name, i.AmountUsed));
            }

            return(mi);
        }
Esempio n. 4
0
        public void CreateTeam(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(name));
            }

            var d = new CreateTeamDataDelegate(name);

            executor.ExecuteNonQuery(d);
        }
Esempio n. 5
0
        /// <summary>
        /// If valid inputs, adds a hotel reservation to the trip when the user clicks "Add Reservation" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddReservation_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string hotelName = Check.FormatName(uxHotelName.Text);
                string address   = uxHotelAddress.Text;

                string country  = Check.FormatName(uxCountry.Text);
                string region   = Check.FormatName(uxRegion.Text);
                string cityname = Check.FormatName(uxCity.Text);

                double   roomPrice   = double.Parse(uxRoomPrice.Text);
                DateTime checkInDate = (DateTime)uxCheckinDate.SelectedDate;

                int cityID = 0;
                SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                //Lookup city
                City citysearch = executor.ExecuteReader(new LocationGetCityDelegate(cityname, country, region));

                //If city does not exist, add city
                if (citysearch == null)
                {
                    City city = executor.ExecuteNonQuery(new LocationCreateCityDelegate(cityname, region, country));
                    cityID = city.CityID;
                }
                else
                {
                    cityID = citysearch.CityID;
                }

                int hotelID = 0;

                //Lookup hotel
                Hotel hotelsearch = executor.ExecuteReader(new HotelsFetchHotelDelegate(hotelName, cityID, address));

                //If hotel does not exist, add hotel
                if (hotelsearch == null)
                {
                    Hotel hotel = executor.ExecuteNonQuery(new HotelsCreateHotelDelegate(hotelName, cityID, address));
                    hotelID = hotel.HotelID;
                }
                else
                {
                    hotelID = hotelsearch.HotelID;
                }

                //Add hotel reservation
                HotelReservation hr = executor.ExecuteNonQuery(new HotelsCreateHotelReservationDelegate(tripID, hotelID, checkInDate, roomPrice));

                MessageBox.Show("Reservation at " + hotelName + " successfully added");
            }
        }
        /// <summary>
        /// If valid inputs, make new attraction ticket when the user clicks "Add Ticket" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddTicket_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string   attractionName = Check.FormatName(uxAttractionName.Text);
                float    ticketPrice    = float.Parse(uxTicketPrice.Text);
                DateTime ticketDate     = (DateTime)uxDate.SelectedDate;

                string country  = Check.FormatName(uxCountry.Text);
                string region   = Check.FormatName(uxRegion.Text);
                string cityName = Check.FormatName(uxCity.Text);

                int cityID = 0;

                SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                //Lookup city
                City city = executor.ExecuteReader(new LocationGetCityDelegate(cityName, country, region));

                //If city does not exist, add
                if (city == null)
                {
                    city   = executor.ExecuteNonQuery(new LocationCreateCityDelegate(cityName, region, country));
                    cityID = city.CityID;
                }
                else
                {
                    cityID = city.CityID;
                }

                int attractionID = 0;

                //Lookup attraction
                Attraction attraction = executor.ExecuteReader(new GetAttractionByNameDelegate(attractionName, cityID));

                //If attraction does not exist, add
                if (attraction == null)
                {
                    attraction   = executor.ExecuteNonQuery(new CreateAttractionDelegate(attractionName, cityID));
                    attractionID = attraction.AttractionID;
                }
                else
                {
                    attractionID = attraction.AttractionID;
                }

                //Add a new attraction ticket
                AttractionTicket at = executor.ExecuteNonQuery(new CreateAttractionTicketDelegate(tripID, attractionID, ticketDate, ticketPrice));

                MessageBox.Show("Attraction ticket successfully added for attraction " + attractionName);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// If valid inputs, create new car rental reservation when the user clicks "Add Reservation" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddReservation_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string   carAgencyName = Check.FormatName(uxCarRentalAgencyName.Text);
                string   carModel      = Check.FormatName(uxCarModel.Text);
                float    rentalPrice   = float.Parse(uxRentalPrice.Text);
                DateTime rentalDate    = (DateTime)uxRentalDate.SelectedDate;

                string cityName = Check.FormatName(uxCity.Text);
                string country  = Check.FormatName(uxCountry.Text);
                string region   = Check.FormatName(uxRegion.Text);

                int cityID = 0;
                SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                //Lookup city
                City city = executor.ExecuteReader(new LocationGetCityDelegate(cityName, country, region));

                //If city does not exist, add
                if (city == null)
                {
                    city   = executor.ExecuteNonQuery(new LocationCreateCityDelegate(cityName, region, country));
                    cityID = city.CityID;
                }
                else
                {
                    cityID = city.CityID;
                }
                int carRentalID = 0;

                //Lookup car rental agency
                CarRental agency = executor.ExecuteReader(new CarsGetAgencyByNameDelegate(carAgencyName, cityID));

                //If agency does not exist, add
                if (agency == null)
                {
                    agency      = executor.ExecuteNonQuery(new CarsCreateCarRentalDelegate(carAgencyName, cityID));
                    carRentalID = agency.CarRentalID;
                }
                else
                {
                    carRentalID = agency.CarRentalID;
                }

                //Add new car rental reservation
                CarRentalReservation carRentalReservation = executor.ExecuteNonQuery(new CarsCreateCarRentalReservationDelegate
                                                                                         (tripID, carRentalID, rentalDate, carModel, rentalPrice));

                MessageBox.Show("Car successfully reserved with agency " + carAgencyName);
            }
        }
        private void DispatchCommands()
        {
            if (!_isLive || Interlocked.CompareExchange(ref _isDispatching, 1, 0) != 0)
            {
                return;
            }

            var candidates = Enumerable.Repeat(new { Id = default(Guid), CausationId = default(Guid) }, 0).ToList();

            using (var reader = _queryExecutor.ExecuteReader(TSql.QueryStatement(@"SELECT [Id], [CausationId] FROM [ApprovalProcess] WHERE [DispatchAcknowledged] = 0 AND ([Dispatched] IS NULL OR [Dispatched] < DATEADD(MINUTE, -5, GETDATE()))")))
            {
                candidates = reader.Cast <IDataRecord>()
                             .Select(record => new { Id = record.GetGuid(0), CausationId = record.GetGuid(1) })
                             .ToList();
            }

            foreach (var candidate in candidates)
            {
                var newCausationId = ApprovalProcessorConstants.DeterministicGuid.Create(candidate.CausationId);

                _bus.Publish(new MarkApprovalAccepted
                {
                    Id = candidate.Id,
                    ReferenceNumber = GuidEncoder.Encode(candidate.CausationId)
                }, context => context.SetHeader(Constants.CausationIdKey, newCausationId.ToString()));

                _queryExecutor.ExecuteNonQuery(TSql.NonQueryStatement(@"UPDATE [ApprovalProcess] SET [Dispatched] = GETDATE() WHERE [Id] = @P1", new { P1 = TSql.UniqueIdentifier(candidate.Id) }));
            }

            Interlocked.Exchange(ref _isDispatching, 0);
        }
        public DailyMetrics CreateDailyMetrics(string Date, double Weight, double SleepDuration, double Calories)
        {
            if (string.IsNullOrWhiteSpace(Date))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Date));
            }

            if (Weight == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Weight));
            }

            if (SleepDuration == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(SleepDuration));
            }

            if (Calories == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Calories));
            }

            var d = new CreateDailyMetricsDataDelegate(Date, Weight, SleepDuration, Calories);

            return(executor.ExecuteNonQuery(d));
        }
        /// <summary>
        /// Deletes the selected trip when the user clicks "Delete Trip" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void DeleteTrip_Click(object sender, RoutedEventArgs args)
        {
            if (uxTrips.SelectedItem != null)
            {
                if (uxTrips.SelectedItem is TextBlock t)
                {
                    int tripID;
                    tripID = int.Parse(t.Text.Split(' ')[0].Trim());

                    SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                    //Find trip
                    Trip trip = executor.ExecuteReader(new AgencyFetchTripDelegate(tripID));
                    //Set isDeleted value for trip to 1
                    executor.ExecuteNonQuery(new AgencySaveTripDelegate(trip.TripID, trip.CustomerID, 1, trip.DateCreated, trip.AgentID));

                    uxTrips.Items.Remove(uxTrips.SelectedItem);
                    RefreshTripList();
                    MessageBox.Show("Trip " + tripID + " has been removed");
                }
                else
                {
                    MessageBox.Show("Can't access selected item");
                }
            }
            else
            {
                MessageBox.Show("Please select a trip to delete");
            }
        }
Esempio n. 11
0
        public Member CreateMember(int libraryId, string firstName, string lastName, string email, string phone)
        {
            if (firstName == null)
            {
                throw new ArgumentNullException(nameof(firstName));
            }

            if (lastName == null)
            {
                throw new ArgumentNullException(nameof(lastName));
            }

            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }

            if (phone == null)
            {
                throw new ArgumentNullException(nameof(phone));
            }

            var d = new CreateMemberDataDelegate(libraryId, firstName, lastName, email, phone);

            return(executor.ExecuteNonQuery(d)); //prodecure has OUTPUT parameters
        }
Esempio n. 12
0
        public void CreateTrainingRun(int runnerId, DateTime date, int distance, int time, int averageHeartRate = 0, int isArchived = 0)
        {
            if (string.IsNullOrWhiteSpace(runnerId.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(runnerId));
            }

            if (string.IsNullOrWhiteSpace(date.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(date));
            }

            if (string.IsNullOrWhiteSpace(distance.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(distance));
            }

            if (string.IsNullOrWhiteSpace(time.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(time));
            }

            var d = new CreateTrainingRunDataDelegate(date, distance, time, averageHeartRate, isArchived);

            executor.ExecuteNonQuery(d);
        }
Esempio n. 13
0
        private IEnumerable <object> ScopedHandle(Envelope <MessageContext, object> mainEnvelope)
        {
            var tenantId = mainEnvelope.Header.MetadataLookup["tenantId"].First() as string;

            if (tenantId == null)
            {
                return new[] { new NotHandled(mainEnvelope) }
            }
            ;

            var scopedDispatcher = new Dispatcher();

            scopedDispatcher.Register <WriteToStream>(writeToStream =>
            {
                var envelope = Envelope.Create(mainEnvelope.Header, writeToStream);
                Task.WhenAll(EventStoreHandlers.WriteAsync(envelope, _eventStoreConnection)).Wait();
                return(Enumerable.Empty <object>());
            });

            scopedDispatcher.Register <Envelope <MessageContext, ItemPurchased> >(envelope =>
            {
                var eventId = EventId.Create(mainEnvelope.Header.EventId);
                return(InventoryProjectionHandlers.Project(envelope.Body, eventId, envelope.Header.StreamContext.EventNumber));
            });

            var connectionSettingsFactory = new MultitenantSqlConnectionSettingsFactory(tenantId);
            var connectionStringSettings  = connectionSettingsFactory.GetSettings("Projections");
            var connectionString          = connectionStringSettings.ConnectionString;

            _hasInitialized.GetOrAdd(tenantId, _ =>
            {
                var executor = new SqlCommandExecutor(connectionStringSettings);
                executor.ExecuteNonQuery(InventoryProjectionHandlers.CreateSchema());
                return(Nothing.Value);
            });

            var sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            using (sqlConnection)
                using (var transaction = sqlConnection.BeginTransaction())
                {
                    var sqlExecutor = new ConnectedTransactionalSqlCommandExecutor(transaction);

                    scopedDispatcher.Register <SqlNonQueryCommand>(command =>
                    {
                        sqlExecutor.ExecuteNonQuery(command);
                        return(Enumerable.Empty <object>());
                    });

                    var typedMainEnvelope = Envelope.CreateGeneric(mainEnvelope.Header, mainEnvelope.Body);
                    var unhandled         = scopedDispatcher.DispatchExhaustive(typedMainEnvelope);

                    transaction.Commit();

                    return(unhandled);
                }
        }
        /// <summary>
        /// If valid inputs, create a new restaurant reservation when the user clicks "Add Reservation" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddReservation_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string   restaurantName  = Check.FormatName(uxRestaurantName.Text);
                DateTime reservationTime = new DateTime(((DateTime)uxReservationDate.SelectedDate).Year,
                                                        ((DateTime)uxReservationDate.SelectedDate).Month, ((DateTime)uxReservationDate.SelectedDate).Day,
                                                        int.Parse(uxReservationTime.Text.Split(':')[0]), int.Parse(uxReservationTime.Text.Split(':')[1]), 0);

                string cityName = Check.FormatName(uxCity.Text);
                string country  = Check.FormatName(uxCountry.Text);
                string region   = Check.FormatName(uxRegion.Text);

                SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                int cityID = 0;

                //Lookup city
                City city = executor.ExecuteReader(new LocationGetCityDelegate(cityName, country, region));

                //If city does not exist, add
                if (city == null)
                {
                    city = executor.ExecuteNonQuery(new LocationCreateCityDelegate(cityName, region, country));
                }
                cityID = city.CityID;

                int restaurantID = 0;

                //Lookup restaurant
                Restaurant restaurant = executor.ExecuteReader(new RestaurantsGetResturantByNameDelegate(restaurantName, cityID));

                //If restaurant does not exist, add
                if (restaurant == null)
                {
                    restaurant = executor.ExecuteNonQuery(new RestaurantsCreateRestaurantDelegate(cityID, cityName));
                }
                restaurantID = restaurant.RestaurantID;

                //Add new restaurant reservation
                RestaurantReservation restaurantReservation =
                    executor.ExecuteNonQuery(new RestaurantsCreateRestaurantReservationDelegate(tripID, restaurantID, reservationTime));

                MessageBox.Show("Reservation successfully added for " + restaurantName);
            }
        }
Esempio n. 15
0
        public Product CreateProduct(string sku, string productname,
                                     int producttypeId, int quantity, string description, string price, string rating)
        {
            if (string.IsNullOrWhiteSpace(sku))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(sku));
            }

            if (string.IsNullOrWhiteSpace(productname))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(productname));
            }

            if (producttypeId < 0)
            {
                throw new ArgumentException("The parameter cannot be negative or empty.", nameof(producttypeId));
            }

            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(description));
            }

            if (string.IsNullOrWhiteSpace(rating))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(rating));
            }

            if (string.IsNullOrWhiteSpace(price))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(price));
            }

            if (quantity < 0)
            {
                throw new ArgumentException("The parameter cannot be negative or empty.", nameof(quantity));
            }

            var d = new CreateProductDataDelegate(sku, productname, producttypeId, quantity, description, price, rating);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 16
0
        public Shipment CreateShipment(DateTimeOffset shipmentdate, string shipmentaddress)
        {
            if (string.IsNullOrWhiteSpace(shipmentaddress))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(shipmentaddress));
            }

            var d = new CreateShipmentDataDelegate(shipmentdate, shipmentaddress);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 17
0
        public void UpdateOrder(int orderid, int memberid, int employeeid, int shipmentid, DateTimeOffset orderdate, string shipmentaddress)
        {
            if (shipmentaddress == null)
            {
                throw new ArgumentNullException(nameof(shipmentaddress));
            }

            var d = new UpdateOrderDataDelegate(orderid, memberid, employeeid, shipmentid, orderdate, shipmentaddress);

            executor.ExecuteNonQuery(d);
        }
Esempio n. 18
0
        public Member CreateMember(string email, string firstName, string lastName, string phone, string billingAddress, int points, DateTimeOffset joinedOn, DateTimeOffset birthDate, string status)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(email));
            }

            if (string.IsNullOrWhiteSpace(firstName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(firstName));
            }

            if (string.IsNullOrWhiteSpace(lastName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(lastName));
            }

            if (string.IsNullOrWhiteSpace(phone))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(phone));
            }

            if (string.IsNullOrEmpty(billingAddress))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(billingAddress));
            }

            if (points < 0)
            {
                throw new ArgumentException("The parameter cannot be negative or empty.", nameof(points));
            }

            if (string.IsNullOrWhiteSpace(status))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(status));
            }

            var d = new CreateMemberDataDelegate(email, firstName, lastName, phone, billingAddress, points, joinedOn, birthDate, status);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 19
0
        public Location CreateLocation(string Name)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Name));
            }


            var d = new CreateLocationDataDelegate(Name);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 20
0
        public void CreateRace(int locationId, DateTime dateTime, int distance, int isArchived = 0)
        {
            if (string.IsNullOrWhiteSpace(locationId.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(locationId));
            }

            if (string.IsNullOrWhiteSpace(dateTime.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(dateTime));
            }

            if (string.IsNullOrWhiteSpace(distance.ToString()))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(distance));
            }

            var d = new CreateRaceDataDelegate(locationId, dateTime, distance, isArchived);

            executor.ExecuteNonQuery(d);
        }
        public Repair CreateRepair(string repName, string laborCost, string status)
        {
            if (repName == null)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(repName));
            }
            if (laborCost == null)
            {
                throw new ArgumentException("The parameter cannot be negative", nameof(laborCost));
            }
            if (repName == null)
            {
                throw new ArgumentException("The parameter cannot be negative", nameof(repName));
            }
            if (status == null)
            {
                throw new ArgumentException("The parameter cannot be negative", nameof(status));
            }
            var d = new CreateRepairDataDelegate(repName, laborCost, status);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 22
0
 /// <summary>
 /// Adds a waiter into the database
 /// </summary>
 /// <param name="FirstName">Waiter's first name</param>
 /// <param name="LastName">Waiter's last name</param>
 /// <param name="Salary">Waiter's salary or hourly pay</param>
 /// <returns>Waiter's information</returns>
 public Waiter AddWaiter(string FirstName, string LastName, decimal Salary)
 {
     if (FirstName.Length == 0)
     {
         throw new ArgumentException("Empty first Name");
     }
     if (LastName.Length == 0)
     {
         throw new ArgumentException("Empty last name");
     }
     return(executor.ExecuteNonQuery(new AddWaiterDelegate(FirstName, LastName, Salary)));
 }
Esempio n. 23
0
        /// <summary>
        /// Creates a new movie in the database.
        /// </summary>
        /// <param name="movieId">Identifier of the movie.</param>
        /// <param name="movieName">Name of the movie.</param>
        /// <param name="rating">MPAA Rating of the movie.</param>
        /// <param name="runTime">Run time of the movie in minutes.</param>
        /// <param name="releaseDate">Date the movie is released.</param>
        /// <returns>The resulting instance of Movie.</returns>
        public Movie CreateMovie(string movieName, string rating, int runTime, DateTime releaseDate, string directorFirst, string directorLast, double directorSalary)
        {
            if (string.IsNullOrWhiteSpace(movieName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(movieName));
            }

            if (string.IsNullOrWhiteSpace(rating))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(rating));
            }

            if (runTime == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(runTime));
            }

            if (string.IsNullOrWhiteSpace(directorFirst))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(directorFirst));
            }

            if (string.IsNullOrWhiteSpace(directorLast))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(directorLast));
            }

            var cmdd = new CreateMovieDataDelegate(movieName, rating, runTime, releaseDate);

            CreateDirector(directorFirst, directorLast);
            var movie = executor.ExecuteNonQuery(cmdd);

            CreateMovieDirector(directorFirst, directorLast, directorSalary, movieName);

            return(movie);
        }
        /// <summary>
        /// Add agent to the database if valid entries when user clicks "Add Agent" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddAgent_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                int    agentID  = 0;
                string fullName = Check.FormatName(uxAgentFirstName.Text) + " " + Check.FormatName(uxAgentLastName.Text);
                float  salary   = float.Parse(uxSalary.Text);

                SqlCommandExecutor        executor     = new SqlCommandExecutor(connectionString);
                AgencyCreateAgentDelegate createsAgent = new AgencyCreateAgentDelegate(fullName, salary);
                Agent agent = executor.ExecuteNonQuery(createsAgent);
                agentID = agent.AgentID;

                MessageBox.Show("Agent " + fullName + " successfully added. Agent ID = " + agentID);
            }
        }
        public Workout CreateWorkout(int SessionID, double Duration, double AvgHeartRate)
        {
            if (Duration == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Duration));
            }

            if (AvgHeartRate == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(AvgHeartRate));
            }

            var d = new CreateWorkoutDataDelegate(SessionID, Duration, AvgHeartRate);

            return(executor.ExecuteNonQuery(d));
        }
Esempio n. 26
0
        public Person CreatePerson(string firstName, string lastName)
        {
            if (string.IsNullOrWhiteSpace(firstName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(firstName));
            }

            if (string.IsNullOrWhiteSpace(lastName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(lastName));
            }

            var d = new CreatePersonDataDelegate(firstName, lastName);

            return(executor.ExecuteNonQuery(d));
        }
        public Employee CreateEmployee(string employeeName, string workPositionName, string departmentName, double hourlyPay)
        {
            if (string.IsNullOrWhiteSpace(employeeName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(employeeName));
            }

            if (string.IsNullOrWhiteSpace(workPositionName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(workPositionName));
            }

            if (string.IsNullOrWhiteSpace(departmentName))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(departmentName));
            }

            var d = new CreateEmployeeDataDelegate(employeeName, workPositionName, departmentName, hourlyPay);

            return(executor.ExecuteNonQuery(d));
        }
        public Session CreateSession(int MetricID, int EnvironmentID, string StartTime, string EndTime, double Rating)
        {
            if (string.IsNullOrWhiteSpace(StartTime))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(StartTime));
            }

            if (string.IsNullOrWhiteSpace(EndTime))
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(EndTime));
            }

            if (Rating == 0)
            {
                throw new ArgumentException("The parameter cannot be null or empty.", nameof(Rating));
            }

            var d = new CreateSessionDataDelegate(MetricID, EnvironmentID, StartTime, EndTime, Rating);

            return(executor.ExecuteNonQuery(d));
        }
        /// <summary>
        /// Deletes the selected reservation from the trip
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void DeleteSelected_Click(object sender, RoutedEventArgs args)
        {
            if (uxReservations.SelectedItem != null)
            {
                if (uxReservations.SelectedItem is TextBlock t)
                {
                    int reservationID = int.Parse(t.Text.Split('\t')[1].Split(',')[0].Trim());

                    SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);
                    executor.ExecuteNonQuery(new AgencyDeleteReservationDelegate(reservationID));

                    uxReservations.Items.Remove(uxReservations.SelectedItem);
                    MessageBox.Show("Reservation " + reservationID + " was successfully deleted.");
                }
                else
                {
                    MessageBox.Show("Unable to access selected reserveration");
                }
            }
            else
            {
                MessageBox.Show("Please select a reservation to delete");
            }
        }
Esempio n. 30
0
        public void SaveAddress(int personId, AddressType addressType, string line1, string line2, string city, string stateCode, string zipCode)
        {
            if (line1 == null)
            {
                throw new ArgumentNullException(nameof(line1));
            }

            if (city == null)
            {
                throw new ArgumentNullException(nameof(city));
            }

            if (stateCode == null)
            {
                throw new ArgumentNullException(nameof(stateCode));
            }

            if (stateCode.Length != 2)
            {
                throw new ArgumentException("State code must be two characters.", nameof(stateCode));
            }

            if (zipCode == null)
            {
                throw new ArgumentNullException(nameof(zipCode));
            }

            if (zipCode.Length != 5)
            {
                throw new ArgumentException("Zip code must be five characters.", nameof(stateCode));
            }

            var d = new SavePersonAddressDataDelegate(personId, addressType, line1, line2 ?? "", city, stateCode, zipCode);

            executor.ExecuteNonQuery(d);
        }