-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecipeReviewManager.cs
59 lines (54 loc) · 1.85 KB
/
RecipeReviewManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TheGoodRecipe
{
public class RecipeReviewManager : RecipeReviewStorageManager
{
List<RecipeReview> allRecipeReviews;
List<RecipeReview> showRecipeReviews;
string REVIEW_FILENAME = "reviews.txt";
public void saveReviews()
{
FileStream f = new FileStream(REVIEW_FILENAME, FileMode.Truncate);
StreamWriter sw = new StreamWriter(f);
foreach(RecipeReview r in allRecipeReviews)
{
sw.WriteLine(r.getUsername() + "," + r.getrecipeID() + "," + r.getreviewText() + "," + r.gettimeStamp());
}
sw.Close();
f.Close();
}
public void readReviews()
{
allRecipeReviews = new List<RecipeReview>();
FileStream f = new FileStream(REVIEW_FILENAME, FileMode.OpenOrCreate);
StreamReader sr = new StreamReader(f);
while(sr.Peek() != -1)
{
string line = sr.ReadLine();
string[] line_var = line.Split(',');
allRecipeReviews.Add(new RecipeReview(line_var[0], line_var[1], line_var[2], DateTime.Parse(line_var[3])));
}
sr.Close();
f.Close();
}
public List<RecipeReview> getReviewsByRecipeID(string id)
{
showRecipeReviews = new List<RecipeReview>();
foreach(RecipeReview r in allRecipeReviews)
{
if (r.getrecipeID().Equals( id))
showRecipeReviews.Add(r);
}
return showRecipeReviews;
}
public void AddRecipeReview(RecipeReview recipeReview)
{
allRecipeReviews.Add(recipeReview);
}
}
}