vendredi 14 août 2020

MVC random object in C#

I wanted to make a view page where website will randomly recommend 5 books out of all books. I wanted to base it on random values since I have never worked with Random class. The issue is that Random works only with int's as far I can see. Can anyone help me work it out for books class?

My code Book object:

public abstract class BaseEntity
{
    public string Id { get; set; }
    public DateTimeOffset CreatedAt { get; set; }

    public BaseEntity()
    {
        this.Id = Guid.NewGuid().ToString();
        this.CreatedAt = DateTime.Now;
    }
}

public class Book : BaseEntity
{
    [StringLength(30)]
    [DisplayName("Book Title")]
    public String Title { get; set; }
    [DisplayName("Writer First Name")]
    public String WriterFirstName { get; set; }
    [DisplayName("Writer Last Name")]
    public String WriterLastName { get; set; }
    [DisplayName("Released")]
    public DateTime ReleaseDate { get; set; }
    [DisplayName("Publisher")]
    public String Publisher { get; set; }
    [DisplayName("Number of Books")]
    public int NumberOfBooks { get; set; }
    public String Genre { get; set; }
    public String Format { get; set; }
    public String Description { get; set; }
    public String Image { get; set; }
    public static int Count { get; set; }
}



Aucun commentaire:

Enregistrer un commentaire