private void PerformRowCommand() { object sender = Session["senderForAdj"]; GridViewCommandEventArgs e = (GridViewCommandEventArgs)Session["gvCommandEvent"]; try { if (e.CommandName.Equals("Approve")) { Control ctl = e.CommandSource as Control; GridViewRow currentRow = ctl.NamingContainer as GridViewRow; object id = gvPendingAdjutment.DataKeys[currentRow.RowIndex].Value as object; string adjustmentCode = null; if (id != null) { adjustmentCode = id.ToString(); } string price = (currentRow.FindControl("lblPrice") as Label).Text; TextBox tbxHeadRemarks = (currentRow.FindControl("tbxHeadRemarks") as TextBox); string approveStatus = "Approve"; //This method will use when we login to application and this method can acess who logged in and can get the user //var user = HttpContext.Current.GetOwinContext().Get<ApplicationUserManager>().FindById(User.Identity.GetUserName()); //this is getting username from user.And Use this to get user name instead hardcode value. //string userName = user.UserName; //Adjustment ad = new Adjustment(); //ad.AdjustmentCode = adjustmentCode; Adjustment ad = storeSpController.GetAdjustment(adjustmentCode); ad.HeadRemarks = tbxHeadRemarks.Text; ad.Status = approveStatus; ad.ApprovedBy = Context.User.Identity.GetUserName(); ad.DateApproved = DateTime.Now; storeSpController.UpdateAdjustmentBySupervisor(ad); StationeryCatalogue stationery = storeSpController.GetStationeryCatalogue(ad.ItemCode); stationery.Stock += ad.AdjustmentQuant; storeSpController.UpdateStationery(stationery); PopulateGridViewForSupervisor(); lblSuccessMsg.Text = "Adjustment request Approved"; lblErrorMsg.Text = ""; //send email string fromEmail = emailController.GetUserEmail(Context.User.Identity.Name); string password = txtPassword.Text; string username = Context.User.Identity.Name; try { emailController.AdjApproveRejectSendEmail(fromEmail, password, username, ad); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Adjustment have been successfully approved! Email notifications have been sent successfully!')", true); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Adjustment have been successfully approved! However an error has occurred when sending email!')", true); } } else { Control ctlReject = e.CommandSource as Control; GridViewRow currentRowOfreject = ctlReject.NamingContainer as GridViewRow; object id2 = gvPendingAdjutment.DataKeys[currentRowOfreject.RowIndex].Value as object; string adjustmentCodeOfreject = null; if (id2 != null) { adjustmentCodeOfreject = id2.ToString(); } TextBox tbxHeadRemarksOfReject = (currentRowOfreject.FindControl("tbxHeadRemarks") as TextBox); string rejectstatus = "Reject"; //This method will use when we login to application and this method can acess who logged in and can get the user var user = HttpContext.Current.GetOwinContext().Get <ApplicationUserManager>().FindById(User.Identity.GetUserName()); //this is getting username from user.And Use this to get user name instead hardcode value. //string userName = user.UserName; //Adjustment adOFReject = new Adjustment(); //adOFReject.AdjustmentCode = adjustmentCodeOfreject; //adOFReject.HeadRemarks = tbxHeadRemarksOfReject.Text; //adOFReject.Status = rejectstatus; //// ad.ApprovedBy = userName;//Use this when we get successful login. //adOFReject.ApprovedBy = "*****@*****.**"; //adOFReject.DateApproved = DateTime.Now.Date; Adjustment adOFReject = storeSpController.GetAdjustment(adjustmentCodeOfreject); adOFReject.HeadRemarks = tbxHeadRemarksOfReject.Text; adOFReject.Status = rejectstatus; adOFReject.ApprovedBy = Context.User.Identity.GetUserName(); adOFReject.DateApproved = DateTime.Now; storeSpController.UpdateAdjustmentBySupervisor(adOFReject); PopulateGridViewForSupervisor(); lblSuccessMsg.Text = ""; lblErrorMsg.Text = "Adjustment request rejected"; //send email string fromEmail = emailController.GetUserEmail(Context.User.Identity.Name); string password = txtPassword.Text; string username = Context.User.Identity.Name; try { emailController.AdjApproveRejectSendEmail(fromEmail, password, username, adOFReject); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Adjustment have been successfully rejected! Email notifications have been sent successfully!')", true); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Adjustment have been successfully rejected! However an error has occurred when sending email!')", true); } } } catch (Exception ex) { lblSuccessMsg.Text = ""; lblErrorMsg.Text = ex.Message; } }