Skip to content

Commit

Permalink
Created RagfairService.AddOffer and made RagfairService.CreateAndAddO…
Browse files Browse the repository at this point in the history
…ffer call that method
  • Loading branch information
nexus4880 committed Jan 22, 2025
1 parent e1dd821 commit fbea6d2
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Fuyu.Backend.EFTMain/Services/RagfairService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ public Offer CreateAndAddOffer(IRagfairUser user, List<ItemInstance> items, bool
throw new Exception($"{nameof(requirements)} is empty");
}

var handbook = _eftOrm.GetHandbook();
var handbookItem = handbook.Items.Find(i => i.Id == items[0].TemplateId);

if (!CategoricalOffers.TryAdd(handbookItem.ParentId, 1))
{
CategoricalOffers[handbookItem.ParentId]++;
}

if (!CategoricalOffers.TryAdd(items[0].TemplateId, 1))
{
CategoricalOffers[items[0].TemplateId]++;
}

var offer = new Offer()
{
Id = MongoId.Generate(),
Expand All @@ -89,16 +76,35 @@ public Offer CreateAndAddOffer(IRagfairUser user, List<ItemInstance> items, bool
LoyaltyLevel = loyaltyLevel
};

Offers.Add(offer);

return offer;
return AddOffer(offer);
}

public Offer GetOffer(MongoId offerId)
{
return Offers.Find(o => o.Id == offerId);
}

public Offer AddOffer(Offer offer)
{
var items = offer.Items;
var handbook = _eftOrm.GetHandbook();
var handbookItem = handbook.Items.Find(i => i.Id == items[0].TemplateId);

if (!CategoricalOffers.TryAdd(handbookItem.ParentId, 1))
{
CategoricalOffers[handbookItem.ParentId]++;
}

if (!CategoricalOffers.TryAdd(items[0].TemplateId, 1))
{
CategoricalOffers[items[0].TemplateId]++;
}

Offers.Add(offer);

return offer;
}

public void RemoveOffer(Offer offer)
{
if (!Offers.Remove(offer))
Expand Down

0 comments on commit fbea6d2

Please sign in to comment.