I'm building an API using ASP.NET Core 6 with mongodb as database. I'm trying to set a certain field to toggle from true to false and vice versa. If the field isactive:"True" then I have to update it to false and vice versa.
I have figured out how to update the value, but I have to toggle this field to opposite value automatically without having to specify the value.
Here is the repository class:
public bool UpdateStatus(string id)
{
_activity.UpdateOne(x => x.Id == id,
Builders<Activity>.Update.Set(u => u.IsActive,false));
return true;
}
Controller for above repository:
public ActionResult putbystatus(string id)
{
var existingactivity = activityRepository.Get(id);
if (existingactivity == null)
{
return NotFound($"Activity with provider id = {id} not found");
}
activityRepository.UpdateStatus(id);
return NoContent();
}