I am building a character creator for an out-of-print TTRPG system. The issue that I've run into is how to dynamically create dropdown boxes where the user can make skill/weapon choices based on their race/class choice.
For example: If user picks raceOne, he may pick any Lore skill he wants(he can do this twice), and he may choose one of any profession.
Now, Race two has some more interesting choices: He needs to pick between skillId 5 or SkillId 6, he also needs to make a decision between skillId 7 or 8.
My initial thought was to create a multi-dimensional array, and have array[x][] represent the number of choices one would have to make (RaceTwo in this example, has 2 different choices to make.) and choice[0][x] would represent one of the options. and then in my view I could just iterate through the array to create the dropdowns and their options, but it appears that arrays cannot be sized dynamically in c#.
Attached here is my RaceEntity, and the StartingSKills entity. I dont know enough about what I'm doing to know exactly what all code I should post here, but I'm trying to learn.
public class Race
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string? ImagePath { get; set; }
public virtual IList<RaceStartingArmor> RaceStartingArmor { get; set; }
public virtual IList<RaceStartingSkills> RaceStartingSkills { get; set; }
public virtual IList<RaceStartingTalents> RaceStartingTalents { get; set; }
public virtual IList<RaceStartingWeapons> RaceStartingWeapons { get; set; }
public virtual IList<RaceStartingGear> RaceStartingGear { get; set; }
}
public class RaceStartingSkills
{
public RaceStartingSkills(int RaceId, int SkillId , bool isKnown)
{
this.RaceId = RaceId;
this.SkillId = SkillId;
this.isKnown = isKnown;
}
public int Id { get; set; }
[ForeignKey(nameof(Race))]
public int RaceId { get; set; }
public Race Race { get; set; }
[ForeignKey(nameof(Skill))]
public int SkillId { get; set; }
public Skill Skill { get; set; }
public bool isKnown { get; set; }
public bool isTrained { get; set; }
public bool isSkilled { get; set; }
public bool isExpert { get; set; }
}
some more context: After race/class is chosen, the user is taken to a view where both race and class options are to be populated and chosen, this DTO will then be sent to the character sheet view and populated
any information, or video links, or anything just to get me moving in the right direction would be exceptionally helpful.
Related
Firstly, apologies if this seems basic, I am new to C#/dotnet and if the answer to this questions is somewhere obvious please point me in the right direction.
I have a DTO class with the following code
public class LessonDetailView : BaseResult
{
public long Id { get; set; }
public string Title { get; set; }
public List<LessonImagesListView> LessonImages { get; set; }
public List<LessonInstructionCardListView> InstructionCards { get; set; }
}
public class LessonImagesListView
{
public long Id { get; set; }
public string Title { get; set; }
public ImageDetailView Image { get; set; }
public LessonImagesListView()
{
Image = new ImageDetailView();
}
}
public class LessonInstructionCardListView
{
public long Id { get; set; }
public string Instructions { get; set; }
}
So I have 2 distinct types of object that I attach to the lesson and send to the frontend.
I will add that in the future I might have 6 different types of object.
These Images, or Instructions are also going to be displayed in a certain order on the front end so instead of sending them all separately I wanted to combine them all and send them in a new List LessonAssetsListView for example.
How can i create Lists in a DTO that combine 2 other lists ?
OR ... is this something I even need to do here ... and can i just do all this in my service.
Help appreciated.
You could simply define a type that composes both your existing and send a List of them
public class LessonAsset
{
public LessonImagesListView Image {get;set; }
public LessonInstructionCardListView Instruction {get;set;}
}
and then
public class LessonDetailView : BaseResult
{
public long Id { get; set; }
public string Title { get; set; }
public List<LessonAsset> LessonAssets { get; set; }
}
I'm writing a Xamarin Forms page that is going to display a document that has some properties and a list of projects. The user should be able to add and remove transactions from each project. From what I can find on the internet, it's not a good practice to nest listview and people are referring to RepeaterView instead. My problem with RepeaterView is that each repeater (project) needs to be interacted with (which I read was not possible), f.x. to add new transactions or delete other transactions.
Here is a link to a screenshot (I don't have enough reputation to post image) of the design for more clarity of what I want to accomplish:
https://imgur.com/a/Cth1XfT
How would I set up a page like this? Nested listviews, Repeater with a listview inside or something else?
EDIT: here is a example of the model that will be fed to the view:
public class Document
{
public int DocumentID { get; set; }
public string DocumentName { get; set; }
public string DocumentProperty1 { get; set; }
*
*
*
public string DocumentPropertyN { get; set; }
public List<Project> Projects { get; set; }
}
public class Project
{
public int ProjectID { get; set; }
public string ProjectName { get; set; }
public string ProjectProperty1 { get; set; }
*
*
*
public string ProjectPropertyM { get; set; }
public List<Transaction> Transactions { get; set; }
}
public class Transaction
{
public int TransactionID { get; set; }
public string TransactionName { get; set; }
public string TransactionProperty1 { get; set; }
*
*
*
public string TransactionPropertyM { get; set; }
}
You can check SyncFusion Listview Grouping, they have the functionalities you desire
They have a community license as well
I am creating web api for application which support football team in collecting statistic data from matches. I am on implementing phase now. And lets say I am thinking what (if it is needed) type of design patter will be best for something like this:
public class Shot
{
public int Id { get; set; }
public int PlayerId { get; set; }
public string Comment { get; set; }
public bool OnGoal { get; set; }
public int GameId { get; set; }
}
and
public class Card
{
public int Id { get; set; }
public int PlayerId { get; set; }
public string Comment { get; set; }
public bool IsRed{ get; set; }
public int GameId { get; set; }
}
As You can see some properties are same. It should be implemented with interface, inheritance ( f.e. class Action) or maybe I should use one of Design patterns (which one)? What will be best for Entity Framework to avoid problems in later phases?
Well, both your classes represent some kind of game event - shot and card. There could be some other game events, like a free kick, throw in, substitution, penalty, or corner kick. All of these events should have id, game id, player id, timestamp, and probably comment. So your problem is the duplication of data in several classes. It is easily solved with inheritance. No patterns required:
public abstract class GameEvent
{
public int Id { get; set; }
public int GameId { get; set; }
public int PlayerId { get; set; }
public TimeSpan Time { get; set; }
public string Comment { get; set; }
}
And various specific events
public class Shot : GameEvent
{
public bool OnGoal { get; set; }
}
public class Card : GameEvent
{
public bool IsRed { get; set; }
}
You should also think about saving timestamp of added time because you can get both 46 minutes time span (start of second half) and 45+1 minutes of first half.
How to: Do nested lists in sqlite-net-extensions
Answer Found: Keeping the question as an example of how to do it.
The problem i encountered was not sqlite-net-extensions related, but i'm keeping the question for context.
[Old Question]
I've got a problem with TwinCoders SQLite-net extensions.
I'm trying to insert a Series object into my database:
I'm using the Db.InsertWithChildren(SelectedSeriesObject,recursive:true) method.
The Series object is added accordingly with it's attributes.
All the Episodes are added as well, no problems there.
The problem is the BaseSeason.
It will only insert one Season object, which is (for some reason) the last Season Object of the list of Seasons in the Series
public class BaseSeries : BaseMedia
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Indexed]
public int ShowId { get; set; }
public string FirstAirDate { get; set; }
public string LastAirDate { get; set; }
public string Status { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BaseSeason> Seasons { get; set; }
/// <summary>
/// TvShow = 0, Anime = 1
/// </summary>
public int SeriesType { get; set; }
}
public class BaseSeason
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(BaseSeries))]
public int SeasonId { get; set; }
public int SeasonNumber { get; set; }
public int NumberOfEpisodes { get; set; }
public string Plot { get; set; }
public string Poster { get; set; }
public string AirDate { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BaseEpisode> Episodes { get; set; }
[ManyToOne]
public BaseSeries BaseSeries { get; set; }
}
public class BaseEpisode
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(BaseSeason))]
public int EpisodeId { get; set; }
public string Title { get; set; }
public string Plot { get; set; }
public string Poster { get; set; } //still path
public string AirDate { get; set; }
public int EpisodeNumber { get; set; }
public int SeasonNumber { get; set; }
public string SeriesName { get; set; }
[ManyToOne]
public BaseSeason BaseSeason { get; set; }
}
Is there anyone with experience regarding nested relationships in sqlite-net-extensions that knows how to make this work or see what i did wrong?
So regarding writing nested lists in sqlite-net-extensions:
My problem turned out the be related to how I handle the creation of these objects, this is by no means related to sqlite-net extensions. So my bad!
Which means that the questions example is valid and works. (I tested it of course)
Setting up the entities for the database:
The example shown in my question, with a Series class, Season class and Episode class, is the correct way of setting it up.
Inserting into the database:
If you're wondering how to insert an object similar to my Series object (with nested lists), use:
db.InsertWitchChildren(yourObject, recursion: true)
Here's an extended example:
public void AddSeries()
{
MediaDB.db.CreateTable<BaseSeries>();
MediaDB.db.CreateTable<BaseSeason>();
MediaDB.db.CreateTable<BaseEpisode>();
MediaDB.db.InsertWithChildren(SelectedSeries, recursion: true);
}
Side Note:
The example uses a static property on class with the connection string. Like so:
public class MediaDB
{
public static SQLiteConnection db => new SQLiteConnection(new SQLitePlatformGeneric(),"Media.db");
}
Refrain from doing this it is not really the best thing to do, since you should use using for the SQLiteConnection, making sure it's disposed once you're done with it.
more info on: sqlite-net-extentions
[UPDATE]: Further expansion of handling nested lists in sqlite-net extensions:
Deleting tables with children:
This is quite simple, but i spent a good hour and half figuring it out anyways.
Just use:
For lists/arrays: db.DeleteAll(yourCollection, recursion: true)
For single objects: db.Delete(yourObject, true);
As an exmaple: here's my implementation of a method that will delete a List
(BaseSeries is the class shown in the original question question):
public static void RemoveCollection<T>(List<T> collection)
{
using (db)
{
if (typeof(T) == typeof(BaseMovie))
{
db.DeleteAll(collection);
}
if (typeof(T) == typeof(BaseSeries))
{
db.DeleteAll(collection, recursion: true);
}
}
}
The BaseMovie class is a simple single entity, recursion is not needed since it holds no children.
I'm looking for a way to "divide" multiple operations that needs to be done so as to gain efficiency.
Let me put an example to explain my need.
Say that I have this object:
public class CardInfo
{
public int mCardID { get; set; }
public string mCardName { get; set; }
public int? mCardNumber { get; set; }
public string mCardColor { get; set; }
(...)
}
Each objects may be linked to a price list object:
public class PriceListInfo
{
public int mPriceListId { get; set; }
public int mPriceProviderID { get; set; }
public PriceProviderInfo mPriceListProvider { get; set; }
public int mCardID { get; set; }
public CardInfo mCard { get; set; }
public decimal? mPriceLow { get; set; }
public decimal? mPriceMid { get; set; }
public decimal? mPriceHigh { get; set; }
}
Now I have a process which task is to actually get a list of cards and build the price list of each cards, like this:
List<CardInfo> listCards = mCardManager.ListCardsForCardSet(_cardSetID);
foreach(var card in listCards)
{
List<PriceListInfo> listPrices = mPriceManager.ListPricesForCar(card);
}
Something quite simple, however if the list of cards contains more than 500 items, it will take a while. I am wondering (and since I don't know much about Asp.Net, it is why I am asking the question) if there's a way to divide the list by an [X] number and then launch many times the List<PriceListInfo> listPrices = mPriceManager.ListPricesForCar(card); line? Or is there a way to make these operation asynchronously? (please pardon my ignorance, thank you.) Can anybody explain how could I proceed, and if you could provide an example, I'd be more than happy.