-
Notifications
You must be signed in to change notification settings - Fork 0
/
SingleArtwork.aspx.cs
executable file
·208 lines (177 loc) · 6.43 KB
/
SingleArtwork.aspx.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Content.Business;
using Content.DataAccess;
using System.Web.Security;
public partial class DisplaySingleArtWork : System.Web.UI.Page
{
private ArtWorkCollection ac = new ArtWorkCollection();
private ArtWorkReviewCollection artReview = new ArtWorkReviewCollection(false);
private int artWorkId = 0;
protected void Page_Load(object sender, EventArgs e)
{
artWorkId = GetQueryString();
if (artWorkId <= 0)
errorMsg.Text = "No artwork found or specified.";
else
{
//Fetch Single Artwork
ac.FetchForId(artWorkId);
if (ac.Count <= 0)
errorMsg.Text = "No artwork found or specified.";
else
{
//Parent repeater of page
rptSingleWork.DataSource = ac;
rptSingleWork.DataBind();
}
}
}
/// <summary>
/// Gallery/Genre/Subject/Reviews repeater nested within 'parentRptSingleWork_ItemDataBound'
/// </summary>
protected void parentRptSingleWork_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
//Gallery Repeater: Child
Repeater innerRptGallery = (Repeater)e.Item.FindControl("rptGallery");
GalleryCollection gl = new GalleryCollection(false);
gl.FetchForId(ac[0].GalleryID);
innerRptGallery.DataSource = gl;
innerRptGallery.DataBind();
//Genre Repeater: Child
Repeater innerRptGenre = (Repeater)e.Item.FindControl("rptGenre");
GenreCollection _gCol = new GenreCollection(false);
_gCol.FetchByArtWorkID(artWorkId);
innerRptGenre.DataSource = _gCol;
innerRptGenre.DataBind();
//Second Genre Repeater (For Related Artworks in Accordian): Child
Repeater innerRptRelatedArt = (Repeater)e.Item.FindControl("rptRelatedArt");
GenreCollection _gCol2 = new GenreCollection(false);
_gCol2.FetchByArtWorkID(artWorkId);
innerRptRelatedArt.DataSource = _gCol2;
innerRptRelatedArt.DataBind();
//Subject Repeater: Child
Repeater innerRptSubject = (Repeater)e.Item.FindControl("rptSubject");
SubjectCollection _sCol = new SubjectCollection(false);
_sCol.FetchByArtWorkId(artWorkId);
innerRptSubject.DataSource = _sCol;
innerRptSubject.DataBind();
//Sales Repeater (Using date created---> Order/OrderDetails)
Repeater innerRptOrders = (Repeater)e.Item.FindControl("rptSalesDateCreatedList");
OrdersCollection _ordCol = new OrdersCollection();
_ordCol.FetchByArtworkID(artWorkId);
innerRptOrders.DataSource = _ordCol;
innerRptOrders.DataBind();
//Getting the Reviews
artReview.FetchReviewsByArtWorkId(artWorkId);
if (!artReview.IsEmpty)
{
rptReview.DataSource = artReview;
rptReview.DataBind();
}
else emptyReview.Text = "There is no review for this artwork ";
}
/// <summary>
/// Grab Query String of ArtworkId
/// </summary>
protected int GetQueryString()
{
int artistId = 0;
bool flag = Int32.TryParse(Request["id"], out artistId);
return artistId;
}
/// <summary>
/// Ratings for Review, switches star image according to a new start rating passed in.
/// </summary>
/// <param name="num">New Rating to switch image.</param>
protected string MakeStars(string num)
{
int i = 0;
i = Convert.ToInt32(num);
string img = "";
switch (i)
{
case 1:
img = "Assets/nav-images/star1.gif";
break;
case 2:
img = "Assets/nav-images/star2.gif";
break;
case 3:
img = "Assets/nav-images/star3.gif";
break;
case 4:
img = "Assets/nav-images/star4.gif";
break;
case 5:
img = "Assets/nav-images/star5.gif";
break;
default:
img = "";
break;
}
return img;
}
/// <summary>
/// Fetches the average rating of an artwork.
/// </summary>
protected string AvgRateMakeStars(string artId)
{
int artIdInt = Convert.ToInt32(artId);
int rating = 0;
rating = artReview.FetchCurrentAvgRating(artIdInt);
return MakeStars(rating.ToString());
}
/// <summary>
/// Create new review and display. A user can only make a review to a given artwork once.
/// </summary>
protected void btnReview_Click(object sender, EventArgs e)
{
string reviewText = txtReview.Text;
ArtWorkReview awr = new ArtWorkReview();
awr.ArtWorkId = artWorkId;
MembershipUser reviewer = Membership.GetUser();
awr.Reviewer = reviewer.UserName;
awr.Comment = reviewText;
awr.Rating = Convert.ToInt32(rdiStar.SelectedValue);
awr.ReviewDate = DateTime.Today;
if (!HasCommented(reviewer.UserName))
{
awr.Insert();
}
Response.Redirect("SingleArtWork.aspx?id=" + artWorkId, true);
}
/// <summary>
/// Check: A user can only make a review to a given artwork once.
/// </summary>
/// <param name="user">logged in user</param>
private bool HasCommented(string user)
{
bool hasCommented = false;
ArtWorkReviewCollection awrc = new ArtWorkReviewCollection();
awrc.FetchReviewsByArtWorkId(artWorkId);
foreach (ArtWorkReview awr in awrc)
{
if (awr.Reviewer == user)
{
hasCommented = true;
}
}
return hasCommented;
}
/// <summary>
/// Deletes a review from an artwork.
/// </summary>
protected void btnDelete_Command(object sender, CommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
ArtWorkReview awr = new ArtWorkReview(id);
awr.Delete();
Response.Redirect("SingleArtWork.aspx?id=" + artWorkId, true);
}
}