Example #1
0
        public static async Task <List <models.Work> > List(string site, Display display, int pageIndex, int pageSize)
        {
            bool show = display == Display.Approved;
            List <Task <models.Work> > taskList = await TaskList(site, show, pageIndex, pageSize);

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

            for (var i = 0; 0 < taskList.Count; i++)
            {
                if (i == taskList.Count)
                {
                    break;
                }
                models.Work item = taskList[i].Result;
                if (!output.Contains(item))
                {
                    output.Add(item);
                }
            }
            return(output);
        }
Example #2
0
        public static async Task <models.Work> Item(Guid?id)
        {
            if (!id.HasValue)
            {
                return(null);
            }
            Tables.dbo.Work item = await dbRead.Work.Item(id.Value);

            if (item == null)
            {
                return(null);
            }
            var output = new models.Work
            {
                Id          = item.Id,
                Cover       = await Image.Item(item.CoverId),
                Title       = item.Title,
                Authors     = item.Authors,
                Href        = item.Href,
                DateCreated = item.DateCreated,
                Display     = item.Display
            };

            return(output);
        }
Example #3
0
        /// <summary>
        /// Saves work and child items.
        /// </summary>
        /// <instructions>
        /// Set inputItem.Id to null when creating a new object.
        /// </instructions>
        /// <param name="site">Name of site related to work.</param>
        /// <param name="inputItem">Work object.</param>
        /// <returns>Returns save status and messages. If successful, returns an identifier via ReturnId.</returns>
        public static async Task <Result> Save(string site, models.Work inputItem)
        {
            var messages = new List <string>();

            if (inputItem == null)
            {
                return(new Result(ResultStatus.Failed, "Work 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."));
            }

            Tables.dbo.Image convertImage = Image.Convert(inputItem.Cover, siteItem.Id);
            if (convertImage == null)
            {
                return(new Result(ResultStatus.Failed, "Work must have a cover image."));
            }

            Result saveImageResult = await Image.Save(site, inputItem.Cover);

            if (saveImageResult.Status == ResultStatus.Failed)
            {
                return(new Result(saveImageResult.Status, messages));
            }

            Rules.StringRequiredMaxLength(inputItem.Title, "Title", 100, ref messages);
            Rules.StringRequiredMaxLength(inputItem.Authors, "Authors", 255, ref messages);
            if (Rules.StringRequiredMaxLength(inputItem.Href, "Href", 2048, ref messages) == Rules.Passed.Yes)
            {
                Rules.ValidateUrl(inputItem.Href, "Href", ref messages);
            }

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

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

            Result output = await dbWrite.Item(site, convertedWork);

            if (output.Status == ResultStatus.PartialSuccess || output.Status == ResultStatus.Succeeded)
            {
                output.ReturnId = inputItem.Id;
            }
            return(output);
        }
        public async Task Item()
        {
            List<models.Work> list = await SharedList();
            Guid? id = list[0].Id;
            if (!id.HasValue)
            {
                Assert.Fail("List is empty.");
            }

            models.Work item = await repository.Item(id);
            Assert.IsTrue(item != null);
        }
 internal static models.Work WriteItem()
 {
     var output = new models.Work
     {
         Id = Guid.Empty,
         Title = "Test",
         Authors = "Jane Austen Test",
         Cover = Image.WriteItem(),
         Href = "https://testurl.com",
         DateCreated = DateTime.Now,
         Display = false
     };
     return output;
 }
Example #6
0
        internal static Tables.dbo.Work Convert(models.Work inputItem, Guid siteId)
        {
            if (inputItem == null)
            {
                return(null);
            }
            var output = new Tables.dbo.Work
            {
                Id          = inputItem.Id,
                SiteId      = siteId,
                CoverId     = inputItem.Cover.Id,
                Title       = inputItem.Title,
                Authors     = inputItem.Authors,
                Href        = inputItem.Href,
                DateCreated = inputItem.DateCreated,
                Display     = inputItem.Display
            };

            return(output);
        }
        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);
            }
        }
Example #8
0
        public static async Task <List <models.Work> > List(string site)
        {
            List <Task <models.Work> > taskList = await TaskList(site);

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

            for (var i = 0; 0 < taskList.Count; i++)
            {
                if (i == taskList.Count)
                {
                    break;
                }
                models.Work item = taskList[i].Result;
                if (!output.Contains(item))
                {
                    output.Add(item);
                }
            }
            return(output);
        }
Example #9
0
        public static async Task <List <models.Work> > ListWithTestimonials(string site, int pageIndex, int pageSize)
        {
            List <Task <models.Work> > taskList = await TaskListTestimonials(site, true, pageIndex, pageSize);

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

            for (var i = 0; 0 < taskList.Count; i++)
            {
                if (i == taskList.Count)
                {
                    break;
                }
                models.Work item = taskList[i].Result;
                if (!output.Contains(item))
                {
                    output.Add(item);
                }
            }
            return(output);
        }
 public async Task Save()
 {
     models.Work item = WriteItem();
     Result result = await repository.Save(Constants.Site, item);
     Assert.IsTrue(result.Status == ResultStatus.Succeeded);
 }