public ActionResult Create(AdPostViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var ad = new AdPostModel { ClientName = viewModel.ClientName, Address = viewModel.Address, Date = DateTime.Today, Description = viewModel.Description, Price = viewModel.Price, Email = viewModel.Email }; _context.Ads.Add(ad); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public DataTable get(AdPostModel a) { SqlConnection conn = new SqlConnection(commonCode.conStr); conn.Open(); SqlCommand cmd = new SqlCommand("Pro_AdCRUD", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ad_Id", SqlDbType.Int).Value = a.ad_Id; cmd.Parameters.Add("@login_Id", SqlDbType.Int).Value = a.login_Id; cmd.Parameters.Add("@category_Id", SqlDbType.Int).Value = a.category_Id; cmd.Parameters.Add("@subCategory_Id", SqlDbType.Int).Value = a.subCategory_Id; cmd.Parameters.Add("@lastDate", SqlDbType.DateTime).Value = a.lastDate == Convert.ToDateTime("1/1/0001 12:00:00 AM") ? DateTime.Now : a.lastDate; cmd.Parameters.Add("@dataCount", SqlDbType.Int).Value = a.dataCount; cmd.Parameters.Add("@location_id", SqlDbType.NVarChar).Value = a.location_id; cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = a.mode; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); DataTable Dt = ds.Tables[0]; conn.Close(); if (Dt.Rows.Count > 0) { List <AdPostModel> fm = new List <AdPostModel>(); fm = commonCode.ConvertDataTable <AdPostModel>(Dt); for (int i = 0; i < fm.Count; i++) { fm[i].favlogins = listfav(fm[i].ad_Id); } Dt = ToDataTable(fm); } return(Dt); }
public int delete(AdPostModel a) { try { SqlConnection con = new SqlConnection(commonCode.conStr); con.Open(); SqlCommand cmd = new SqlCommand("Pro_AdCRUD", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ad_Id", SqlDbType.Int).Value = a.ad_Id; cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = a.mode; int s = (int)cmd.ExecuteNonQuery(); con.Close(); if (s < 0) { s = -1; } return(s); } catch (Exception ex) { return(-1); } }
public CommonModal Insert(AdPostModel a) { CommonModal e1 = new CommonModal(); SqlConnection conn = new SqlConnection(commonCode.conStr); conn.Open(); SqlCommand cmd = new SqlCommand("Pro_AdCRUD", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ad_Id", SqlDbType.Int).Value = a.ad_Id; cmd.Parameters.Add("@login_Id", SqlDbType.Int).Value = a.login_Id; cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = a.name; cmd.Parameters.Add("@price", SqlDbType.Int).Value = a.price; cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = a.description; cmd.Parameters.Add("@category_Id", SqlDbType.Int).Value = a.category_Id; cmd.Parameters.Add("@subCategory_Id", SqlDbType.Int).Value = a.subCategory_Id; cmd.Parameters.Add("@companyName", SqlDbType.NVarChar).Value = a.companyName; cmd.Parameters.Add("@contactPerson", SqlDbType.NVarChar).Value = a.contactPerson; cmd.Parameters.Add("@mobileNo", SqlDbType.NVarChar).Value = a.mobileNo; cmd.Parameters.Add("@landlineNo", SqlDbType.NVarChar).Value = a.landlineNo; cmd.Parameters.Add("@Parking", SqlDbType.NVarChar).Value = a.Parking; cmd.Parameters.Add("@Features", SqlDbType.NVarChar).Value = a.Features; cmd.Parameters.Add("@SuperBuildUparea", SqlDbType.NVarChar).Value = a.SuperBuildUparea; cmd.Parameters.Add("@PlotArea", SqlDbType.NVarChar).Value = a.PlotArea; cmd.Parameters.Add("@CallibrateDate", SqlDbType.NVarChar).Value = a.CallibrateDate; cmd.Parameters.Add("@CallibrateMachine", SqlDbType.NVarChar).Value = a.CallibrateMachine; cmd.Parameters.Add("@GSTNumber", SqlDbType.NVarChar).Value = a.GSTNumber; cmd.Parameters.Add("@PlantCapacity", SqlDbType.NVarChar).Value = a.PlantCapacity; cmd.Parameters.Add("@companyAddress", SqlDbType.NVarChar).Value = a.companyAddress; cmd.Parameters.Add("@plantCompany", SqlDbType.NVarChar).Value = a.plantCompany; cmd.Parameters.Add("@modelYear", SqlDbType.NVarChar).Value = a.modelYear; cmd.Parameters.Add("@serialNo", SqlDbType.NVarChar).Value = a.serialNo; cmd.Parameters.Add("@newCost", SqlDbType.Int).Value = a.newCost; cmd.Parameters.Add("@expectCost", SqlDbType.Int).Value = a.expectCost; cmd.Parameters.Add("@location", SqlDbType.NVarChar).Value = a.location; cmd.Parameters.Add("@location_id", SqlDbType.NVarChar).Value = a.location_id; cmd.Parameters.Add("@comment", SqlDbType.NVarChar).Value = a.comment; cmd.Parameters.Add("@image1", SqlDbType.NVarChar).Value = a.image1; cmd.Parameters.Add("@payment_status", SqlDbType.Int).Value = a.payment_status; cmd.Parameters.Add("@category", SqlDbType.NVarChar).Value = a.category; cmd.Parameters.Add("@no_labours", SqlDbType.Int).Value = a.no_labours; cmd.Parameters.Add("@available", SqlDbType.NVarChar).Value = a.available; cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = a.mode; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); DataTable Dt = ds.Tables[0]; DataTable Dt1 = ds.Tables[1]; conn.Close(); if (Dt.Rows.Count > 0) { e1.ResponseStatus = Dt1.Rows[0]["status"].ToString(); e1.ResponseMessage = Dt1.Rows[0]["MSG"].ToString(); e1.data = Dt; } else { e1.ResponseStatus = "False"; e1.ResponseMessage = "Ad Posting Failed"; } return(e1); }
public DataTable search(AdPostModel a) { SqlConnection conn = new SqlConnection(commonCode.conStr); conn.Open(); SqlCommand cmd = new SqlCommand("Pro_searchalltables", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@location_id", SqlDbType.NVarChar).Value = a.location_id; cmd.Parameters.Add("@category_Id", SqlDbType.Int).Value = a.category_Id; cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = a.mode; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); DataTable Dt = ds.Tables[0]; conn.Close(); if (Dt.Rows.Count > 0) { if (a.category_Id == 26) { List <AdJobModel> fm = new List <AdJobModel>(); fm = commonCode.ConvertDataTable <AdJobModel>(Dt); for (int i = 0; i < fm.Count; i++) { fm[i].favlogins = listfavjob(fm[i].Job_Id); } Dt = ToDataTable(fm); } else if (a.category_Id == 7) { Dt.Columns.Add("favlogins", typeof(System.Int32[])); foreach (DataRow row in Dt.Rows) { row["favlogins"] = new int[0]; } } else { List <AdPostModel> fm = new List <AdPostModel>(); fm = commonCode.ConvertDataTable <AdPostModel>(Dt); for (int i = 0; i < fm.Count; i++) { fm[i].favlogins = listfav(fm[i].ad_Id); } Dt = ToDataTable(fm); } } //if (Dt.Rows.Count > 0) //{ // Dt.Columns.Add("favlogins", typeof(System.Int32[])); // foreach (DataRow n in Dt.Rows) // { // if (Convert.ToInt32(n["category_Id"]) == 26) // { // n["favlogins"] = listfavjob(Convert.ToInt32(n["Job_Id"])); // } // else if (Convert.ToInt32(n["category_Id"]) != 7) // { // n["favlogins"] = ""; // } // else // { // n["favlogins"] = listfav(Convert.ToInt32(n["ad_Id"])); // } // } //} return(Dt); }