Example #1
0
        public async Task <IActionResult> UpdateSiteInfo(UpdateSiteInfoAddressModel model)
        {
            var appid = await _tokenManager.ValidateAccessToken(model.AccessToken);

            var site = await _dbContext
                       .Sites
                       .Include(t => t.Root)
                       .SingleOrDefaultAsync(t => t.SiteName == model.OldSiteName);

            if (site == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"Could not find a site with name: '{model.OldSiteName}'"));
            }
            if (site.AppId != appid)
            {
                return(this.Protocol(ErrorType.Unauthorized, $"The site you tried to update is not your app's site."));
            }
            var conflict = await _dbContext.Sites
                           .Where(t => t.Id != site.Id)
                           .AnyAsync(t => t.SiteName.ToLower().Trim() == model.NewSiteName.ToLower().Trim());

            if (conflict)
            {
                return(this.Protocol(ErrorType.NotEnoughResources, $"There is already a site with name: '{model.NewSiteName}'. Please try another new name."));
            }
            site.SiteName       = model.NewSiteName;
            site.OpenToDownload = model.OpenToDownload;
            site.OpenToUpload   = model.OpenToUpload;
            await _dbContext.SaveChangesAsync();

            return(this.Protocol(ErrorType.Success, "Successfully updated your site!"));
        }
Example #2
0
        public async Task <IActionResult> UpdateSiteInfo(UpdateSiteInfoAddressModel model)
        {
            var appid = await _appRepo.GetAppId(model.AccessToken);

            var site = await _siteRepo.GetSiteByNameUnderApp(model.OldSiteName, appid);

            // Conflict = Name changed, and new name already exists.
            var conflict = model.NewSiteName.ToLower() != model.OldSiteName.ToLower() &&
                           await _siteRepo.GetSiteByName(model.NewSiteName) != null;

            if (conflict)
            {
                return(this.Protocol(ErrorType.NotEnoughResources, $"There is already a site with name: '{model.NewSiteName}'. Please try another new name."));
            }
            site.SiteName       = model.NewSiteName;
            site.OpenToDownload = model.OpenToDownload;
            site.OpenToUpload   = model.OpenToUpload;
            await _siteRepo.UpdateSite(site);

            return(this.Protocol(ErrorType.Success, "Successfully updated your site!"));
        }