Shell passing complex json alters it - xaml

So I have the problem where passing complex json might be altered by moving it with shell.
string json = JsonConvert.SerializeObject(SelectedAnimeMedia);
Shell.Current.GoToAsync($"MediaDetailsPage?name={json}");
SelectedAnimeMedia is object of my class
public class Media
{
public int Id { get; set; }
public string Description { get; set; }
public string BannerImage { get; set; }
public int? AverageScore { get; set; }
public int Favourites { get; set; }
public int? Episodes { get; set; }
public airingSchedule airingSchedule { get; set; }
public MediaScheduleNode nextAiringEpisode { get; set; }
public ListEntry mediaListEntry { get; set; }
public TitleType Title { get; set; }
public CoverImageType CoverImage { get; set; }
public Date startDate { get; set; }
}
I need to serialize to pass it with that shell method. This is what I pass
"{\"Id\":129898,\"Description\":\"The world's number one assassin has been reincarnated as the eldest son of a family of aristocrat assassins. In exchange for being reincarnated in another world, a goddess has imposed upon him one condition. \\\"Kill the Hero who is prophesied to destroy the world.\\\" <br>\\n<br>\\nThis was to be the mission in his new life. The synergistic effect of the vast knowledge and experience he gained that made all manner of assassinations possible in the modern world, and the secret techniques and magic of the fantasy world's most powerful family of assassins turn him into the greatest assassin of all time.<br>\\n<br>\\n(Source: Crunchyroll)\",\"BannerImage\":null,\"AverageScore\":null,\"Favourites\":253,\"Episodes\":null,\"airingSchedule\":null,\"nextAiringEpisode\":null,\"mediaListEntry\":null,\"Title\":{\"Romaji\":null,\"English\":null,\"Native\":null,\"UserPreferred\":\"The World's Finest Assassin Gets Reincarnated in Another World as an Aristocrat\"},\"CoverImage\":{\"Medium\":null,\"Large\":\"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx129898-FRUzDtPhRigt.jpg\"},\"startDate\":null}"
This is what is received:
"{\"Id\":129898,\"Description\":\"The world's number one assassin has been reincarnated as the eldest son of a family of aristocrat assassins. In exchange for being reincarnated in another world, a goddess has imposed upon him one condition. /\"Kill the Hero who is prophesied to destroy the world./\" <br>/n<br>/nThis was to be the mission in his new life. The synergistic effect of the vast knowledge and experience he gained that made all manner of assassinations possible in the modern world, and the secret techniques and magic of the fantasy world's most powerful family of assassins turn him into the greatest assassin of all time.<br>/n<br>/n(Source: Crunchyroll)\",\"BannerImage\":null,\"AverageScore\":null,\"Favourites\":253,\"Episodes\":null,\"airingSchedule\":null,\"nextAiringEpisode\":null,\"mediaListEntry\":null,\"Title\":{\"Romaji\":null,\"English\":null,\"Native\":null,\"UserPreferred\":\"The World's Finest Assassin Gets Reincarnated in Another World as an Aristocrat\"},\"CoverImage\":{\"Medium\":null,\"Large\":\"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx129898-FRUzDtPhRigt.jpg\"},\"startDate\":null}"
Please copy and paste it in your notepad. Notice messed up slashes which unables me to deserialize it. Especially in Description field, but they are wrong in whole json.
I can do this Shell.Current.Navigation.PushAsync(new MediaDetailsPage(selectedAnimeMedia));
But what is the difference between this and the string based one? Is this method also pushing on Shell stack? As it isn't mentioned NOWHERE in the docs, which is weird. It doesn't require me to register route. And I don't know If I should use it or will it cause me problems on the line
What would be the correct way to just pass data having such complex strings with Shell? Or maybe I should not use strings.

Related

Confused about DTOs when reading and editing. How to desing DTO for filling the form in VUEjs app?

