protected void ButtonSaveDeals_Click(object sender, EventArgs e) { string imagePath = "~/images/" + DealImage.FileName; DealImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("Insert into promotionalDeals(dealName,dealImage,dealDescription,restaurantID) values('" + TextBoxDealName.Text + "','" + imagePath + "','" + TextBoxDealDescription.Text + "','" + Session["restaurantID"] + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); Response.Redirect("Deals.aspx"); }
public ActionResult CreateDeal(DealViewModel _deal, IEnumerable <HttpPostedFileBase> files) { var userId = Convert.ToInt32(Session[KeyList.SessionKeys.UserID].ToString()); DealViewModel dropdown = DropDownForstore(userId); try { if (ModelState.IsValid) { var stores = storeService.Get(x => x.UserId == userId); var image = files.IsValidImageList(false); if (image == false) { ViewBag.message = "Image is required and should only have .pdf,.jpeg,.jpg,.gif"; return(View(dropdown)); } else { foreach (var store in stores) { if (store.StoreId == _deal.StoreId) { var strikePrice = _deal.Price - (decimal)((double)_deal.Discount / 100 * _deal.Price); if (store.IsValid == true) { Deal deal = new Deal { StoreId = _deal.StoreId, Description = _deal.Description, Title = _deal.Title, ValidTill = _deal.ValidTill.Date, Price = _deal.Price, Discount = _deal.Discount, StrikePrice = strikePrice, AddedOn = DateTime.Now, IsDeleted = false, IsDealFree = _deal.IsDealfree }; int id = dealServices.CreateDeal(deal); foreach (var item in files) { var path = item.SaveImageFile(); DealImage _dealImage = new DealImage() { DealId = id, DealImage1 = path }; dealImageServices.CreateDealImage(_dealImage); } } else { ViewBag.message = "your store registration certificate is not valid"; return(View(dropdown)); } } } } Logs GenerateLog = new Logs(); GenerateLog.CreateLog(userId, KeyList.LogMessages.EditStore); return(RedirectToAction("Deal")); } return(View(dropdown)); } catch (Exception e) { return(View(dropdown)); } }