public async Task <IActionResult> Edit(int id, [Bind("Id,SenderItemId,ReceiverItemId")] Swapped swapped) { if (id != swapped.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(swapped); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SwappedExists(swapped.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(swapped)); }
public void Swap(int pos1, int pos2) { Swapped?.Invoke(pos1, pos2); int temp = Get(pos1); Set(pos1, Get(pos2)); Set(pos2, temp); }
public async Task <IActionResult> Create([Bind("Id,SenderItemId,ReceiverItemId")] Swapped swapped) { if (ModelState.IsValid) { _context.Add(swapped); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(swapped)); }
public async Task <IActionResult> CreateSwap([Bind("Id,Category,Img,Description,UserId,SwappedId, SenderItemId, ReceiverItemId")] int ReceiverItemId, int SenderItemId) { Swapped swapped = new Swapped(); var user = await GetCurrentUserAsync(); var swaps = _context.Item .Where(i => i.UserId == user.Id); if (ModelState.IsValid) { swapped.SenderItemId = SenderItemId; swapped.ReceiverItemId = ReceiverItemId; _context.Add(swapped); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Id"] = new SelectList(swaps, "Id", "Id"); return(View()); }
public async Task <IActionResult> AcceptOffer([Bind("Id,SenderItem,ReceiverItem,SenderItemId,ReceiverItemId")] int id, Swapped swapped) { Message message = new Message(); var user = await GetCurrentUserAsync(); if (ModelState.IsValid) { swapped.ReceiverItem.Id = swapped.ReceiverItemId; swapped.SenderItem.Id = swapped.SenderItemId; swapped.ReceiverItem.UserId = swapped.SenderItem.UserId; swapped.SenderItem.UserId = user.Id; _context.Update(swapped); message.SenderId = user.Id; message.ReceiverId = swapped.ReceiverItem.UserId; message.Text = $"{user.FirstName} has accepted your offer. Contact them at: {user.PhoneNumber}"; message.Datetime = DateTime.Now; _context.Add(message); await _context.SaveChangesAsync(); var swap = await _context.Swapped.FindAsync(id); _context.Swapped.Remove(swapped); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(swapped)); }