/// <summary>
        /// Alters location record information, whether it be through:
        ///     CREATING a new record,
        ///     UPDATING a prexisting record,
        ///     DELETING a preexisting record, or
        ///     RECOVERING a delete Locations record
        /// </summary>
        ///
        /// <param name="context"> MaphawksContext class object </param>
        /// <param name="action"> AlterRecordInfoEnum type. Create, Update, Delete or Recover</param>
        /// <param name="table"> Maphawks Database table (model class) </param>
        ///
        /// <returns> Returns true on success, otherwise returns false </returns>
        public virtual bool AlterRecordInfo(AlterRecordInfoEnum action, IMaphawksDatabaseTable table)
        {
            if (table is null)
            {
                return(false);
            }


            var table_type = GetTable(table);


            switch (table_type)
            {
            case Table.Locations:
                return(AlterLocations(action, table));


            case Table.Contacts:
                return(AlterContacts(action, table));


            case Table.Special_Qualities:
                return(AlterSpecialQualities(action, table));


            case Table.Daily_Hours:
                return(AlterDailyHours(action, table));


            default:
                return(false);
            }
        }
        /// <summary>
        /// Performs Create, Update, and Delete actions on SpecialQualities table
        /// </summary>
        ///
        /// <param name="action"> AlterRecordInfoEnum type. Create, Update, Delete or Recover</param>
        /// <param name="table"> Maphawks Database table (model class) </param>
        ///
        /// <returns>False if error, true otherwise</returns>
        private bool AlterSpecialQualities(AlterRecordInfoEnum action, IMaphawksDatabaseTable table)
        {
            var special_qualities_record = (SpecialQualities)table;

            if (action is AlterRecordInfoEnum.Create)
            {
                try
                {
                    context.Add(special_qualities_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Update)
            {
                try
                {
                    context.Update(special_qualities_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Delete)
            {
                try
                {
                    context.Remove(context.SpecialQualities.Single(c => c.LocationId.Equals(special_qualities_record.LocationId)));
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            return(false);
        }
        /// <summary>
        /// Performs Create, Update and Delete actions on DailyHours table
        /// </summary>
        ///
        /// <param name="action"> AlterRecordInfoEnum type. Create, Update, Delete or Recover</param>
        /// <param name="table"> Maphawks Database table (model class) </param>
        ///
        /// <returns>False if error, true otherwise</returns>
        private bool AlterDailyHours(AlterRecordInfoEnum action, IMaphawksDatabaseTable table)
        {
            var daily_hours_record = (DailyHours)table;

            if (action is AlterRecordInfoEnum.Create)
            {
                try
                {
                    context.Add(daily_hours_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Update)
            {
                try
                {
                    context.Update(daily_hours_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Delete)
            {
                try
                {
                    context.Remove(context.DailyHours.Single(c => c.LocationId.Equals(daily_hours_record.LocationId)));
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            return(false);
        }
        /// <summary>
        /// Performs Create, Update, and Delete actions on Locations table
        /// </summary>
        ///
        /// <param name="action"> AlterRecordInfoEnum type. Create, Update, Delete or Recover</param>
        /// <param name="table"> Maphawks Database table (model class) </param>
        ///
        /// <returns>Fals if error, true otherwise.</returns>
        private bool AlterLocations(AlterRecordInfoEnum action, IMaphawksDatabaseTable table)
        {
            var locations_record = (Locations)table;

            if (action is AlterRecordInfoEnum.Create)
            {
                try
                {
                    context.Add(locations_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Update)
            {
                try
                {
                    context.Update(locations_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Delete)
            {
                try
                {
                    locations_record.SoftDelete = true;
                    context.Update(locations_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            if (action is AlterRecordInfoEnum.Recover)
            {
                try
                {
                    locations_record.SoftDelete = false;
                    context.Update(locations_record);
                    context.SaveChanges();
                    return(true);
                }
                catch (DbUpdateException)
                {
                    return(false);
                }
            }


            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Alters location record information, whether it be through:
        ///     CREATING a new record,
        ///     UPDATING a prexisting record,
        ///     DELETING a preexisting record, or
        ///     RECOVERING a delete Locations record
        /// </summary>
        ///
        ///
        /// <param name="context"> MaphawksContext class object </param>
        /// <param name="action"> AlterRecordInfoEnum type. Create, Update, Delete or Recover</param>
        /// <param name="table"> Maphawks Database table (model class) </param>
        ///
        /// <returns> Returns true on success, otherwise returns false </returns>
        public virtual bool AlterRecordInfo(AlterRecordInfoEnum action, IMaphawksDatabaseTable table)
        {
            if (table is null)
            {
                return(false);
            }


            var table_type = GetTable(table);



            switch (table_type)
            {
                #region Locations
            case Table.Locations:


                var locations_record = (Locations)table;

                if (action is AlterRecordInfoEnum.Create)
                {
                    try
                    {
                        context.Add(locations_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Update)
                {
                    try
                    {
                        context.Update(locations_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Delete)
                {
                    try
                    {
                        locations_record.SoftDelete = true;
                        context.Update(locations_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }



                if (action is AlterRecordInfoEnum.Recover)
                {
                    try
                    {
                        locations_record.SoftDelete = false;
                        context.Update(locations_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                return(false);

                #endregion



                #region Contact
            case Table.Contacts:


                var contact_record = (Contacts)table;

                if (action is AlterRecordInfoEnum.Create)
                {
                    try
                    {
                        context.Add(contact_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Update)
                {
                    try
                    {
                        context.Update(contact_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Delete)
                {
                    try
                    {
                        context.Remove(context.Contacts.Single(c => c.LocationId.Equals(contact_record.LocationId)));
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }

                return(false);

                #endregion



                #region Special Qualities
            case Table.Special_Qualities:


                var special_qualities_record = (SpecialQualities)table;

                if (action is AlterRecordInfoEnum.Create)
                {
                    try
                    {
                        context.Add(special_qualities_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Update)
                {
                    try
                    {
                        context.Update(special_qualities_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Delete)
                {
                    try
                    {
                        context.Remove(context.SpecialQualities.Single(c => c.LocationId.Equals(special_qualities_record.LocationId)));
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                return(false);

                #endregion



                #region Daily Hours
            case Table.Daily_Hours:


                var daily_hours_record = (DailyHours)table;

                if (action is AlterRecordInfoEnum.Create)
                {
                    try
                    {
                        context.Add(daily_hours_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Update)
                {
                    try
                    {
                        context.Update(daily_hours_record);
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                if (action is AlterRecordInfoEnum.Delete)
                {
                    try
                    {
                        context.Remove(context.DailyHours.Single(c => c.LocationId.Equals(daily_hours_record.LocationId)));
                        context.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateException)
                    {
                        return(false);
                    }
                }


                return(false);

                #endregion


            default:
                return(false);
            }
        }