示例#1
0
        public virtual async Task <bool> AcceptChanges(string commonidentifier, string actionKey, string actionInstanceId, int registerEnvironment, [FromBody] string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                throw new ArgumentException("Content was null");
            }

            var surveillanceAction = Di.GetInstance <ISurveillanceAction>(actionKey);

            if (!surveillanceAction.ValidJson(content))
            {
                throw new ArgumentException("Content was not in the right format given actionkey: " + actionKey);
            }

            var latestResultDb = Di.GetInstance <IJsonStorage <LatestSurveillanceResult> >();
            var latestResult   = await LatestSurveillanceResult.GetLatestSurveillanceResult(actionKey, actionInstanceId,
                                                                                            GetTeam(), latestResultDb);

            if (latestResult != null)
            {
                await latestResultDb.Delete(latestResult);
            }

            var claimDb = Di.GetInstance <ITableStorageDb <SurveilledItem> >();

            var surveillance = await SurveilledItem.Get(actionKey, actionInstanceId, GetTeam(), claimDb);

            surveillance.ContentAsJson = content;
            surveillance.ClaimedWhen   = DateTime.Now;

            await claimDb.InsertAsync(surveillance, true, true);

            return(true);
        }
示例#2
0
        public virtual async Task <bool> Off(string commonidentifier, string actionKey, string actionInstanceId, int registerEnvironment)
        {
            var claimDb = Di.GetInstance <ITableStorageDb <SurveilledItem> >();

            var element = await SurveilledItem.Get(actionKey, actionInstanceId, GetTeam(), claimDb);

            if (element == null)
            {
                return(false);
            }

            claimDb.DeleteMany(new [] { element });

            var latestResultDb = Di.GetInstance <IJsonStorage <LatestSurveillanceResult> >();
            var latestResult   = await LatestSurveillanceResult.GetLatestSurveillanceResult(actionKey, actionInstanceId, GetTeam(), latestResultDb);

            if (latestResult != null)
            {
                await latestResultDb.Delete(latestResult);
            }

            var team = GetTeam().Id;
            var anyOtherSurveillanceItems = TriggerAllSurveillanceItems <RegisterPersonModel> .GetAllSurveillanceItems(Di)
                                            .Any(item => !string.IsNullOrEmpty(item.CommonIdentifier) && item.CommonIdentifier == commonidentifier && item.TeamProjectInt == team);

            if (!anyOtherSurveillanceItems)
            {
                await _personIndex.RemoveFromPropertyList(commonidentifier, "Teams", team.ToString());
            }

            return(true);
        }