// ReSharper disable once SuggestBaseTypeForParameter
        private static async Task <models.Subscriber> Item(string site, Tables.dbo.Subscriber inputItem)
        {
            if (inputItem == null)
            {
                return(null);
            }

            try
            {
                var output = new models.Subscriber
                {
                    Id           = inputItem.Id,
                    FirstName    = inputItem.FirstName,
                    LastName     = inputItem.LastName,
                    EmailAddress = inputItem.EmailAddress
                };
                return(output);
            }
            catch (System.Exception ex)
            {
                await Exception.Save(site, ex, "Repository.ProfessionalTranslator.Net.Subscriber");

                return(null);
            }
        }
        public static async Task <List <models.Subscriber> > List(string site, Area area, int pageIndex, int pageSize)
        {
            int areaId = Enumerators.Values.Area(area);
            List <Task <models.Subscriber> > taskList = await TaskList(site, areaId, pageIndex, pageSize);

            if (taskList.Count == 0)
            {
                return(new List <models.Subscriber>());
            }
            var output = new List <models.Subscriber>();

            for (var i = 0; 0 < taskList.Count; i++)
            {
                if (i == taskList.Count)
                {
                    break;
                }
                models.Subscriber item = taskList[i].Result;
                if (!output.Contains(item))
                {
                    output.Add(item);
                }
            }
            return(output);
        }
        /// <summary>
        /// Saves page and child items.
        /// </summary>
        /// <instructions>
        /// Set inputItem.Id to null when creating a new object.
        /// </instructions>
        /// <param name="site">Name of site to which page is related.</param>
        /// <param name="area">Area where page resides.</param>
        /// <param name="inputItem">Subscriber object.</param>
        /// <returns>Returns save status and messages. If successful, returns an identifier via ReturnId.</returns>
        public static async Task <Result> Save(string site, Area area, models.Subscriber inputItem)
        {
            var messages = new List <string>();

            if (inputItem == null)
            {
                return(new Result(ResultStatus.Failed, "Subscriber cannot be null."));
            }

            Tables.dbo.Site siteItem = await dbRead.Site.Item(site);

            if (siteItem == null)
            {
                return(new Result(ResultStatus.Failed, "No site was found with that name."));
            }

            Rules.StringRequiredMaxLength(inputItem.FirstName, "Name", 50, ref messages);
            Rules.StringRequiredMaxLength(inputItem.LastName, "Name", 50, ref messages);
            if (Rules.StringRequiredMaxLength(inputItem.EmailAddress, "Email Address", 255, ref messages) ==
                Rules.Passed.Yes)
            {
                Rules.ValidateEmailAddress(inputItem.EmailAddress, "Email Address", ref messages);
            }

            if (messages.Any())
            {
                return(new Result(ResultStatus.Failed, messages));
            }

            models.Subscriber existingItem = await Item(site, area, inputItem.EmailAddress);

            Guid returnId = existingItem?.Id ?? Guid.NewGuid();
            int  areaId   = Enumerators.Values.Area(area);
            var  saveItem = new Tables.dbo.Subscriber
            {
                Id           = returnId,
                SiteId       = siteItem.Id,
                AreaId       = areaId,
                FirstName    = inputItem.FirstName,
                LastName     = inputItem.LastName,
                EmailAddress = inputItem.EmailAddress
            };

            Result saveSubscriberResult = await dbWrite.Item(site, saveItem);

            messages = saveSubscriberResult.Messages;

            return(new Result(saveSubscriberResult.Status, messages, returnId));
        }