public async Task <ActionResult> DeleteAccount() { PetOwner po = GetOwner(); var eggs = _eggRepo.GetEggsByPetOwner(po); foreach (var egg in eggs) { _eggRepo.RemoveEgg(egg); } var listings = _listingRepo.GetListingsByUsers(po); foreach (var list in listings) { _listingRepo.RemoveListing(list); } if (po.HasImage) { _imageRepo.RemoveImage(po.Image); } _poRepo.SaveChanges(); _poRepo.RemovePO(po); var user = await _um.FindByEmailAsync(po.Email); await _um.DeleteAsync(user); _poRepo.SaveChanges(); return(Ok()); }
public ActionResult <List <POItemDTO> > BuyItem(int id, int amount) { try { PetOwner user = GetUser(); Market markt = GetMarket(); MarketListing ml = GetListingWithID(markt, id); int valueOfTransaction = ml.ListingAmount * amount; if (valueOfTransaction > user.WalletAmount) { throw new Exception("You don't have enough funds for the transaction"); } Item it = ml.BuyItem(amount); user.WalletAmount -= valueOfTransaction; user.AddItem(it, amount); _poc.SaveChanges(); return(Ok(user.POI.Select(po => new POItemDTO(po)).ToList())); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(BadRequest(ModelState)); } }