Beispiel #1
0
        /// <summary>
        /// Francis Mingomba
        /// Created: 2019/04/03
        ///
        /// Adds Resort Property to database
        /// </summary>
        /// <param name="resortProperty">resort property</param>
        /// <returns>resort property id</returns>
        public int AddResortProperty(ResortProperty resortProperty)
        {
            int id;

            var conn = DBConnection.GetDbConnection();

            const string cmdText = @"sp_create_resort_property";

            var cmd = new SqlCommand(cmdText, conn)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@ResortPropertyTypeId", resortProperty.ResortPropertyTypeId);

            try
            {
                conn.Open();

                id = Convert.ToInt32(cmd.ExecuteScalar());
            }
            finally
            {
                conn.Close();
            }

            return(id);
        }
Beispiel #2
0
        /// <summary author="Francis Mingomba" created="2019/04/03">
        /// Updates Resort Property
        /// </summary>
        /// <param name="oldResortProperty">Old Resort Property (database copy)</param>
        /// <param name="newResortProperty">New Resort Property (new copy)</param>
        public void UpdateResortProperty(ResortProperty oldResortProperty, ResortProperty newResortProperty)
        {
            try
            {
                this.MeetsValidationCriteria(newResortProperty, GetResortVehicleValidationCriteria());

                _resortPropertyAccessor.UpdateResortProperty(oldResortProperty, newResortProperty);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Francis Mingomba
        /// Created: 2019/04/03
        ///
        /// Retrieves Resort Property from database by resort property id
        /// </summary>
        /// <param name="id">resort property id</param>
        /// <returns>Resort Property Object</returns>
        public ResortProperty RetrieveResortPropertyById(string id)
        {
            ResortProperty resortProperty;

            var conn = DBConnection.GetDbConnection();

            const string cmdText = @"sp_select_resort_property_by_id";

            var cmd = new SqlCommand(cmdText, conn)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@ResortPropertyId", id);

            try
            {
                conn.Open();

                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();

                    resortProperty = new ResortProperty()
                    {
                        ResortPropertyId     = reader.GetInt32(0),
                        ResortPropertyTypeId = reader.GetString(1)
                    };
                }
                else
                {
                    throw new ApplicationException("Resort Property not found.");
                }

                reader.Close();
            }
            finally
            {
                conn.Close();
            }

            return(resortProperty);
        }
Beispiel #4
0
        /// <summary author="Francis Mingomba" created="2019/04/03">
        /// Adds Resort Property to database
        /// </summary>
        /// <param name="resortProperty">resort property</param>
        /// <returns>resort property id</returns>
        public int AddResortProperty(ResortProperty resortProperty)
        {
            int resortPropertyId;

            try
            {
                this.MeetsValidationCriteria(resortProperty, GetResortVehicleValidationCriteria());

                resortPropertyId = _resortPropertyAccessor.AddResortProperty(resortProperty);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(resortPropertyId);
        }
Beispiel #5
0
        /// <summary>
        /// Francis Mingomba
        /// Created: 2019/04/03
        ///
        /// Updates resort property in database
        /// </summary>
        /// <param name="oldResortProperty">old resort property</param>
        /// <param name="newResortProperty">new resort property</param>
        public void UpdateResortProperty(ResortProperty oldResortProperty, ResortProperty newResortProperty)
        {
            var conn = DBConnection.GetDbConnection();

            const string cmdText = @"sp_update_resort_property";

            var cmd = new SqlCommand(cmdText, conn)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@ResortPropertyId", oldResortProperty.ResortPropertyId);
            cmd.Parameters.AddWithValue("@OldResortPropertyTypeId", oldResortProperty.ResortPropertyTypeId);

            cmd.Parameters.AddWithValue("@NewResortPropertyTypeId", newResortProperty.ResortPropertyTypeId);

            try
            {
                conn.Open();

                int result = cmd.ExecuteNonQuery();

                if (result == 0)
                {
                    // .. resort property wasn't found or old and database copy did not match
                    throw new ApplicationException("Database: Resort property not updated");
                }
                else if (result > 1)
                {
                    // .. protection against change in expected stored stored procedure behaviour
                    throw new ApplicationException("Fatal Error: More than one property updated");
                }
            }
            finally
            {
                conn.Close();
            }
        }
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            bool success = ValidateArgs();

            if (success)
            {
                if (string.IsNullOrEmpty(cmbResortPropertyType.Text))
                {
                    return;
                }

                var resortProperty = new ResortProperty
                {
                    ResortPropertyId     = int.Parse(txtResortProperty.Text),
                    ResortPropertyTypeId = cmbResortPropertyType.Text
                };

                if (Save(resortProperty, out string errorStr))
                {
                    MessageBox.Show("Resort Property Saved Successfully");

                    RefreshFormAtCurrentIndex();

                    EnableDirectionNavigation();

                    ToggleNowCancelButtonToNew();
                }
                else
                {
                    MessageBox.Show(
                        $"{((resortProperty.ResortPropertyId == 0) ? "Failed to create resort property" : "Failed to update resort property")}\n{errorStr}");
                }
            }
            else
            {
                MessageBox.Show(_errorText);
            }
        }
        private bool Save(ResortProperty resortProperty, out string errorStr)
        {
            try
            {
                errorStr = "";

                if (resortProperty.ResortPropertyId == 0)
                {
                    _resortPropertyManager.AddResortProperty(resortProperty);
                }
                else
                {
                    _resortPropertyManager.UpdateResortProperty(_resortProperties[_currentIndex], resortProperty);
                }

                return(true);
            }
            catch (Exception e)
            {
                errorStr = $"{e.Message}\n{e.StackTrace}";
            }

            return(false);
        }