// To protect from overposting attacks, please 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()); } var type = await _context.OfferTypes.FirstOrDefaultAsync(x => x.Id == Offer.TypeId); if (type == null) { return(Page()); } var company = await _context.Companies.FirstOrDefaultAsync(x => x.CompanyOwnerId == this.GetUserId()); if (company == null) { return(Page()); } _context.Offers.Add(new Offer(Offer.Name, Offer.Description, type, Offer.Price, company)); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(Guid?id) { if (id == null) { return(NotFound()); } Offer = await _context.Offers.FirstOrDefaultAsync(x => x.Id == id && x.IsSold == false); if (Offer != null) { Offer.IsDeleted = true; await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } OfferType = await _context.OfferTypes.FindAsync(id); if (OfferType != null) { _context.OfferTypes.Remove(OfferType); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }