public static Scenario UpdateScenarioFlow(this IRepositoryAsync<Scenario> repository, int scenarioId, ScenarioResource put, ref CacheTracker cacheTracker) { Scenario scenario = repository.Query(k => k.ScenarioID == scenarioId).Select().First(); if (scenario.TopLevelFragmentID != put.TopLevelFragmentID) { scenario.TopLevelFragmentID = put.TopLevelFragmentID; cacheTracker.Recompute = true; } if (scenario.FlowID != put.ReferenceFlowID) { // changing reference flow means we have to re-traverse the fragment scenario.FlowID = put.ReferenceFlowID; int ffid = repository.GetRepository<FragmentFlow>().Queryable() .Where(k => k.FragmentID == scenario.TopLevelFragmentID) .Where(k => k.ParentFragmentFlowID == null) .Select(k => k.FragmentFlowID).First(); cacheTracker.FragmentFlowsTraverse.Add(ffid); } scenario.DirectionID = Convert.ToInt32(Enum.Parse(typeof(DirectionEnum),put.ReferenceDirection)); return scenario; }
public static Scenario PostScenario(this IRepositoryAsync<Scenario> repository, ScenarioResource post) { Scenario scenario = new Scenario() { ScenarioGroupID = post.ScenarioGroupID, Name = post.Name, Description = post.Description, ActivityLevel = post.ActivityLevel, TopLevelFragmentID = post.TopLevelFragmentID, FlowID = post.ReferenceFlowID, DirectionID = Convert.ToInt32(Enum.Parse(typeof(DirectionEnum),post.ReferenceDirection)), StaleCache = true }; scenario.ObjectState = ObjectState.Added; repository.Insert(scenario); return scenario; }
public static Scenario UpdateScenario(this IRepositoryAsync<Scenario> repository, Scenario scenario, ScenarioResource put) { if (put.Name != null) scenario.Name = put.Name; if (put.ActivityLevel != 0) scenario.ActivityLevel = put.ActivityLevel; if (!String.IsNullOrEmpty(put.Description)) scenario.Description = put.Description; scenario.ObjectState = ObjectState.Modified; repository.Update(scenario); return scenario; }
public HttpResponseMessage AddScenario([FromBody] ScenarioResource postdata) { int cloneScenario = Scenario.MODEL_BASE_CASE_ID; var cloneScenarioFromQuery = HttpUtility.ParseQueryString(Request.RequestUri.Query)["cloneScenario"]; if (!String.IsNullOrEmpty(cloneScenarioFromQuery)) cloneScenario = Convert.ToInt32(cloneScenarioFromQuery); int? authGroup = _ScenarioGroupService.CheckAuthorizedGroup(RequestContext); // need to authorize this if (authGroup != 0 && authGroup != null && _ScenarioGroupService.CanGet(RequestContext, cloneScenario)) { if (postdata == null) postdata = new ScenarioResource(); postdata = _ScenarioService.Queryable().Where(k => k.ScenarioID == cloneScenario) .Select(k => new ScenarioResource() { Name = String.IsNullOrEmpty(postdata.Name) ? "New Scenario" : postdata.Name, ActivityLevel = postdata.ActivityLevel == 0 ? k.ActivityLevel : postdata.ActivityLevel, TopLevelFragmentID = postdata.TopLevelFragmentID == 0 ? k.TopLevelFragmentID : postdata.TopLevelFragmentID, Description = String.IsNullOrEmpty(postdata.Description) ? k.Description : postdata.Description }).First(); int scenarioId = _ResourceService.AddScenario(postdata, (int)authGroup, cloneScenario); return Request.CreateResponse(HttpStatusCode.OK, _ResourceService.GetScenarios().Where(k => k.ScenarioID == scenarioId).FirstOrDefault()); } else return Request.CreateResponse(HttpStatusCode.Unauthorized); }