I am trying to develop an enterprise-level application. I have domain and application services. I have created my DTOs for multiple purposes separately. But confused about which way I should use them from the API viewpoint.
I have complex objects lets say,
public class Entity{
public int Id { get; set; }
public string Name { get; set; }
public int? ManufacturerId { get; set; }
public virtual Manufacturer Manufacturer { get; set; }
}
public class Manufacturer{
public int Id { get; set; }
public string Text { get; set; }
}
And I have corresponding DTOs designed with composition now. It was separated before.
public class EntityBaseDto{
public string Name { get; set; }
}
public class EntityReadDto : EntityBaseDto{
public string Manufacturer { get; set; }
}
public class EntityWriteDto : EntityBaseDto{
public int? ManufacturerId { get; set; }
}
Now the question is,
I have a table which is filled with List<EntityReadDto> which is clear. Before, EntityReadDto also had the ManufacturerDto as fully included with id and text. Whenever I require to edit one of the entries from the table I was able to load the dropdown selected items or list of tags etc with the ids attached to the Manufacturer objects within ReadDtos. Now it is not possible. Since I wanted to simplify the codes I just converted them to strings that are read-only. Now I have created another endpoint to get an editable version of the record when needed. Ex: EntityWriteDto will be used to fill the form when the edit is clicked on a specific item. The manipulation will be carried on that DTO and sent with the PUT type request to edit the record.
I am not sure if this approach is ok for these cases. What is the best practice for this? I have many objects related to the entities from other tables. Is it ok to make a call to get an editable version from the backend or need to have it right away in a VUEjs app?

Reference another class using an index vs storing entire instance

