public void savelog(spView_admin_strategicplansearchGetAll_Result value) { try { SpActivityLog existlog = new SpActivityLog(); //if (string.IsNullOrEmpty(existlog.ActivityLogCode.ToString()) || existlog.ActivityLogCode == 0) //{ // var newCode = NewCodeLog(); // existlog.ActivityLogCode = ++newCode; //} ////Save Old Record //existlog.SpAStrategyCode = Convert.ToInt32(exist.sp_a_strategy_code); //existlog.SpAActivity = exist.sp_a_activity; //existlog.SpAOutput = exist.sp_a_output; //existlog.SpATimeframeYear = Convert.ToInt32(exist.sp_a_timeframe_code); //existlog.SpATimeframeYear = Convert.ToInt32(exist.sp_a_timeframe_year); //existlog.SpAPerformanceIndicator = exist.sp_a_performance_Indicator; //existlog.SpAEstimatedCostMillions = exist.sp_a_estimated_cost_millions; //existlog.SpAIsVisible = exist.sp_a_is_visible; //existlog.Deleted = false; //Save New Record existlog.SpAStrategyCodeNew = Convert.ToInt32(value.sp_a_strategy_code); existlog.SpAActivityNew = value.sp_a_activity; existlog.SpAOutputNew = value.sp_a_output; existlog.SpATimeframeYearNew = Convert.ToInt32(value.sp_a_timeframe_code); existlog.SpATimeframeYearNew = Convert.ToInt32(value.sp_a_timeframe_year); existlog.SpAPerformanceIndicatorNew = value.sp_a_performance_Indicator; existlog.SpAEstimatedCostMillionsNew = value.sp_a_estimated_cost_millions; existlog.SpAIsVisibleNew = value.sp_a_is_visible; existlog.Deleted = false; existlog.UpdatedBy = userInfor.GetUser().Identity.Name; existlog.UpdatedDate = DateTime.Now; //context.Entry(existlog).State = EntityState.Modified;//Update record in original table //context.Entry(existlog).CurrentValues.SetValues(value); //context.Entry(existlog).State = EntityState.Modified; //Update record in log table context.SpActivityLog.Add(existlog); context.SaveChanges(); //Throws an error here } catch { } }
public ActionResult BatchUpdateActivities([FromBody] CRUDModel <spView_admin_strategicplansearchGetAll_Result> value) { //var recordssaved = 0; if (value.Changed != null && value.Changed.Count() > 0) { foreach (var temp in value.Changed) { var exist = context.SpActivity.FirstOrDefault(o => o.SpAActivityCode == temp.sp_a_activity_code); SpActivityLog existlog = new SpActivityLog(); //var existlog = context.SpActivityLog.FirstOrDefault(o => o.ActivityLogCode == temp.sp_a_activity_code); if (exist != null) { if (string.IsNullOrEmpty(existlog.ActivityLogCode.ToString()) || existlog.ActivityLogCode == 0) { var newCode = NewCodeLog(); existlog.ActivityLogCode = ++newCode; } //Save Old Record existlog.SpAStrategyCode = Convert.ToInt32(exist.SpAStrategyCode); existlog.SpAActivity = exist.SpAActivity; existlog.SpAOutput = exist.SpAOutput; existlog.SpATimeframeYear = Convert.ToInt32(exist.SpATimeframeCode); existlog.SpATimeframeYear = Convert.ToInt32(exist.SpATimeframeYear); existlog.SpAPerformanceIndicator = exist.SpAPerformanceIndicator; existlog.SpAEstimatedCostMillions = exist.SpAEstimatedCostMillions; existlog.SpAIsVisible = exist.SpAIsVisible; existlog.Deleted = exist.Deleted; //Into New existlog.SpAStrategyCodeNew = Convert.ToInt32(temp.sp_a_strategy_code); existlog.SpAActivityNew = temp.sp_a_activity; existlog.SpAOutputNew = temp.sp_a_output; existlog.SpATimeframeCodeNew = Convert.ToInt32(temp.sp_a_timeframe_code); existlog.SpATimeframeYearNew = Convert.ToInt32(temp.sp_a_timeframe_year); existlog.SpAPerformanceIndicatorNew = temp.sp_a_performance_Indicator; existlog.SpAEstimatedCostMillionsNew = temp.sp_a_estimated_cost_millions; existlog.SpAIsVisibleNew = temp.sp_a_is_visible; //existlog.Deleted = temp.Deleted; context.SpActivityLog.Add(existlog); context.SaveChanges(); //Save into sp_activity exist.SpAStrategyCode = Convert.ToInt32(temp.sp_a_strategy_code); exist.SpAActivity = temp.sp_a_activity; exist.SpAOutput = temp.sp_a_output; exist.SpATimeframeCode = Convert.ToInt32(temp.sp_a_timeframe_code); exist.SpATimeframeYear = Convert.ToInt32(temp.sp_a_timeframe_year); exist.SpAPerformanceIndicator = temp.sp_a_performance_Indicator; exist.SpAEstimatedCostMillions = temp.sp_a_estimated_cost_millions; exist.SpAIsVisible = temp.sp_a_is_visible; exist.Deleted = temp.Deleted; context.Entry(exist).State = EntityState.Modified;//Update record in original table context.SaveChanges(); } //return Json(value.Value); //return Content("") /*RedirectToAction("DataSourceCommonMarket")*/; } } return(Json(value.Value)); }