示例#1
0
        public async Task <IActionResult> Create(SiteEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var siteModel = _editModelToModelMapper.Map(new Sites(), editModel);

            if (siteModel.CheckInterval < MinCheckTimeSeconds || siteModel.CheckInterval > MaxCheckTimeSeconds)
            {
                return(BadRequest());
            }

            await _sitesRepository.AddAsync(siteModel);

            return(RedirectToAction(nameof(Index)));
        }
    public async Task SaveAsync()
    {
        try {
            var siteDb = SiteViewDto.ToSite();

            if (siteDb.Id == 0)
            {
                Site newSiteDb = await _sitesRepository.AddAsync(siteDb);

                SiteViewDto.Id = newSiteDb.Id;
                _toastService.ShowSuccess("New site added");
            }
            else
            {
                await _sitesRepository.SaveSiteAsync(siteDb);

                _toastService.ShowSuccess("Site was saved");
            }
        }
        catch (Exception ex) {
            _toastService.ShowError(ex.Message);
        }
    }