public ActionResult Delete(Student model) { try { // TODO: Add delete logic here Student theStudent = work.StudentRepository.GetByID(model.StudentID); string theUserString = theStudent.UserID;// user.UserName; var user = Membership.GetUser(theUserString); _rolesService.RemoveFromAllRoles(user); _userService.Delete(user); work.StudentRepository.Delete(theStudent); work.Save(); // DELETE FROM table_name WHERE some_column=some_value string con = System.Configuration.ConfigurationManager.ConnectionStrings["sdDatabase"].ConnectionString; SqlConnection conn = new System.Data.SqlClient.SqlConnection(con); SqlCommand updateCmd = new SqlCommand("DELETE FROM Users " + //"SET LastActivityDate = @LastActivityDate " + "WHERE UserName = @UserName", conn); // updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).AddMinutes(-10); updateCmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = theUserString; //updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName; conn.Open(); updateCmd.ExecuteNonQuery(); conn.Close(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(Student model) { try { // TODO: Add update logic here TryUpdateModel(model); if (ModelState.IsValid) { work.StudentRepository.Update(model); work.Save(); } return RedirectToAction("Index"); } catch { List<SelectListItem> theItem3 = new List<SelectListItem>(); string[] theRoles = Roles.GetAllRoles(); theItem3.Add(new SelectListItem() { Text = "None", Value = "" }); foreach (var role in theRoles) { theItem3.Add(new SelectListItem() { Text = role, Value = role }); } ViewData["Role"] = theItem3; return View(); } }