//grabs list of notifcations and if the notification you want to mark as read actually exsists, then it assigns it as read public static void MarkRead(int note) { var notes = GetAllFromFile(); if (note >= notes.Length || note < 0) { throw new ArgumentOutOfRangeException("note", new Exception("You cannot mark a notification that does not exist as read.")); } notes[note].Read = true; //assigns the specific notification as read WriteNotes(notes); NotificationRead?.Invoke(); }
public async Task <IActionResult> AddReadNotificationAsync(Dictionary <string, string> data, [FromServices] IMongoCollection <NotificationRead> mongoCollection) { if (data == null || !data.ContainsKey("NotificationID") || !data.ContainsKey("User")) { return(this.Error(HttpStatusCode.BadRequest, "Json should contain Dictionary with <string, string> with Keys: NotificationID : Guid and User : string!")); } Guid notificationID; if (!Guid.TryParse(data["NotificationID"], out notificationID)) { return(this.Error(HttpStatusCode.BadRequest, "NotificationID wrong format. It should be Guid!")); } string user = data["User"]; NotificationRead temp = new NotificationRead { ID = Guid.NewGuid(), NotificationID = notificationID, User = user }; await mongoCollection.InsertOneAsync(temp); return(this.Success(temp.ID)); }