public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(CreditCard).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CreditCardExists(CreditCard.CreditCardId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string listingid) { EntityEntry entry = _context.Entry(Review); Listing = await _context.Listing.FirstOrDefaultAsync(m => m.ListingId == listingid); Review.Listing = Listing; Review.Lodger = await userManager.GetUserAsync(User); Review.DateTime = DateTime.Now; var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception)); if (!ModelState.IsValid) { return(Page()); } _context.Attach(Review).State = EntityState.Modified; try { await _context.SaveChangesAsync(); // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Review " + Review.ReviewId + " was edited"; auditrecord.DateTimeStamp = DateTime.Now; // Get current logged-in user auditrecord.PerformedBy = await userManager.GetUserAsync(User); auditrecord.IPAddress = auditrecord.PerformedBy.IPAddress; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReviewExists(Review.ReviewId)) { return(NotFound()); } else { throw; } } return(Redirect("./ListingDetails?id=" + Listing.ListingId)); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } //CustomerSupport.Username = await _userManager.GetUserNameAsync(await (_userManager.GetUserAsync(User))); //CustomerSupport.DateTimeStamp = DateTime.Now; var username = (from l in _context.CustomerSupport where l.CustomerSupport_ID == id select l.Username).ToList(); var datetime = (from l in _context.CustomerSupport where l.CustomerSupport_ID == id select l.DateTimeStamp).ToList(); var noreplies = (from l in _context.CustomerSupport where l.CustomerSupport_ID == id select l.NoReplies).ToList(); CustomerSupport.Username = username[0]; CustomerSupport.DateTimeStamp = datetime[0]; CustomerSupport.NoReplies = noreplies[0]; _context.Attach(CustomerSupport).State = EntityState.Modified; if (await _context.SaveChangesAsync() > 0) { var user = await _userManager.GetUserAsync(User); var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Edit Customer Support Record id: " + id; auditrecord.DateTimeStamp = DateTime.Now; auditrecord.PerformedBy = user; auditrecord.AuditRecordId = Guid.NewGuid().ToString(); auditrecord.IPAddress = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerSupportExists(CustomerSupport.CustomerSupport_ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string id) { Lodger = await userManager.GetUserAsync(User); var creator = (from l in _context.Listing where l.ListingId == id select l.Lodger.Id).ToList(); if (Lodger.Id == creator[0]) { var existingPic = (from l in _context.Listing where l.ListingId == id select l.CoverPic).ToList(); if (!ModelState.IsValid) { return(Page()); } if (Upload != null) { VirusReport vr = await ScanForVirus(Upload); if (vr.Positives > 0) { ModelState.AddModelError("CoverPicFailedVirusCheck", "Cover Picture failed virus scan!"); ModelState.AddModelError("CoverPicReportLink", vr.ReportLink); return(Page()); } changePic = true; string fullPath = "./wwwroot/ListingCover/" + existingPic[0]; fullPath = Path.GetFullPath(fullPath); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } var filename = Guid.NewGuid().ToString() + Path.GetExtension(Upload.FileName); var file = Path.Combine(_environment.ContentRootPath, "wwwroot", "ListingCover", filename); using (var fileStream = new FileStream(file, FileMode.Create)) { await Upload.CopyToAsync(fileStream); using (var ms = new MemoryStream()) { Upload.CopyTo(ms); var fileBytes = ms.ToArray(); hex = BitConverter.ToString(fileBytes).Replace("-", "").Substring(0, 4); if (!allowedFileTypes.Contains(hex)) { return(RedirectToPage("/Error/wrongFileType")); } Listing.CoverPic = filename; } } } _context.Attach(Listing).State = EntityState.Modified; if (!changePic) { Listing.CoverPic = existingPic[0]; _context.Listing.Update(Listing); } try { await _context.SaveChangesAsync(); // Create an auditrecord object var auditrecord = new AuditRecord(); auditrecord.AuditActionType = "Listing " + Listing.ListingId + " was edited"; auditrecord.DateTimeStamp = DateTime.Now; // Get current logged-in user auditrecord.PerformedBy = await userManager.GetUserAsync(User); auditrecord.IPAddress = auditrecord.PerformedBy.IPAddress; _context.AuditRecords.Add(auditrecord); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ListingExists(Listing.ListingId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Listings")); } else { return(RedirectToPage("./Error/NiceTry")); } }