public async Task Save()
        {
            models.Image item   = WriteItem();
            Result       result = await repository.Save(Constants.Site, item);

            Assert.IsTrue(result.Status == ResultStatus.Succeeded);
        }
        public async Task SaveFailForInvalidSite()
        {
            models.Image item   = WriteItem();
            Result       result = await repository.Save(string.Empty, item);

            Assert.IsTrue(result.Status == ResultStatus.Failed);
        }
        public async Task SaveFailForPathLength()
        {
            models.Image item = WriteItem();
            item.Path = "Bygt2SRCOY4h1UeLu4cvIM9l4lTcfPLRb8CZvny91uhMDoUoL6jdbuPjSQDeKo3Xz2cOkChLVrZPqLu2ZfgToCB3OnVqFgWY8wlK2p6fZ253g2Gp982wgVL30eSEeYzVVozCkaIoBvnie6Bgds947aUoTLg4XFOsqOGRg8EtMCq7gnDteCQVNpxOdD5LGcKXmhsLdcKbRhVcbLe2fagg07Sz19JzWDMdz9JlQNXmwvlPabjfAFbyF0TRWjU0nIwXEyk5CX6uF5lZ8sZVeLSIHOFlPiVluTkRmec6Z7VaFFr0s0V4LHj5C0SZU7DRB8Sn6WilO7XHO0xgnBnxAk2H4WKppY9wab4mh23CTHkyf5gxkJoQIuvtAnuvcoZPgGdjy0TP0KfKlE5s0o3wYySzX6z4ScBygt2SRCOY4h1UeLu4cvIM9l4lTcfPLRb8CZvny91uhMDoUoL6jdbuPjSQDeKo3Xz2cOkChLVrZPqLu2ZfgToCB3OnVqFgWY8wlK2p6fZ253g2Gp982wgVL30eSEeYzVVozCkaIoBvnie6Bgds947aUoTLg4XFOsqOGRg8EtMCq7gnDteCQVNpxOdD5LGcKXmhsLdcKbRhVcbLe2fagg07Sz19JzWDMdz9JlQNXmwvlPabjfAFbyF0TRWjU0nIwXEyk5CX6uF5lZ8sZVeLSIHOFlPiVluTkRmec6Z7VaFFr0s0V4LHj5C0SZU7DRB8Sn6WilO7XHO0xgnBnxAk2H4WKppY9wab4mh23CTHkyf5gxkJoQIuvtAnuvcoZPgGdjy0TP0KfKlE5s0o3wYySzX6z4Sc";
            Result result = await repository.Save(Constants.Site, item);

            Assert.IsTrue(result.Status == ResultStatus.Failed);
        }
        public async Task SaveFailForEmptyPath()
        {
            models.Image item = WriteItem();
            item.Path = string.Empty;
            Result result = await repository.Save(Constants.Site, item);

            Assert.IsTrue(result.Status == ResultStatus.Failed);
        }
        internal static models.Image WriteItem()
        {
            var output = new models.Image
            {
                Id   = Guid.Empty,
                Path = "https://test.com/test.jpg"
            };

            return(output);
        }
        private static models.Image Item(Tables.dbo.Image inputItem)
        {
            if (inputItem == null)
            {
                return(null);
            }
            var output = new models.Image
            {
                Id   = inputItem.Id,
                Path = inputItem.Path
            };

            return(output);
        }
        internal static Tables.dbo.Image Convert(models.Image inputItem, Guid siteId)
        {
            if (inputItem == null)
            {
                return(null);
            }
            var output = new Tables.dbo.Image
            {
                Id     = inputItem.Id,
                SiteId = siteId,
                Path   = inputItem.Path
            };

            return(output);
        }
        public async Task Item()
        {
            List <models.Image> list = await repository.List(Constants.Site);

            Guid?id = list[0].Id;

            if (!id.HasValue)
            {
                Assert.Fail("Id is null.");
            }

            models.Image item = await repository.Item(id.Value);

            Assert.IsTrue(item != null);
        }
        /// <summary>
        /// Save image.
        /// </summary>
        /// /// <instructions>
        /// Set inputItem.Id to null when creating a new object.
        /// </instructions>
        /// <param name="site">Name of site for image.</param>
        /// <param name="inputItem">Image object.</param>
        /// <note>See https://stackoverflow.com/questions/39322085/how-to-save-iformfile-to-disk for admin save file.</note>
        /// <returns>Returns save status and messages. If successful, returns an identifier via ReturnId.</returns>
        public static async Task <Result> Save(string site, models.Image inputItem)
        {
            var messages = new List <string>();

            if (inputItem == null)
            {
                return(new Result(ResultStatus.Failed, "Image 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.Path, "Path", 440, ref messages);

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

            Tables.dbo.Image convertedImage = Convert(inputItem, siteItem.Id);
            if (convertedImage == null)
            {
                return(new Result(ResultStatus.Failed, "Could not convert Image model to table."));
            }

            Result saveImageResult = await dbWrite.Item(site, convertedImage);

            if (saveImageResult.Status == ResultStatus.PartialSuccess || saveImageResult.Status == ResultStatus.Succeeded)
            {
                saveImageResult.ReturnId = inputItem.Id;
            }

            return(saveImageResult);
        }
        private static async Task <models.Testimonial> Item(Tables.dbo.Testimonial testimonial)
        {
            try
            {
                models.Image portrait = await Image.Item(testimonial.PortraitImageId);

                models.Work work = await Work.Item(testimonial.WorkId);

                if ((portrait == null) && (work?.Cover?.Id != null))
                {
                    portrait = await Image.Item(work.Cover.Id);
                }
                List <Tables.Localization.Testimonial> localizedList = await dbLocalizedRead.List(testimonial.Id);

                var output = new models.Testimonial
                {
                    Id           = testimonial.Id,
                    Work         = work,
                    Portrait     = portrait,
                    Name         = testimonial.Name,
                    EmailAddress = testimonial.EmailAddress,
                    DateCreated  = testimonial.DateCreated,
                    Approved     = testimonial.Approved,
                    Entries      = localizedList.Select(n => new Models.ProfessionalTranslator.Net.Localized.Testimonial
                    {
                        Lcid = n.Lcid,
                        Html = n.Html.Trim()
                    }).ToList()
                };
                return(output);
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return(null);
            }
        }