Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Adjust default value in Blazor model

$
0
0

In my app I have a BaseEntity model that is inherited by all other models, it looks like this.

public class BaseEntity{    public int Id { get; set; }    public bool IsDeleted { get; set; } = false;    public DateTime DateCreated { get; set; } = DateTime.Now;    public DateTime? DateUpdated { get; set; }    public DateTime? DateDeleted { get; set; }}

In a given model I'm doing something like this.

public class TagVariant : BaseEntity{    public string Name { get; set; } = string.Empty;    public int? TagId { get; set; }    public Tag? Tag { get; set; }}public class Tag : BaseEntity{    public string Text { get; set; } = string.Empty;    [JsonIgnore]    public List<TagVariant> Variants { get; set; } = new List<TagVariant>();}

My controller looks like this.

[HttpPost]public async Task<ActionResult<List<Tag>>> CreateTag(Tag tag){    //temp force to be false    tag.IsDeleted = false;    _dataContext.Tags.Add(tag);    await _dataContext.SaveChangesAsync();    return Ok(tag);}

As you can see I'm having to manually tell the submission to change isDeleted to be false. I have it set in the model, so why am I having to manually set it?

Thanks!


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>