Example #1
0
        /// <summary>
        /// retrieve a list of all widgets using the repository
        /// </summary>
        /// <returns>all widgets</returns>
        private List <Widget> GetAllWidgets()
        {
            List <Widget> widgets = null;

            FileIoStatus = FileIoMessage.None;

            try
            {
                using (WidgetRepository wRepository = new WidgetRepository())
                {
                    widgets = wRepository.GetAll() as List <Widget>;
                };

                if (widgets != null)
                {
                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.NoRecordsFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }

            return(widgets);
        }
Example #2
0
        /// <summary>
        /// retrieve a widget using the repository
        /// </summary>
        /// <returns>widget</returns>
        private Widget GetWidget(int id)
        {
            Widget widget = null;

            FileIoStatus = FileIoMessage.None;

            try
            {
                using (WidgetRepository wRepository = new WidgetRepository())
                {
                    widget = wRepository.GetById(id);
                };

                if (widget != null)
                {
                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }

            return(widget);
        }
Example #3
0
        /// <summary>
        /// add a new widget
        /// </summary>
        /// <param name="widget">widget to add</param>
        public void AddWidget(Widget widget)
        {
            try
            {
                if (widget != null)
                {
                    using (WidgetRepository wRepository = new WidgetRepository())
                    {
                        wRepository.Add(widget);
                    };

                    FileIoStatus = FileIoMessage.Complete;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }
Example #4
0
        /// <summary>
        /// retrieve a widget by id
        /// </summary>
        /// <param name="id">widget id</param>
        public void DeleteWidget(int id)
        {
            try
            {
                if (GetWidget(id) != null)
                {
                    using (WidgetRepository wRepository = new WidgetRepository())
                    {
                        wRepository.Delete(id);
                    }

                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }
Example #5
0
        /// <summary>
        /// update a widget
        /// </summary>
        /// <param name="updatedWidget">updated widget</param>
        public void UpdateWidget(Widget updatedWidget)
        {
            try
            {
                if (GetWidget(updatedWidget.Id) != null)
                {
                    using (WidgetRepository repo = new WidgetRepository())
                    {
                        repo.Update(updatedWidget);
                    }

                    FileIoStatus = FileIoMessage.Complete;
                }
                else
                {
                    FileIoStatus = FileIoMessage.RecordNotFound;
                }
            }
            catch (Exception)
            {
                FileIoStatus = FileIoMessage.FileAccessError;
            }
        }