// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } db.Update(Company); await db.CommitAsync(); //Image uploading if (Imgfile != null) { CompanyPicInfo = CompanyPicInfo == null ? new CompanyPicture() : CompanyPicInfo; //Upload to file system string uploadsFolder = Path.Combine(env.WebRootPath, "img"); string uniqueFileName = Path.Combine("org", Guid.NewGuid().ToString() + "_" + Imgfile.FileName); string filePath = Path.Combine(uploadsFolder, uniqueFileName); //Update database CompanyPicInfo.Path = uniqueFileName; CompanyPicInfo.imageType = ImageType.Icon; CompanyPicInfo.CompanyId = Company.companyId; picdb.AddIcon(CompanyPicInfo); await picdb.CommitAsync(); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await Imgfile.CopyToAsync(fileStream); } } TempData["CompanyStatus"] = "Your company profile has been saved!"; return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (Company == null) { return(RedirectToPage("../Index")); } db.Delete(Company); await db.CommitAsync(); TempData["CompanyDelete"] = "Your company has been removed!"; return(RedirectToPage("../Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { var user = await userManager.GetUserAsync(User); if (!ModelState.IsValid) { return(Page()); } await Task.Run(() => { Company.company_create_date = DateTime.Now; }); db.Add(Company); await db.CommitAsync(); await Task.Run(() => { user.CompanyID = Company.companyId; }); if (Imgfile != null) { CompanyPicInfo = CompanyPicInfo == null ? new CompanyPicture() : CompanyPicInfo; //Upload to file system string uploadsFolder = Path.Combine(env.WebRootPath, "img"); string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName); string filePath = Path.Combine(uploadsFolder, uniqueFileName); //Update database await Task.Run(() => { CompanyPicInfo.Path = uniqueFileName; CompanyPicInfo.imageType = ImageType.Icon; CompanyPicInfo.CompanyId = Company.companyId; }); picdb.AddIcon(CompanyPicInfo); await picdb.CommitAsync(); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await Imgfile.CopyToAsync(fileStream); } } await userManager.UpdateAsync(user); await signInManager.RefreshSignInAsync(user); TempData["CompanyStatus"] = "Your company profile has been created!"; return(RedirectToPage("./Index")); }