In a class which needs to "contain information" about another class (sorry I don't know the terms for this), should I store the reference to that other class as something like an integer/id, or should I store it as an instance of the other class? What is this called, if there is a name for it?
As a very basic example, an app where we want to store what a user's favorite restaurant is:
public class User {
public int id { get; set; }
public string name { get; set; }
// id of restaurant...
// public int favoriteRestaurantId { get; set; }
// ...or entire instance of Restaurant type
// public Restaurant favoriteRestaurant { get; set; }
}
public class Restaurant {
public int id { get; set; }
public string name { get; set; }
}
Note: if you think this is off topic, please explain why this question would be allowed and is a highly rated/useful question, but mine is not: Interface vs Base class Or at the very least tell me what this is "called" so I can research it more myself. As far as I can tell from Stackoverflow's FAQ this question is on topic.
Your first variant
public int favoriteRestaurantId { get; set; }
only makes sense if you are only interested in the id and not the other attributes (name) of the restaurant object. Otherwise you will need some external container that stores all restaurant objects and have to search the container for the restaurant with the given id.
In your second variant
public Restaurant favoriteRestaurant { get; set; }
if you write
someUser.favouriteRestaurant = someRestaurant;
this also stores a reference to an existing someRestaurant. It will not copy the whole object. at least not in languages like C# and Java.
Only if you do something like
someUser.favouriteRestaurant = new Restaurant(someRestaurant);
the user will have its own copy of the restaurant object.
There are cases where this would make sense but in your example it is probably not a good idea for two reasons:
If for example the name of the someRestaurant changes, this should also change the name of favouriteRestaurant. This will not happen automatically if favouriteRestaurant is a copy.
It is a waste of memory.

RavenDB document design, patching, and index creation

I am revisiting RavenDB after a brief experiment quite a while ago. At the moment I'm considering document design which is nested 3 levels deep, i.e.
public class UserEvent
{
public UserEvent()
{
Shows = new List<Show>();
}
public readonly string IdPrefix = "Events/";
public string Id { get; set; }
public string Title { get; set; }
public List<Show> Shows { get; set; }
}
public class Show
{
public Show()
{
Entries = new List<ShowEntry>();
}
public readonly string IdPrefix = "Shows/";
public string Id { get; set; }
public string EventId { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public List<ShowEntry> Entries { get; set; }
}
public class ShowEntry
{
public readonly string IdPrefix = "ShowEntries/";
public string Id { get; set; }
public string DogId { get; set; }
public string OwnerName { get; set; }
public EntryClass Class { get; set; }
}
First of all, is this a sensible design? A UserEvent generally has a few (less than 6) Show, but a Show can have between tens to hundreds of ShowEntry. I have included DogId in ShowEntry but maybe later I will change it to a property of Dog type. A Dog is of a particular Breed, and a Breed belongs to a Group. The Dog side of the story will have to be another question but for now I'm interested in the UserEvent side.
If my documents are designed this way can I use the Patching API to add items into the Entries collection within a Show? I would like to have an index which will summarise Entries based on Dog properties. Will indexes get processed if an a document is patched?
Your design certainly looks sensible from an outside perspective. The big question you need to ask yourself is, "What do you plan on querying a majority of the time?"
For instance, Show seems to be a fairly common object that would benefit from being an Aggregate Root (from Domain Driven Design). I find that when organizing my documents, the most important question is, "how often do you plan on querying the object."
To answer your last question, Patching should definitely causing re-indexing.

Modeling varying perspectives of an aggregate in Domain Driven Design

In employing Domain Driven design I often encounter an issue regarding the various perspective on a domain object, especially when using NHibernate. Perspectives are essentially ways to view an domain object. For example, a simplified model:
class Transaction
{
string Id { get; set; }
string CustomerName { get; set; }
DateTime Date { get; set; }
decimal Amount { get; set; }
decimal Tax { get; set; }
}
class Batch
{
string Account { get; set; }
string Number { get; set; }
DateTime? ClearDate { get; set; }
IList<Transaction> Transactions { get; }
decimal Total { get; }
}
The total property on the batch is the sum of the amounts on each transaction. When considering a single batch this model works well and is a proper representation of the domain. The client application however has a screen which displays collections of batches. That screen does not require any details about the transactions within a batch, only the total amount. Utilizing the same object on the listing screen is slow. One option is to make the Total property be settable, another option is to create a new class, such as:
class BatchOverview
{
string Number { get; set; }
decimal Total { get; set; }
}
This would have its own repository and its own NHibernate mapping to a database view.
Does this object belong to the domain model, or is it more application/GUI specific?
Should the batch overview object reference the batch object?
Is this a common pattern?
Is there any guidance in relation to this issue?
DDD has the concept of bounded contexts, however in this case the context is the same. Both the Batch class and the BatchOverview class refer to the same 'actual' batch - they are different views, or perspectives on it.
I would keep the new class out of the domain - it is a presentation concern in my book, and i would treat it as such. Normally this new object would be read-only so as not to having two ways of altering data (and one of them not having the full set of business logic contained).
However, you don't have to make a setter for the value just because you use nHibernate. Just make it use a backing field and let nHibernate write to that. (use access="field" in your mapping).
EDIT:
I call it a PresentationModel or ViewModel depending on the amount of logic inside.
I would probably keep a reference to the original object - but might only be an Id.

How to structure domain model when using NHibernate Search/Lucene

I am messing around with NHibernate Search and Lucene to create a searchable index of legal entities. My domain model looks somewhat like this:
[Indexed]
public abstract class LegalEntity : AggregateRoot
{
public virtual Address Address { get; set; }
}
public class Person : LegalEntity
{
public virtual string FirstNames { get; set; }
public virtual string LastName { get; set; }
}
public class Company: LegalEntity
{
public virtual string Name { get; set; }
}
public class Address : Component
{
public virtual string Street { get; set; }
public virtual string HouseNumber { get; set; }
// etc...
}
As the subclassing implies, LegalEntity is an NHibernate entity specialized as Person and Company, and Address is an NHibernate component.
Now, how would I best go about creating a really Google-like fuzzy search that includes all the fields of a LegalEntity, including those inside the Address component?
My first idea was to implement an AddressFieldBridge to help in bringing in the fields of the Address component, and then just throw in [Field] on all the fields, but then I could not find a way to construct a FuzzyQuery as a conjuntion between multiple search terms.
My next idea was to create an abstract property tagged with [Field] on LegalEntity, like so:
[Field(Index.Tokenized)]
public abstract string SearchableText { get; }
and then have Person and Company return texts that combine names and all the fields from the Address component into one string, which would then be tokenized and indexed by Lucene.
That, however, made me feel kind of icky.
I would like to learn the best and least intrusive (from a domain model perspective) way to accomplish this task - any suggestions are appreciated :)
Take a look at my question.
Andrey created patch to specify lucene stuff outside. Syntax ain't uber clean (maybe there's some progress done on this, haven't checked), but i guess it gets job done.