-
Notifications
You must be signed in to change notification settings - Fork 1
/
addrecipe.aspx.cs
189 lines (169 loc) · 7.15 KB
/
addrecipe.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
#region XD World Recipe V 2.8
// FileName: addrecipe.cs
// Author: Dexter Zafra
// Date Created: 5/28/2008
// Website: www.ex-designz.net
#endregion
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using XDRecipe.UI;
using XDRecipe.BL;
using XDRecipe.BL.Providers;
using XDRecipe.Common;
using XDRecipe.Model;
using XDRecipe.BL.Providers.Recipes;
using XDRecipe.Common.Utilities;
using XDRecipe.Security;
using XDRecipe.BL.Providers.User;
public partial class addrecipe : BasePage
{
protected void Page_Load(Object sender, EventArgs e)
{
Panel3.Visible = false;
lblwarning.Visible = true;
lblwarning.Text = "<img src='images/lock.gif' align='absmiddle'> You must login to submit a recipe. " + "<a href='registration.aspx'>Register here</a>";
if (Authentication.IsUserAuthenticated)
{
Panel3.Visible = true;
lblwarning.Visible = false;
lblusername.Text = UserIdentity.UserName;
Author.Value = UserIdentity.UserName;
LoadDropDownListCategory.LoadDropDownCategory("Recipe Category", CategoryID, "Select a Category");
}
}
public void Add_Recipe(Object s, EventArgs e)
{
if (Authentication.IsUserAuthenticated)
{
if (Page.IsValid)
{
Utility Util = new Utility();
RecipeRepository Recipe = new RecipeRepository();
//Filters harmful scripts from input string.
Recipe.RecipeName = Util.FormatTextForInput(Request.Form[Name.UniqueID]);
Recipe.Author = Util.FormatTextForInput(Request.Form[Author.UniqueID]);
Recipe.CatID = int.Parse(Request.Form[CategoryID.UniqueID]);
Recipe.Ingredients = Util.FormatTextForInput(Request.Form[Ingredients.UniqueID]);
Recipe.Instructions = Util.FormatTextForInput(Request.Form[Instructions.UniqueID]);
Recipe.UID = UserIdentity.UserID;
#region Form Input Validator
//Validate for empty recipe name
if (Recipe.RecipeName.Length == 0)
{
lbvalenght.Text = "<br>Error: Recipe Name is empty, please enter a recipe name.";
lbvalenght.Visible = true;
return;
}
if (Recipe.CatID == 0)
{
lbvalenght.Text = "<br>Error: You must select a category where you want your recipe to show.";
lbvalenght.Visible = true;
return;
}
//Validate for empty author name
if (Recipe.Author.Length == 0)
{
lbvalenght.Text = "<br>Error: Author Name is empty, please enter the author name";
lbvalenght.Visible = true;
return;
}
//Validate for empty ingredients
if (Recipe.Ingredients.Length == 0)
{
lbvalenght.Text = "<br>Error: Ingredients is empty, please enter an ingredients.";
lbvalenght.Visible = true;
return;
}
//Validate for empty instruction
if (Recipe.Instructions.Length == 0)
{
lbvalenght.Text = "<br>Error: Instructions is empty, please enter an instruction.";
lbvalenght.Visible = true;
return;
}
//Recipe name maximum of 50 char allowed
if (Recipe.RecipeName.Length > 50)
{
lbvalenght.Text = "<br>Error: Recipe Name is too long. Max of 50 characters.";
lbvalenght.Visible = true;
Name.Value = "";
return;
}
//Author name maximum of 25 char allowed
if (Recipe.Author.Length > 25)
{
lbvalenght.Text = "<br>Error: Author Name is too long. Max of 25 characters.";
lbvalenght.Visible = true;
Author.Value = "";
return;
}
//Ingredients maximum of 1000 char allowed - can be increase to max of 1000 char.
if (Recipe.Ingredients.Length > 500)
{
lbvalenght.Text = "<br>Error: Ingredients is too long. Max of 500 characters.";
lbvalenght.Visible = true;
return;
}
//Instruction maximum of 750 char allowed - can be increase to max of 2000 char
if (Recipe.Instructions.Length > 750)
{
lbvalenght.Text = "<br>Error: Instructions is too long. Max of 700 characters.";
lbvalenght.Visible = true;
return;
}
#endregion
if (RecipeImageFileUpload.HasFile)
{
int FileSize = RecipeImageFileUpload.PostedFile.ContentLength;
string contentType = RecipeImageFileUpload.PostedFile.ContentType;
//File type validation
if (!contentType.Equals("image/gif") &&
!contentType.Equals("image/jpeg") &&
!contentType.Equals("image/jpg") &&
!contentType.Equals("image/png"))
{
lbvalenght.Text = "<br>File format is invalid. Only gif, jpg, jpeg or png files are allowed.";
lbvalenght.Visible = true;
return;
}
// File size validation
if (FileSize > constant.RecipeImageMaxSize)
{
lbvalenght.Text = "<br>File size exceed the maximun allowed 30000 bytes";
lbvalenght.Visible = true;
return;
}
}
ImageUploadManager.UploadRecipeImage(Recipe, PlaceHolder1, GetRecipeImage.ImagePathDetail, constant.RecipeImageMaxSize, false);
if (Recipe.Add(Recipe) != 0)
{
JSLiteral.Text = "Error occured while processing your submit.";
return;
}
EmailRecipeSubmissionNotificationToAdministrator(Recipe.RecipeName);
Recipe = null;
Response.Redirect("confirmaddeditrecipe.aspx?mode=Added");
Util = null;
}
}
}
private void ValidateFileUploadContentType(FileUpload ImageUpload, int maxFileSize)
{
}
private void EmailRecipeSubmissionNotificationToAdministrator(string RecipeName)
{
EmailTemplate SendEMail = new EmailTemplate();
SendEMail.ItemName = RecipeName;
SendEMail.SendEmailAddRecipeNotify();
SendEMail = null;
}
}