Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sPerson"></param>
        /// <returns></returns>
        public bool NewSalesPerson(SalesPerson sPerson)
        {
            bool created = false;

            int lastId;

            try
            {
                lastId = dBa.GetLastId("Salesperson");
            }
            catch
            {
                throw new ArgumentException("Database connection down", "original");
            }


            // Control to see if there is any in the customer list if not set cNr to 1 or at 1 to total number of customer.Count
            PersonId = lastId < 0 ? 1 : lastId + 1;


            /// <summary>
            /// Stored procedure CreateSalesPerson @firstname string, @lastname string,  @tfl int, @email string, @role string
            /// </summary>
            try
            {
                if (dBa.NewOrUpdateDB("exec CreateSalesPerson @firstname ='" + sPerson.FirstName + "', @lastname = '" + sPerson.LastName + "', @tlf ='"
                                      + sPerson.tlfNr + "', @email = '" + sPerson.Email + "', @role = '" + sPerson.salesRole + "';"))
                {
                    created = true;
                }
            }
            catch
            {
                throw new ArgumentException("Database connection down", "original");
            }


            return(created);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="customer"></param>
        /// <returns></returns>
        public bool UpdateSalesPerson(int id, SalesPerson sPerson)
        {
            bool updated = false;
            List <SalesPerson> sPersons = new List <SalesPerson>();

            try
            {
                // Getting all info about a customer from the database where the id equals the input id
                sPersons = dBa.GetSalesPersonListFromDB("SELECT * FROM SalesPerson WHERE id = " + id + ";");
            }
            catch { throw new ArgumentException("Database connection down", "original"); }


            // Control if the input first name is null and setting it to the first name from the database else setting it to the input firstname
            sPerson.FirstName = sPerson.FirstName == null ? sPersons[0].FirstName : sPerson.FirstName;

            // Control if the input last name is null and setting it to the last name from the database else setting it to the input lastname
            sPerson.LastName = sPerson.LastName == null ? sPersons[0].LastName : sPerson.LastName;

            // Control if the input phone number is 0 and setting it to the phone number from the database else setting it to the input phone number
            sPerson.tlfNr = sPerson.tlfNr == 0 ? sPersons[0].tlfNr : sPerson.tlfNr;

            // Control if the input email is null and setting it to the email from the database else setting it to the input email
            sPerson.Email = sPerson.Email == null ? sPersons[0].Email : sPerson.Email;

            // Control if the input role is null and setting it to the role from the database else setting it to the input role
            sPerson.salesRole = sPerson.salesRole == null ? sPersons[0].salesRole : sPerson.salesRole;

            /// <summary>
            /// Stored procedure UpdateSalesPerson with paramaters @id, @firstname, @lastname, @tfl, @email, @role
            /// </summary>
            if (dBa.NewOrUpdateDB("exec UpdateSalesPerson @id = '" + id + "', @firstname = '" + sPerson.FirstName + "', @lastname = '" + sPerson.LastName + "', @tlf = '" + sPerson.tlfNr + "', @email = '"
                                  + sPerson.Email + "' , @role = '" + sPerson.salesRole + "';"))
            {
                return(updated = true);
            }

            return(updated);
        }