예제 #1
0
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Area> Output = new List <Area>();

                var Source = Umbraco.Content(1122).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        Output.Add(new Area {
                            ID    = Node.Id,
                            Title = Node.GetPropertyValue("title")
                        });
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Post> Output = new List <Post>();

                var Source = Umbraco.Content(1125).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        Output.Add(new Post
                        {
                            ID          = Node.Id,
                            Title       = (string)Node.GetPropertyValue("title"),
                            Body        = (string)Node.GetPropertyValue("body"),
                            PublishedOn = Node.CreateDate,
                            PublishedBy = (string)Node.CreatorName,
                            Image       = "https://www.jirikralovec.cz/dev/givskud/images/demo-animalimage.jpg"
                                          // Image = "https://" + HttpContext.Current.Request.Url.Host + Node.GetPropertyValue("image").Url,
                        });
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public HttpResponseMessage Post([FromBody] SeasonPass Data)
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                IContentService Service = Services.ContentService;

                var Pass = Service.CreateContent(EncDecService.Hash(Data.ID), 1121, "seasonPass");
                Pass.SetValue("passID", EncDecService.Hash(Data.ID));
                Pass.SetValue("holderName", EncDecService.Encrypt(Data.Holder));
                Pass.SetValue("validFrom", Convert.ToDateTime(Data.ValidFrom));
                Pass.SetValue("validTo", Convert.ToDateTime(Data.ValidTo));
                Pass.SetValue("acquiredOn", Convert.ToDateTime(Data.AcquiredOn));

                string ResponseMessage;

                if (Service.SaveAndPublishWithStatus(Pass))
                {
                    ResponseMessage = "The content has been successfully saved.";
                }
                else
                {
                    ResponseMessage = "An error occured while saving the season pass.";
                }

                Response.Set(new StringContent(ResponseMessage, ApiContext.GetEncoding(), "text/plain"));
            }

            return(Response.Get());
        }
예제 #4
0
 public JsonResponse <JS.TextEditor> Load(string id)
 {
     return(JsonResponse.Catch(() => {
         var p = Texts.All.FirstOrDefault(x => x.Id == id && x.SiteId == Sites.CurrentSiteId);
         return JsonResponse.Create(new JS.TextEditor {
             Id = id, Text = p == null ? "" : p.BbText
         });
     }, Log));
 }
예제 #5
0
        public JsonResponse <JS.PageEditor> Load(int id)
        {
            return(JsonResponse.Catch(() => {
                var p = Pages.All.FirstOrDefault(x => x.Id == id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    return JsonResponse <JS.PageEditor> .NotFound;
                }

                return JsonResponse.Create(new JS.PageEditor {
                    Id = id, Path = p.Url, Text = p.BbText ?? "", Title = p.Title ?? "",
                    TagsStandIn = p.TagsStandIn, ReferenceName = p.ReferenceName ?? ""
                });
            }, Log));
        }
