-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNew.aspx.cs
More file actions
91 lines (76 loc) · 2.43 KB
/
Copy pathAddNew.aspx.cs
File metadata and controls
91 lines (76 loc) · 2.43 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
Users User;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadCateogries();
}
}
void GetUser()
{
string _user;
if (Session["LoggedInuser"] != null)
_user = Session["LoggedInuser"].ToString();
else
{
Response.Redirect("Login.aspx");
return;
}
int user;
int.TryParse(_user, out user);
User = new Users();
User.Id = user;
User.Get();
}
void LoadCateogries()
{
List<Category> Categories = Category.GetAll();
ddlCategory.Items.Add(new ListItem("Select Category", "-1"));
foreach(var cat in Categories)
{
ListItem item = new ListItem(cat.Name, cat.Id.ToString());
ddlCategory.Items.Add(item);
}
}
protected void btnSaveListing_Click(object sender, EventArgs e)
{
GetUser();
var _listingCode = txtItemCode.Text;
int listingCode;
int.TryParse(_listingCode, out listingCode);
var title = txtTitle.Text;
var _categoryId = ddlCategory.SelectedValue;
int categoryId;
int.TryParse(_categoryId, out categoryId);
var _price = txtPrice.Text;
int price;
int.TryParse(_price, out price);
string imageUrl = "";
if (uploadImage.HasFiles)
{
var uploadFile = uploadImage.PostedFile;
string _filename = listingCode.ToString();
string path = System.IO.Path.Combine(Server.MapPath("~/data/"), _filename + uploadFile.FileName);
uploadFile.SaveAs(path);
var fileUrl = _filename + uploadFile.FileName;
imageUrl = fileUrl;
}
var description = txtDescripiton.Text;
var location = txtLocation.Text;
var _lastDate = txtLastDate.Text;
DateTime lastDate;
lastDate =Convert.ToDateTime(_lastDate);
Listings Listing = new Listings(listingCode, title, categoryId, User.Id, price, description, location, lastDate, imageUrl);
Listing.Add();
Session["listingAdded"] = "New listing successfully added";
Response.Redirect("AddNew.aspx");
}
}