public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.RootRecover(cuser, 1); return(View(model)); } var newApp = new App(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreatorId = cuser.Id }; // Default icon if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1) { newApp.IconPath = $"{_configuration["AppsIconSiteName"]}/appdefaulticon.png"; } else { var probeFile = await _storageService.SaveToProbe(Request.Form.Files.First(), _configuration["AppsIconSiteName"], newApp.AppId, SaveFileOptions.RandomName); newApp.IconPath = $"{probeFile.SiteName}/{probeFile.FilePath}"; } _dbContext.Apps.Add(newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = newApp.AppId })); }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(cuser, 1); return(View(model)); } string iconPath = string.Empty; if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1) { iconPath = $"{_serviceLocation.CDN}/images/appdefaulticon.png"; } else { var ossFile = await _storageService.SaveToOSS(Request.Form.Files.First(), Convert.ToInt32(_configuration["AppsIconBucketId"]), 3000); iconPath = ossFile.Path; } var _newApp = new App(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreatorId = cuser.Id, AppIconAddress = iconPath }; _dbContext.Apps.Add(_newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId })); }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(cuser, 1); return(View(model)); } string iconPath = string.Empty; if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1) { iconPath = Values.DeveloperServerAddress + "/images/appdefaulticon.png"; } else { iconPath = await StorageService.SaveToOSS(Request.Form.Files.First(), Values.AppsIconBucketId, 365); } var _newApp = new App(cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreaterId = cuser.Id, AppIconAddress = iconPath }; _dbContext.Apps.Add(_newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId })); }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var _cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(_cuser, 1); return(View(model)); } string iconPath = string.Empty; if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1) { iconPath = Values.DeveloperServerAddress + "/images/appdefaulticon.png"; } else { var iconFile = Request.Form.Files.First(); string DirectoryPath = GetCurrentDirectory() + DirectorySeparatorChar + $@"Storage" + DirectorySeparatorChar; if (Exists(DirectoryPath) == false) { CreateDirectory(DirectoryPath); } var NewFilePath = DirectoryPath + StringOperation.RandomString(10) + GetExtension(iconFile.FileName); var fileStream = new FileStream(NewFilePath, FileMode.Create); await iconFile.CopyToAsync(fileStream); fileStream.Close(); var fileAddress = await ApiService.UploadFile(await AppsContainer.AccessToken()(), Values.AppsIconBucketId, NewFilePath); iconPath = fileAddress.Path; } var _newApp = new App(_cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreaterId = _cuser.Id, AppIconAddress = iconPath }; _dbContext.Apps.Add(_newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId })); }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var currentUser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.RootRecover(currentUser); return(View(model)); } var newApp = new DeveloperApp(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform, model.IconPath) { CreatorId = currentUser.Id }; await _dbContext.Apps.AddAsync(newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = newApp.AppId })); }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var _cuser = await GetCurrentUserAsync(); var _newApp = new App(_cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreaterId = _cuser.Id }; _dbContext.Apps.Add(_newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(AllApps))); }