public ActionResult Create() { var categoryModel = new categoryModel(); IniMainCategories(null, ref categoryModel); return(View(categoryModel)); }
public ActionResult Edit(categoryModel data) { var updateCategory = new Category { ID = data.Id, Name = data.Name, Parnt_Id = data.ParentId }; var result = categoryService.Update(updateCategory); if (result == -2) { ViewBag.Message = " Category Name is Exists"; IniMainCategories(data.Id, ref data); return(View(data)); } else if (result > 0) { ViewBag.Success = true; ViewBag.Message = $"Category ({data.Id}) Update Successfully"; } else { ViewBag.Message = "an Error occurred!"; } IniMainCategories(data.Id, ref data); return(View(data)); }
private void IniMainCategories(int?categoryToExclude, ref categoryModel categorymodel) { var categoryList = categoryService.ReadAll(); if (categoryToExclude != null) { var currentCategory = categoryList.Where(c => c.ID == categoryToExclude).FirstOrDefault(); categoryList.Remove(currentCategory); } categorymodel.MainCategories = new SelectList(categoryList, "ID", "Name"); }
///Delete Procedure Data Controller public int deleteCategory(categoryModel currentCategory) { int success; DbCommand sp_ct2DeleteCategory = db.GetStoredProcCommand("sp_ct2DeleteCategory"); db.AddInParameter(sp_ct2DeleteCategory, "@categoryID", SqlDbType.Int, currentCategory.categoryID); success = sp_ct2DeleteCategory.ExecuteNonQuery(); return(success); }
public ActionResult Delete(int?id) { if (id != null) { var category = categoryService.ReadById(id.Value); var categoryInfo = new categoryModel { Id = category.ID, Name = category.Name, ParentName = category.Category2?.Name }; return(View(categoryInfo)); } return(RedirectToAction("Index")); }
public ActionResult Create(categoryModel data) { var newCategory = mapper.Map <Category>(data); newCategory.Category2 = null; int creationResult = categoryService.Create(newCategory); if (creationResult == -2) { IniMainCategories(null, ref data); ViewBag.Message = " Category Name is Exists"; return(View(data)); } return(RedirectToAction("Index")); }
/// Create Procedure Data Controller public int createCategory(categoryModel currentCategory) { int success = 0; DbCommand sp_ct2CreateCategory = db.GetStoredProcCommand("sp_Createct2Category"); sp_ct2CreateCategory.Connection = db.CreateConnection(); sp_ct2CreateCategory.Connection.Open(); db.AddInParameter(sp_ct2CreateCategory, "@categoryParentID", SqlDbType.Int, currentCategory.categoryParentID); db.AddInParameter(sp_ct2CreateCategory, "@isUserDefined", SqlDbType.Bit, currentCategory.isUserDefined); db.AddInParameter(sp_ct2CreateCategory, "@isDeleted", SqlDbType.Bit, currentCategory.isDeleted); db.AddInParameter(sp_ct2CreateCategory, "@dateAdded", SqlDbType.DateTime, currentCategory.dateAdded); db.AddInParameter(sp_ct2CreateCategory, "@categoryDescription", SqlDbType.VarChar, currentCategory.categoryDescription); //sp_ct2CreateCategory.Connection.; success = sp_ct2CreateCategory.ExecuteNonQuery(); return(success); }
public ActionResult Edit(int?id) { if (id == null || id == 0) { return(RedirectToAction("Index", "Home")); } var currentCategory = categoryService.ReadById(id.Value); if (currentCategory == null) { return(HttpNotFound($"This Category ({id}) Not Found")); } var CategoryModel = new categoryModel { Id = currentCategory.ID, Name = currentCategory.Name, ParentId = currentCategory.Parnt_Id }; IniMainCategories(currentCategory.ID, ref CategoryModel); return(View(CategoryModel)); }
public ActionResult Create(doctorModel ob, categoryModel ob2, HttpPostedFileBase file) { SqlConnection con = new SqlConnection(constring); String q = "INSERT into DoctorInfo(DoctorName,Descriptions,Speciality,Imgid,Chamber1,Chamber2,Chamber3,Phone,Email) " + "values(@name,@Description,@Speciality,@imgid,@Chamber1,@Chamber2,@Chamber3,@ContactNo,@Email)"; SqlCommand cmd = new SqlCommand(q, con); con.Open(); cmd.Parameters.AddWithValue("@name", ob.name); cmd.Parameters.AddWithValue("@Description", ob.Description); cmd.Parameters.AddWithValue("@Speciality", ob.Speciality); SqlParameter chamber1 = cmd.Parameters.AddWithValue("@Chamber1", ob.Chamber1); if (ob.Chamber1 == null) { chamber1.Value = "N/A"; } SqlParameter chamber2 = cmd.Parameters.AddWithValue("@Chamber2", ob.Chamber2); if (ob.Chamber2 == null) { chamber2.Value = "N/A"; } SqlParameter chamber3 = cmd.Parameters.AddWithValue("@Chamber3", ob.Chamber3); if (ob.Chamber3 == null) { chamber3.Value = "N/A"; } cmd.Parameters.AddWithValue("@ContactNo", ob.ContactNo); cmd.Parameters.AddWithValue("@Email", ob.Email); if (file != null && file.ContentLength > 0) { string filename = Path.GetFileName(file.FileName); string imgpath = Path.Combine(Server.MapPath("/doctorimages/"), filename); file.SaveAs(imgpath); } cmd.Parameters.AddWithValue("@imgid", "/doctorimages/" + file.FileName); cmd.ExecuteNonQuery(); con.Close(); String q2 = "Select top 1 DoctorId from DoctorInfo order by DoctorId desc"; SqlCommand cmd2 = new SqlCommand(q2, con); con.Open(); int doctorid = Convert.ToInt32(cmd2.ExecuteScalar()); cmd2.ExecuteNonQuery(); con.Close(); String q3 = "INSERT into Category(DoctorId,Category) " + "values(@doctorid,@category)"; SqlCommand cmd3 = new SqlCommand(q3, con); con.Open(); cmd3.Parameters.AddWithValue("@doctorid", doctorid); cmd3.Parameters.AddWithValue("@category", ob2.category); cmd3.ExecuteNonQuery(); con.Close(); return(RedirectToAction("AdminDoctorInfo")); }