protected void btnSubmit_Click(object sender, EventArgs e) { try { SPSecurity.RunWithElevatedPrivileges(delegate() { if (Page.IsValid) { SetProgress_DAL.Update_Objectives("AccPercent", tblObjectives); SetProgress_DAL.Save_or_Update_Objs_ProgressNote(intended_Emp.login_name_to_convert_to_SPUser, Active_Rate_Goals_Year, txtNote1.Text); Show_Success_Message("تم حفظ الأهداف بنجاح"); WFStatusUpdater.Change_State_to(WF_States.Objectives_ProgressSet_by_Emp, strEmpDisplayName, Active_Rate_Goals_Year); Emailer.Send_Objs_ProgressSetByEmp_Email_to_DM(intended_Emp, Active_Rate_Goals_Year); } }); } catch (Exception) { } }
private void SaveToSP() { SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); spWeb.AllowUnsafeUpdates = true; SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "SkillsRating")); #region Remove any previous Ratings of same Emp and Year, by updating "deleted" to 1 SPQuery qry = new SPQuery(); qry.Query = @" <Where> <And> <Eq> <FieldRef Name='Emp' /> <Value Type='User'>" + strEmpDisplayName + @"</Value> </Eq> <Eq> <FieldRef Name='ObjYear' /> <Value Type='Text'>" + Active_Rate_Goals_Year + @"</Value> </Eq> </And> </Where>"; qry.ViewFieldsOnly = true; qry.ViewFields = @"<FieldRef Name='ID' />"; SPListItemCollection listItems = spList.GetItems(qry); foreach (SPListItem item in listItems) { SPListItem itemToUpdate = spList.GetItemById(item.ID); itemToUpdate["deleted"] = 1; itemToUpdate.Update(); } #endregion Remove any previous Ratings of same Emp and Year, by updating "deleted" to 1 #region Add the new Ratings foreach (GridViewRow row in gvw_Std_Skills.Rows) { SPListItem oListItem = spList.AddItem(); oListItem["Title"] = row.Cells[0].Text; var dd = row.Cells[1].FindControl("ddl_Std_Skill_Rating") as DropDownList; oListItem["Rating"] = int.Parse(dd.SelectedValue); oListItem["Emp"] = SPContext.Current.Web.EnsureUser(intended_Emp.login_name_to_convert_to_SPUser); oListItem["ObjYear"] = Active_Rate_Goals_Year; oListItem.Update(); } #endregion Add the new Ratings spWeb.AllowUnsafeUpdates = false; foreach (GridViewRow row in gvwRate.Rows) { DropDownList ddlObjRating = row.FindControl("ddlObjRating") as DropDownList; tblObjectives.Rows[row.RowIndex]["AccRating"] = ddlObjRating.SelectedItem.Text; } SetProgress_DAL.Update_Objectives("AccRating", tblObjectives); EvalNotes evalnotes = new EvalNotes(); evalnotes.ReasonForRating1or5 = txtNote_ReasonForRating1or5.Text; evalnotes.RecommendedCourses = txtNote_RecommendedCourses.Text; SetProgress_DAL.Save_or_Update_Objs_EvalNotes(intended_Emp.login_name_to_convert_to_SPUser, Active_Rate_Goals_Year, evalnotes); }); }