This is my collection:
public ObservableCollection<CheckOutData> _CheckOutCollection = new ObservableCollection<CheckOutData>();
public ObservableCollection<CheckOutData> CheckOutCollection
{
get { return _CheckOutCollection; }
}
public class CheckOutData
{
public int ID { get; set; }
public string RoomType { get; set; }
public string RoomNumber { get; set; }
public decimal RoomPrice { get; set; }
public string RoomPriceWithCurrency { get; set; }
public decimal Discount { get; set; }
public decimal DiscountedPrice { get; set; }
public string DiscountedPriceWithCurrency { get; set; }
public string CheckIn { get; set; }
public string CheckOut { get; set; }
public int TotalDay { get; set; }
public string CheckOutHour { get; set; }
}
I have another window where i want to do following: Add CheckOutData public string serviceName{get;set}
how can this done? i dont even see checkoutdata in my child window.
So my main task is add new collection in checkoutdata and then rebind datagrid. Can anyone help me?
private CheckOut m_parent;
public AddActionService(CheckOut parent)
{
InitializeComponent();
m_parent = parent;
}
You might want to consider some sort of event aggregator. This way any form's code (or ViewModel/Presenter, if you're using MVVM/MVP) can send messages that are picked up by the aggregator and distributed to any other forms/ViewModels/Presenters that have subscribed to that event. This approach means your forms are no longer tightly coupled together. They literally have no reference to each other at all. They communicate through the event aggregator and they don't even know if any objects are listening for those events.
You could also consider taking it one step further and going for a "Domain Events" style, that allows you to react to these events not just in UIs, but also in domain objects elsewhere in your system, including sending messages via external services to call web services, update databases, put messages in queues etc.
Related
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.
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; }
}
New ASP.NET core (to the whole web thing actually). So, making controllers and also started implementing Interfaces for scalability (my code base is pretty big, and already feeling the heat implementing Interfaces too late down the line). I have a couple of classes like this -
public interface IParent {
string IParent1 { get; set; }
string IParent2 { get; set; }
string IParent3 { get; set; }
}
public class ChildClass1: IParent {
public string IParent1 { get; set; }
public string IParent2 { get; set; }
public string IParent3 { get; set; }
string ChildClass11 { get; set; }
string ChildClass12 { get; set; }
string ChildClass13 { get; set; }
}
public class ChildClass2 : IParent {
public string IParent1 { get; set; }
public string IParent2 { get; set; }
public string IParent3 { get; set; }
string ChildClass21 { get; set; }
string ChildClass22 { get; set; }
string ChildClass23 { get; set; }
}
I need to send an object which is of type ChildClass1 or ChildClass2 from my Angular/Typescript website (the json model is either ChildClass1 or ChildClass2), and one of my controllers will receive this -
[HttpPost, DisableRequestSizeLimit]
public async Task<IActionResult> Post(IParent parent)
{
if (parent is ChildClass1)
{
// Do something
}
if (parent is ChildClass2)
{
// Do something else
}
// Rest of the controller
...
}
Now the issue is, the arg parent of the controller is only receiving whatever properties it has. I.e. properties of childclasss are not deserialized and doesn't even exist (because the parent doesn't have them I think).
Can someone kindly suggest how to solve this, please? I would like the parent arg to hold full ChildClass1 or ChildClass2 variables and then typecast and perform their related operation.
Apologies if somethings doesn't make sense. Please let me know if you need more information. Many thanks in advance!
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 have an application serving multiple websites and would like to setup colour scheming like this:
Each element (link, text, heading, etc) has a default for the application
Each element can be overridden for individual websites
If an element is set to application default, the custom colour should be remembered for future reference
Website Configuration.cs
public class WebsiteConfiguration
{
public ApplicationConfiguration ApplicationConfiguration { get; set; }
public string CustomLinkColour { get; set; }
public bool IsCustomLinkColourActive { get; set; }
public string LinkColour
{
get
{
return (IsCustomLinkColourActive ? CustomLinkColour : ApplicationConfiguration.DefaultLinkColour);
}
}
public string CustomTextColour { get; set; }
public bool IsCustomTextColourActive { get; set; }
public string TextColour
{
get
{
return (IsCustomTextColourActive ? CustomTextColour : ApplicationConfiguration.DefaultTextColour);
}
}
// ...and so on for each colour scheme element...
}
ApplicationConfiguration.cs
public class ApplicationConfiguration
{
public List<WebsiteConfiguration> WebsiteConfigurations { get; set; }
public string DefaultLinkColour { get; set; }
public string DefaultTextColour { get; set; }
//... and so on for each colour scheme element...
}
Problems
It's a lot of work!
There are just 2 colour scheme elements in the examples above, but there may be 50+ of them.
Also, it is creating a lot of work in the view files, with if else blocks etc.
Attempted Solution
A ColourSchemeItem class manages the logic.
public class ColourSchemeItem
{
public string DefaultColour { get; set; }
public string CustomColour { get; set; }
public bool IsCustomColourActive { get; set; }
public string ActiveColour
{
get
{
return (IsCustomColourActive ? CustomColour : DefaultColour);
}
}
}
And then WebsiteConfiguration becomes much simpler...
public class WebsiteConfiguration
{
public ApplicationConfiguration ApplicationConfiguration { get; set; }
public ColourSchemeItem Link { get; set; }
public ColourSchemeItem Text { get; set; }
// ...and so on for each colour scheme element...
}
However...
But somehow I need to get the default colour from the ApplicationConfiguration into the ColourSchemeItem. And I can't figure out how.
If the ColourSchemeItem contains a reference to it's parent - WebsiteConfiguration - I get a No Key Defined for Entity error.
If ColourSchemeItem does NOT contain a reference to it's parent, I can't access the default colour from WebsiteConfiguration.ApplicationConfiguration.
The only other option I can think of it to access the DB directly from within the ColourSchemeItemclass. If there are going to be 50+ of these, I don't want to do that.
Create a custom constructor, and set the default to AplicationConfiguration