Home > OS >  .Net Core Automatically update User information after an appointment is set
.Net Core Automatically update User information after an appointment is set

Time:12-16

I'm trying to figure out how I can select an appointment, when the time comes my system can automatically update the user's information. At the moment I have no idea or any information on whether it is possible to have them work automatically. Here's what I'm trying to implement:

public class User 
{
    public bool Status { get; set; }
    public DateTimeOffset? changeStatusDate { get; set; }
}
if changeStatusDate = DateTime.Now
Status = StatusChange      //Status will be update and save to the Database

Example: I have a changeStatusDate = 12/30/2022

If changeStatusDate = DateTime.Now

User Status will be converted from true to false

I've tried searching but haven't found anything similar to what I'm doing. Thanks for everyone's help

CodePudding user response:

you can achieve this by using properties set.

private DateTimeOffset? ChangeStatusDate;
public bool Status { get; set; }
public DateTimeOffset? changeStatusDate
{
    get { return ChangeStatusDate; }
    set
    {
        if (value == DateTime.Now)
        {
            Status = false;
        }
        ChangeStatusDate = value;
    } 
}

CodePudding user response:

If I understand your query correctly, why don't you implement the changedStatusDate as full property and on the setter put the logic and set the status accordingly? Something like:

public class User 
{
    public bool Status { get; set; }
    private DateTimeOffset? changeStatusDate 
    public DateTimeOffset? ChangeStatusDate 
    { 
        get 
        {
            return changeStatusDate;
            } 
        set 
        { 
            changeStatusDate = value;
            if (changeStatusDate = DateTime.Now)
                Status =StatusChange;
        }
    }
}
  • Related