Exemplo n.º 1
0
        /// <summary>
        /// Enteres a modification history entry based on the submitted customer and the modification type.
        /// </summary>
        /// <param name="context">The context in which the modification entry will be performed.</param>
        /// <param name="customer">The customer object that has been modified. Original details are saved in the history table.</param>
        /// <param name="modificationType">The modofication type: Add, Remove, Update, Other</param>
        /// <returns></returns>
        private async Task EnterModificationHistory(CustomersContext context, Customer customer, ModificationType modificationType)
        {
            CustomerDbHistory customerHistory = new CustomerDbHistory()
            {
                // log modification type
                ModificationType = modificationType,
                // and customer details so it's easier to reproduce changes
                Id             = customer.Id,
                AddressLineOne = customer.AddressLineOne,
                Category       = customer.Category,
                Country        = customer.Country,
                DateOfBirth    = customer.DateOfBirth,
                Gender         = customer.Gender,
                HouseNumber    = customer.HouseNumber,
                Name           = customer.Name,
                State          = customer.State,
                ChangedOn      = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")
            };

            try
            {
                context.CustomerDbHistories.Add(customerHistory);
                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                DbLog.LogException(e, "DataProxy.cs");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Takes the CustomerDbHistory and retrieves all the properties names in the form of csv headers.
        /// </summary>
        /// <param name="history">CustomerDbHistory object to parse into csv headers.</param>
        /// <returns>Names of the CustomerDbHistory properties translated into csv headers.</returns>
        private string CustomerHistoryToCsvHeaders(CustomerDbHistory history)
        {
            if (history == null)
            {
                throw new ArgumentNullException("history", "Value can not be null or Nothing!");
            }

            StringBuilder historyHeader = new StringBuilder();
            Type          type          = history.GetType();

            System.Reflection.PropertyInfo[] propertyInfo = type.GetProperties();

            for (int index = 0; index < propertyInfo.Length; index++)
            {
                historyHeader.Append(propertyInfo[index].Name);

                if (index < propertyInfo.Length - 1)
                {
                    historyHeader.Append(",");
                }
            }

            return(historyHeader.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Takes the CustomerDbHistory and retrieves all the properties names in the form of csv headers.
        /// </summary>
        /// <param name="history">CustomerDbHistory object to parse into csv headers.</param>
        /// <returns>Names of the CustomerDbHistory properties translated into csv headers.</returns>
        private string CustomerHistoryToCsvHeaders(CustomerDbHistory history)
        {
            if (history == null)
            {
                throw new ArgumentNullException("history", "Value can not be null or Nothing!");
            }

            StringBuilder historyHeader = new StringBuilder();
            Type type = history.GetType();
            System.Reflection.PropertyInfo[] propertyInfo = type.GetProperties();

            for (int index = 0; index < propertyInfo.Length; index++)
            {
                historyHeader.Append(propertyInfo[index].Name);

                if (index < propertyInfo.Length - 1)
                {
                    historyHeader.Append(",");
                }
            }

            return historyHeader.ToString();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Enteres a modification history entry based on the submitted customer and the modification type.
        /// </summary>
        /// <param name="context">The context in which the modification entry will be performed.</param>
        /// <param name="customer">The customer object that has been modified. Original details are saved in the history table.</param>
        /// <param name="modificationType">The modofication type: Add, Remove, Update, Other</param>
        /// <returns></returns>
        private async Task EnterModificationHistory(CustomersContext context, Customer customer, ModificationType modificationType)
        {
            CustomerDbHistory customerHistory = new CustomerDbHistory()
            {
                // log modification type
                ModificationType = modificationType,
                // and customer details so it's easier to reproduce changes
                Id = customer.Id,
                AddressLineOne = customer.AddressLineOne,
                Category = customer.Category,
                Country = customer.Country,
                DateOfBirth = customer.DateOfBirth,
                Gender = customer.Gender,
                HouseNumber = customer.HouseNumber,
                Name = customer.Name,
                State = customer.State,
                ChangedOn = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")
            };

            try
            {
                context.CustomerDbHistories.Add(customerHistory);
                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                DbLog.LogException(e, "DataProxy.cs");
            }
        }