protected void grdActivities_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { using (DefaultConnectionAL conn = new DefaultConnectionAL()) { var user = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId(); Int32 ActivityID = Convert.ToInt32(grdActivities.DataKeys[e.RowIndex].Values["id"]); var activityItem = (from a in conn.activities where a.id == ActivityID select a).FirstOrDefault(); //save conn.activities.Remove(activityItem); conn.SaveChanges(); //redirect to updated departments page GetActivities(); } } catch (Exception e2) { Response.Redirect("~/error.aspx"); } }
protected void btnLog_Click(object sender, EventArgs e) { try { //connect using (DefaultConnectionAL conn = new DefaultConnectionAL()) { activity objA = new activity(); if (!String.IsNullOrEmpty(Request.QueryString["ActivityID"])) { int ActivityID = Convert.ToInt32(Request.QueryString["ActivityID"]); objA = (from a in conn.activities where a.id == ActivityID select a).FirstOrDefault(); //Populate the activity from the input form objA.activity_name = txtActivityName.Text; } else { //Populate the activity from the input form objA.account_id = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId(); objA.activity_name = txtActivityName.Text; objA.duration = lblTimeHidden.Text; } if (String.IsNullOrEmpty(Request.QueryString["ActivityID"])) { //add conn.activities.Add(objA); } conn.SaveChanges(); Response.Redirect("activitylog.aspx"); } } catch (System.IO.IOException e3) { Server.Transfer("/error.aspx", true); } }