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

            Assert.IsTrue(result.Status == ResultStatus.Succeeded);
        }
        public async Task Delete()
        {
            models.Page item   = WriteItem();
            Result      result = await repository.Delete(Constants.Site, item.Id);

            Assert.IsTrue(result.Status == ResultStatus.Succeeded);
        }
        private static models.Page WriteItem()
        {
            var output = new models.Page
            {
                Id   = Guid.Empty,
                Name = "Test"
            };

            return(output);
        }
        public async Task ItemById()
        {
            List <models.Page> list = await SharedList();

            Guid?id = list[0].Id;

            if (!id.HasValue)
            {
                Assert.Fail("List is empty.");
            }

            models.Page item = await repository.Item(Constants.Site, id);

            Assert.IsTrue(item != null);
        }
Example #5
0
        private static async Task <models.Page> Item(string site, Tables.dbo.Page page)
        {
            if (page == null)
            {
                return(null);
            }

            try
            {
                List <QuotesTable> quotes = await FetchQuotes.List(page.Id);

                List <ContentsTable> contents = await FetchContents.List(page.Id);

                var output = new models.Page
                {
                    Id           = page.Id,
                    Name         = page.Name,
                    DateCreated  = page.DateCreated,
                    LastModified = page.LastModified,
                    Contents     = contents.Select(n => new models.Localized.Page
                    {
                        Lcid  = n.Lcid,
                        Html  = n.Html,
                        Title = n.Title
                    }).ToList(),
                    Quotes = quotes.Select(n => new models.Localized.Pages.Quote
                    {
                        Lcid = n.Lcid,
                        Text = n.Text
                    }).ToList()
                };
                return(output);
            }
            catch (System.Exception ex)
            {
                await Exception.Save(site, ex, "Repository.ProfessionalTranslator.Net.Page");

                return(null);
            }
        }
Example #6
0
        public static async Task <List <models.Page> > List(string site)
        {
            List <Task <models.Page> > taskList = await TaskList(site);

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

            for (var i = 0; 0 < taskList.Count; i++)
            {
                if (i == taskList.Count)
                {
                    break;
                }
                models.Page item = taskList[i].Result;
                if (!output.Contains(item))
                {
                    output.Add(item);
                }
            }
            return(output);
        }
Example #7
0
        /// <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">Page 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.Page inputItem)
        {
            var saveStatus = ResultStatus.Undetermined;
            var messages   = new List <string>();

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

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

            models.Page existingItem = await Item(site, area, inputItem.Name);

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

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

            if (savePageResult.Status == ResultStatus.Failed)
            {
                return(new Result(savePageResult.Status, savePageResult.Messages));
            }

            // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
            //foreach (Models.ProfessionalTranslator.Net.Localized.Page localizedPage in inputItem.Bodies)
            //{
            //    var saveLocalization = new Tables.Localization.Page
            //    {
            //        Id = saveItem.Id,
            //        Html = localizedPage.Html,
            //        Title = localizedPage.Title,
            //        Lcid = localizedPage.Lcid
            //    };
            //    Result localizedResult = await DatabaseOperations.Localization.Write.Page.Item(site, saveLocalization);
            //    if (localizedResult.Status != ResultStatus.Failed) continue;
            //    saveStatus = ResultStatus.PartialSuccess;
            //    messages.AddRange(localizedResult.Messages);
            //}

            if (saveStatus == ResultStatus.Undetermined)
            {
                saveStatus = ResultStatus.Succeeded;
            }

            return(new Result(saveStatus, messages, returnId));
        }
        public async Task ItemByName()
        {
            models.Page item = await repository.Item(Constants.Site, Area.Root, "About");

            Assert.IsTrue(item != null);
        }