public override IReadOnlyCollection <ActionComponentSetup> GetGlobalNavActions()
        {
            var navButtonSetups = new List <ActionComponentSetup>();

            if (CreateSystem.GetInfo().IsIdenticalToCurrent())
            {
                return(navButtonSetups);
            }

            // This will hide itself because Contact Us requires a logged-in user, and the standard library test web site has no users.
            var contactPage = EnterpriseWebFramework.EnterpriseWebLibrary.WebSite.ContactSupport.GetInfo(EwfPage.Instance.InfoAsBaseType.GetUrl());

            navButtonSetups.Add(new HyperlinkSetup(contactPage, contactPage.ResourceName));

            navButtonSetups.Add(
                new ButtonSetup(
                    "Test",
                    behavior: new MenuButtonBehavior(
                        new EwfButton(
                            new StandardButtonStyle("Test method"),
                            behavior: new PostBackBehavior(
                                postBack: PostBack.CreateFull(
                                    id: "testMethod",
                                    firstModificationMethod: () => EwfPage.AddStatusMessage(StatusMessageType.Info, "Successful method execution.")))).ToCollection())));

            return(navButtonSetups);
        }
        public override List <ActionButtonSetup> GetGlobalNavActionControls()
        {
            var navButtonSetups = new List <ActionButtonSetup>();

            if (CreateSystem.GetInfo().IsIdenticalToCurrent())
            {
                return(navButtonSetups);
            }

            // This will hide itself because Contact Us requires a logged-in user, and the standard library test web site has no users.
            var contactPage = EnterpriseWebFramework.EnterpriseWebLibrary.WebSite.ContactSupport.GetInfo(EwfPage.Instance.InfoAsBaseType.GetUrl());

            navButtonSetups.Add(new ActionButtonSetup(contactPage.ResourceName, new EwfLink(contactPage)));

            var menu = EwfTable.Create();

            menu.AddItem(
                () =>
                new EwfTableItem(
                    new EwfTableItemSetup(
                        clickScript:
                        ClickScript.CreatePostBackScript(
                            PostBack.CreateFull(id: "testMethod", firstModificationMethod: () => EwfPage.AddStatusMessage(StatusMessageType.Info, "Successful method execution.")))),
                    "Test method"));
            navButtonSetups.Add(new ActionButtonSetup("Test", new ToolTipButton(menu)));

            return(navButtonSetups);
        }
        public override List <LookupBoxSetup> GetGlobalNavLookupBoxSetups()
        {
            var lookupBoxSetups = new List <LookupBoxSetup>();

            if (CreateSystem.GetInfo().IsIdenticalToCurrent())
            {
                return(lookupBoxSetups);
            }

            lookupBoxSetups.Add(new LookupBoxSetup(100, "test", "lookup1", delegate { return(null); }));
            lookupBoxSetups.Add(new LookupBoxSetup(100, "test", "lookup2", delegate { return(null); }));
            return(lookupBoxSetups);
        }
        public override IReadOnlyCollection <NavFormControl> GetGlobalNavFormControls()
        {
            var controls = new List <NavFormControl>();

            if (CreateSystem.GetInfo().IsIdenticalToCurrent())
            {
                return(controls);
            }

            controls.Add(
                NavFormControl.CreateText(
                    new NavFormControlSetup(100.ToPixels(), "test"),
                    v => new NavFormControlValidationResult("This doesn’t actually work.")));
            controls.Add(
                NavFormControl.CreateText(
                    new NavFormControlSetup(100.ToPixels(), "test"),
                    v => new NavFormControlValidationResult("This doesn’t actually work.")));
            return(controls);
        }
예제 #5
0
        public async Task <CreateSystemResponse> Create(CreateSystem system)
        {
            var response = new CreateSystemResponse();

            if (string.IsNullOrEmpty(system.Name))
            {
                response.Error = "Введите название системы";
                return(response);
            }
            if (system.Name.Length > 40)
            {
                response.Error = "Слишком длинное название системы";
                return(response);
            }
            if (system.About == null)
            {
                system.About = "";
            }
            if (system.About.Length > 140)
            {
                response.Error = "Слишком длинное описание системы";
                return(response);
            }
            var user = await _userManager.GetUserAsync(User);

            var obj = new Test
            {
                Name        = system.Name,
                Description = system.About,
                User        = user
            };
            var        pictureTask = Task.CompletedTask;
            FileStream stream      = null;

            if (system.Picture != null)
            {
                if (system.Picture.Length > 5 * 1024 * 1024)
                {
                    response.Error = "Картинка слишком большая";
                    return(response);
                }
                var path = "/systems/" + obj.Id;
                switch (system.Picture.ContentType)
                {
                case "image/gif":
                    path += ".gif";
                    break;

                case "image/jpeg":
                    path += ".jpg";
                    break;

                case "image/png":
                    path += ".png";
                    break;

                default:
                    response.Error = "Картинка неизвестного формата";
                    return(response);
                }
                stream      = new FileStream(_hostingEnvironment.WebRootPath + path, FileMode.Create);
                pictureTask = system.Picture.CopyToAsync(stream);
                path       += "?d=" + DateTimeOffset.Now.ToUnixTimeMilliseconds();
                obj.Picture = path;
            }
            var responseObj = new TestJson
            {
                system = new SystemJson
                {
                    name    = obj.Name,
                    picture = obj.Picture,
                    about   = obj.Description,
                    pub     = obj.Published,
                    guid    = obj.Id.ToString()
                }
            };
            var json = JsonConvert.SerializeObject(responseObj);

            obj.PublishedJson = json;
            obj.AutosavedJson = json;
            _db.Tests.Add(obj);

            response.Succeded = true;
            response.Json     = json;

            await Task.WhenAll(pictureTask, _db.SaveChangesAsync());

            stream?.Close();
            return(response);
        }