Esempio n. 1
0
        public async Task <HandleResult> Edit([FromBody] Site model)
        {
            var info = model.Id > 0 ? await _service.GetById(model.Id) : new Site();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, info.Id > 0);

            var res = info.Id > 0 ? await _service.Update(info) : await _service.Add(info);

            if (res.IsSuccess)
            {
                if (info.IsDefault)
                {
                    await _service.RemoveOtherDefault(info.Id);
                }

                string siteFolderPath = Path.GetFullPath($"./Views/{info.SiteFolder}");
                if (!Directory.Exists(siteFolderPath))
                {
                    Directory.CreateDirectory(siteFolderPath);
                }
            }


            return(res);
        }
Esempio n. 2
0
        private void btnAddPassword_Click(object sender, EventArgs e)
        {
            Site site = new Site
            {
                EmailId      = GetCurrentEmail().EmailId,
                SiteName     = tbxSiteName.Text,
                SiteUserName = tbxSiteUserName.Text,
                SitePassword = tbxSitePassword.Text
            };

            ControllingException(() => _siteService.Add(site));
        }
Esempio n. 3
0
        public ActionResult Measure(SitePostModel site)
        {
            if (site.Url != null)
            {
                var siteModel = _mapper.Map <SiteModel>(site);
                var measures  = new List <TestingPageModel>();

                var checkSite = _siteService.GetSiteByUrl(site.Url);

                if (checkSite == null)
                {
                    siteModel.Sitemap = _siteService.GetSitemap(site.Url);
                    measures          = _siteService.MeasureSpeedResponse(siteModel.Sitemap);

                    if (measures == null)
                    {
                        return(View("SiteMapNotFound"));
                    }

                    siteModel.Pages = measures;
                    siteModel.Pages = _siteService.GetMinMax(siteModel.Pages);
                    _siteService.Add(siteModel);
                }

                else
                {
                    measures        = _siteService.MeasureSpeedResponse(checkSite.Sitemap);
                    checkSite.Pages = _siteService.GetListSpeeds(measures, checkSite.Pages);
                    checkSite.Pages = _siteService.GetMinMax(checkSite.Pages);
                    _siteService.UpdateSite(checkSite.Pages, checkSite.Id);
                }

                var getSiteResult = _siteService.GetSiteByUrl(site.Url);
                var result        = _mapper.Map <SiteViewModel>(getSiteResult);

                result.Pages = result.Pages.OrderBy(m => m.CurrentResponseTime).ToList();

                foreach (var item in getSiteResult.Pages)
                {
                    result.XPagesUrl.Add(item.PageUrl);
                    result.YPageSpeed.Add(item.CurrentResponseTime);
                }

                result.Sites = GetSelectList();

                return(View(result));
            }

            return(View("Index"));
        }
Esempio n. 4
0
        public HttpResponseMessage Add(SiteModel siteModel)
        {
            HttpRequestMessage request = null;

            if (ModelState.IsValid)
            {
                _siteService.Add(siteModel);
                _siteService.Save();
                return(request.CreateResponse(HttpStatusCode.OK, siteModel));
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 5
0
 public ActionResult <Site> AddSite(Site site)
 {
     try
     {
         var query = _siteService.GetById(site.SiteId);
         if (query == null)
         {
             _siteService.Add(site);
             return(Ok());
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(NoContent());
 }
        public SiteModule(ISiteService siteService): base("/sites")
        {
            if (siteService == null)
            {
                throw new ArgumentNullException(nameof(siteService));
            }

            this.siteService = siteService;

            Get["/"] = _ => siteService.GetAll();

            Get["/{id}"] = parameter => siteService.GetById(parameter.id) ?? HttpStatusCode.NotFound;

            Get["{id}/pages"] = parameter => siteService.GetPages(parameter.id) ?? HttpStatusCode.NotFound;

            Post["/"] = _ =>
            {
                var site = this.Bind<Site>();

                site = siteService.Add(site);

                return site;
            };

            Put["/{id}"] = parameter =>
            {
                var site = this.Bind<Site>();

                site.SiteId = parameter.id;

                bool isUpdated = siteService.Update(site);

                return isUpdated ? HttpStatusCode.OK : HttpStatusCode.NotFound;
            };

            Delete["/{id}"] = parameter =>
            {
                var site = new Site() {SiteId = parameter.id};

                bool isDeleted = siteService.Remove(site);

                return isDeleted ? HttpStatusCode.OK : HttpStatusCode.NotFound;
            };
        }
Esempio n. 7
0
 public async Task <ActionResult <bool> > Add(InsertSiteModel req)
 {
     return(Ok(await _siteService.Add(UserId,
                                      req)));
 }