예제 #6
0
        private static void ApplyJsonResult(
            ActionExecutedContext context, HttpStatusCode statusCode,
            Type type, IJsonResponse response)
        {
            var error   = response.Error;
            var success = error is null;
            var value   = success ? response.Result : null;
            var empty   = value is null;

            Type InnerType() => InnerTypeCache.Get(type) ?? typeof(object);

            ObjectResult Create() =>
            !success?CreateError(JsonResponse.FromError(error !)) :
                empty?CreateResult(statusCode, JsonResponse.Empty) :
                    CreateResult(statusCode, JsonResponse.Create(InnerType(), value, null));

            context.Result = Create();
        }
        /// <summary>
        /// 删除机构
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <JsonResponse> RemoveOrganization(EntityRequest input)
        {
            var existsChild = await _organizationAppService.GetAnyByParentIdAsync(input.Id);

            if (existsChild)
            {
                return(JsonResponse.Create(false, "该机构有下级机构"));
            }
            var exitsEmp = await _relationOrganizationEmployeeAppService.GetAnyByOrganizationIdAsync(input.Id);

            if (exitsEmp)
            {
                return(JsonResponse.Create(false, "该机构有下有成员"));
            }
            input.Ids = new List <string>()
            {
                input.Id
            };
            var orgMenuIds = await _organizationMenuAppService.GetIdsByOrganizationIdsAsync(new List <string>() { input.Id });

            var orgElementIds = await _organizationElementAppService.GetIdsByOrganizationIdsAsync(new List <string>() { input.Id });

            var resJson = await _applicationEnginee.TryTransactionAsync(async() =>
            {
                await _organizationAppService.RemoveAsync(input);
                await _organizationMenuAppService.RemoveAsync(new EntityRequest()
                {
                    Ids            = orgMenuIds,
                    ModifyDate     = DateTime.Now,
                    ModifyUserId   = input.ModifyUserId,
                    ModifyUserName = input.ModifyUserName
                });
                await _organizationElementAppService.RemoveAsync(new EntityRequest()
                {
                    Ids            = orgElementIds,
                    ModifyDate     = DateTime.Now,
                    ModifyUserId   = input.ModifyUserId,
                    ModifyUserName = input.ModifyUserName
                });
            });

            return(resJson);
        }
        public HttpResponseMessage Get()
        {
            SecureContext SC            = new SecureContext();
            string        PassParameter = SC.GetHeaderParam("PassID");

            JsonResponse Response = new JsonResponse(true, SC);

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <SeasonPass> Output = new List <SeasonPass>();

                var Source = Umbraco.Content(1121).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        if ((string)Node.GetPropertyValue("passID") != PassParameter)
                        {
                            continue;
                        }
                        else
                        {
                            Output.Add(new SeasonPass
                            {
                                ID         = "n/a",
                                Holder     = (string)Node.GetPropertyValue("holderName"),
                                ValidFrom  = Convert.ToDateTime(Node.GetPropertyValue("validFrom")).ToString("dd-MM-yyyy"),
                                ValidTo    = Convert.ToDateTime(Node.GetPropertyValue("validTo")).ToString("dd-MM-yyyy"),
                                AcquiredOn = Convert.ToDateTime(Node.GetPropertyValue("acquiredOn")).ToString("dd-MM-yyyy")
                            });
                        }
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
예제 #9
0
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Event> Output     = new List <Event>();
                var          DataSource = Umbraco.Content(1124).Children().Where("Visible");

                if (DataSource.Count() > 0)
                {
                    foreach (var Node in DataSource)
                    {
                        Event Event = new Event
                        {
                            ID            = Node.Id,
                            Title         = Node.GetPropertyValue("title"),
                            Desc          = Node.GetPropertyValue("description"),
                            IsBoundToDate = Node.GetPropertyValue("isDateOnly"),
                            EventDate     = Node.GetPropertyValue("eventDate"),
                            EventTime     = Node.GetPropertyValue("eventTime")
                        };
                        if (Event.IsBoundToDate)
                        {
                            if (DateTime.Now != Event.EventDate)
                            {
                                continue;
                            }
                        }
                        Output.Add(Event);
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
예제 #10
0
        public JsonResponse <JS.TextSaveResult> Update([JsonRequestBody] JS.TextEditor text)
        {
            return(JsonResponse.Catch(() => {
                var p = Texts.All.FirstOrDefault(x => x.Id == text.Id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    p = Texts.Add(new Data.Text {
                        Id = text.Id, SiteId = Sites.CurrentSiteId
                    });
                }

                p.BbText = text.Text;
                p.HtmlText = Markup.ToHtml(p.BbText ?? "", new MarkdownParseArgs {
                    AttachmentMixin = Url.Mixin(( TextController c ) => c.Attachment(text.Id))
                });
                UnitOfWork.Commit();

                return JsonResponse.Create(new JS.TextSaveResult {
                    Html = p.HtmlText
                });
            }, Log));
        }
예제 #11
0
        public JsonResponse <JS.PageSaveResult> Update([JsonRequestBody] JS.PageEditor page)
        {
            return(JsonResponse.Catch(() => {
                var p = Pages.All.FirstOrDefault(x => x.Id == page.Id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    return JsonResponse <JS.PageSaveResult> .NotFound;
                }

                p.Title = page.Title ?? "";
                p.BbText = page.Text;
                p.TagsStandIn = page.TagsStandIn;
                p.ReferenceName = page.ReferenceName;
                p.HtmlText = Markup.ToHtml(p.BbText ?? "", new MarkdownParseArgs {
                    AttachmentMixin = Url.Mixin((PageController c) => c.Attachment(page.Id))
                });
                UnitOfWork.Commit();

                return JsonResponse.Create(new JS.PageSaveResult {
                    Title = p.Title, Html = p.HtmlText
                });
            }, Log));
        }
예제 #12
0
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <JsonResponse> RemoveRole(EntityRequest input)
        {
            var exitsMap = await _relationEmployeeRoleApp.GetAnyByRoleIdAsync(input.Id);

            if (exitsMap)
            {
                return(JsonResponse.Create(false, "该角色下有成员"));
            }
            input.Ids = new List <string>()
            {
                input.Id
            };
            var roleMenuIds = await _roleMenuAppService.GetIdsByRoleIdsAsync(new List <string>() { input.Id });

            var roleElementIds = await _roleElementAppService.GetIdsByRoleIdsAsync(new List <string>() { input.Id });

            var resJson = await _applicationEnginee.TryTransactionAsync(async() =>
            {
                await _roleAppService.RemoveAsync(input);
                await _roleMenuAppService.RemoveAsync(new EntityRequest()
                {
                    Ids            = roleMenuIds,
                    ModifyDate     = DateTime.Now,
                    ModifyUserId   = input.ModifyUserId,
                    ModifyUserName = input.ModifyUserName
                });
                await _roleElementAppService.RemoveAsync(new EntityRequest()
                {
                    Ids            = roleElementIds,
                    ModifyDate     = DateTime.Now,
                    ModifyUserId   = input.ModifyUserId,
                    ModifyUserName = input.ModifyUserName
                });
            });

            return(resJson);
        }
예제 #13
0
        public override Task ExecuteResultAsync(ActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var          response = context.HttpContext.Response;
            JsonResponse data     = null;
            var          value    = ((JsonResult)Value)?.Value;

            if (string.IsNullOrEmpty(value?.ToString()))
            {
                data = JsonResponse.Create();
            }
            else
            {
                data = new JsonResponse <object> {
                    Data = value
                };
            }
            WriteToResponse(response, data);
            //return TaskCache.CompletedTask;
            return(Task.CompletedTask);
        }
예제 #14
0
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <string> Output = new List <string>();

                var Source = Umbraco.Content(0001).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Quiz> Output = new List <Quiz>();

                var Source = Umbraco.Content(1123).Children().Where("Visible");

                // Sort parameter
                Int32.TryParse(HttpContext.Current.Request.QueryString["id"], out int QuizId);

                if (Source.Count() > 0)
                {
                    foreach (var Node in Source)
                    {
                        if (QuizId != 0 && Node.Id != QuizId)
                        {
                            continue;
                        }
                        Quiz Quiz = new Quiz
                        {
                            ID                = Node.Id,
                            Title             = Node.GetPropertyValue("title"),
                            IsLockedByDefault = (bool)Node.GetPropertyValue("isLockedByDefault"),
                            Questions         = new List <QuizQuestion>(),
                            Image             = "https://www.jirikralovec.cz/dev/givskud/images/demo-animalimage.jpg"
                                                // Image = "https://" + HttpContext.Current.Request.Url.Host + Node.GetPropertyValue("image").Url
                        };
                        // Individual questions
                        IEnumerable <IPublishedContent> Questions = Node.GetPropertyValue("questions");
                        foreach (IPublishedContent Q in Questions)
                        {
                            QuizQuestion QQ = new QuizQuestion
                            {
                                Question      = (string)Q.GetPropertyValue("questionText"),
                                Answers       = new Dictionary <int, string>(),
                                CorrectAnswer = (int)Q.GetPropertyValue("correctAnswer")
                            };
                            string[] Answers = (string[])Q.GetPropertyValue("answers");
                            if (Answers.Count() > 0)
                            {
                                for (int i = 0; i < Answers.Count(); i++)
                                {
                                    QQ.Answers.Add(i, Answers[i]);
                                }
                            }
                            Quiz.Questions.Add(QQ);
                        }
                        Output.Add(Quiz);
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
        public HttpResponseMessage Get()
        {
            JsonResponse Response = new JsonResponse(true, new SecureContext());

            Response.Create();

            if (Response.IsAuthentic == true)
            {
                List <Animal> Output = new List <Animal>();

                var Source = Umbraco.Content(1126).Children().Where("Visible");

                if (Source.Count() > 0)
                {
                    Int32.TryParse(HttpContext.Current.Request.QueryString["sortbyarea"], out int AreaId);

                    foreach (var Node in Source)
                    {
                        // Sort by area
                        IPublishedContent AnimalArea = Node.GetPropertyValue <IPublishedContent>("animalAreaId");
                        if (AreaId != 0 && AnimalArea.Id != AreaId)
                        {
                            continue;
                        }
                        // Get Animal quiz
                        int AnimalQuizId = -1;
                        var AnimalQuiz   = Node.GetPropertyValue("animalQuizId");
                        if (AnimalQuiz != null)
                        {
                            IPublishedContent AnimalQuizNode = (IPublishedContent)AnimalQuiz;
                            AnimalQuizId = AnimalQuizNode.Id;
                        }

                        // Output object
                        Animal Out = new Animal
                        {
                            ID   = Node.Id,
                            Name = (string)Node.GetPropertyValue("animalName"),

                            Content = Node.GetPropertyValue <string[]>("animalContent"),

                            Height = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalHeight"), " - ", " cm"),
                            Length = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalLength"), " - ", " cm"),
                            Weight = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalWeight"), " - ", " kg"),

                            Descendants = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalDescendants"), " -  ", ""),
                            Lifetime    = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalLifetime"), " - ", ""),

                            PregnancyTime = Node.GetPropertyValue <string>("animalPregnancyTime"),
                            Continent     = AnimalsControllerHelper.GroupedStringContent(Node.GetPropertyValue <string[]>("animalContinent"), ", ", ""),

                            /*
                             * Icon = "https://" + HttpContext.Current.Request.Url.Host + Node.GetPropertyValue("animalIcon").Url,
                             * Image = "https://" + HttpContext.Current.Request.Url.Host + Node.GetPropertyValue("animalImage").Url,
                             */
                            Icon  = "https://www.jirikralovec.cz/dev/givskud/images/demo-animalicon.png",
                            Image = "https://www.jirikralovec.cz/dev/givskud/images/demo-animalimage.jpg",

                            Status  = Node.GetPropertyValue <string>("animalStatus"),
                            Eats    = Node.GetPropertyValue <string>("animalEats"),
                            Species = Node.GetPropertyValue("animalSpecies"),

                            AreaID = AnimalArea.Id,
                            QuizID = AnimalQuizId
                        };
                        Output.Add(Out);
                    }
                }

                Response.Set(new StringContent(JsonConvert.SerializeObject(Output), ApiContext.GetEncoding(), ApiContext.GetOutputType()));
            }

            return(Response.Get());
        }
예제 #17
0
 private static void ApplyValueResult(
     ActionExecutedContext context, HttpStatusCode statusCode,
     Type type, object value)
 {
     context.Result = CreateResult(statusCode, JsonResponse.Create(type, value, null));
 }