public JsonResult CheckPlaylistIdIsUsed(int id)
 {
     try
     {
         IScenarioItemService scenarioItemService = DependencyUtils.Resolve <IScenarioItemService>();
         IScenarioService     scenarioService     = DependencyUtils.Resolve <IScenarioService>();
         var scenarioItem    = scenarioItemService.Get().ToList();
         var scenario        = scenarioService.Get().ToList();
         var scenarioItemVMs = new List <Models.ScenarioItemVM>();
         var scenarioVMs     = new List <Models.ScenarioDetailVM>();
         //check playlistId have in playlistItem
         foreach (var item in scenarioItem)
         {
             if (item.PlaylistID == id)
             {
                 var b = new Models.ScenarioItemVM
                 {
                     ScenarioId = item.ScenarioID,
                 };
                 scenarioItemVMs.Add(b);
             }
         }
         // if scenarioItemVMs != null, get Scenario Title by ScenarioId
         if (scenarioItemVMs.Count != 0)
         {
             foreach (var item in scenarioItemVMs)
             {
                 foreach (var itemScenario in scenario)
                 {
                     if (item.ScenarioId == itemScenario.ScenarioID)
                     {
                         var b = new Models.ScenarioDetailVM
                         {
                             Title = itemScenario.Title,
                         };
                         scenarioVMs.Add(b);
                     }
                 }
             }
         }
         return(Json(new
         {
             isUsing = scenarioItemVMs.Count != 0,
             scenarioVMlist = scenarioVMs,
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> Get(Guid guid)
        {
            if (ModelState.IsValid)
            {
                Scenario record = await _scenarioService.Get(guid);

                if (record == null)
                {
                    return(new NoContentResult());
                }

                InitUserCredentials();

                if (record.CompanyGuid != CompanyGuid)
                {
                    return(Unauthorized());
                }

                return(Ok(_mapper.Map(record, new ScenarioResponse())));
            }

            return(new NoContentResult());
        }
        public async Task <IActionResult> Post([FromBody] ConditionRequest model)
        {
            Condition newRecord = null;

            if (ModelState.IsValid)
            {
                InitUserCredentials();

                Scenario scenario = await _scenarioService.Get(model.ScenarioGuid);

                if (scenario == null)
                {
                    return(BadRequest());
                }

                if (scenario.CompanyGuid != CompanyGuid)
                {
                    return(Unauthorized());
                }


                newRecord = new Condition
                {
                    Guid             = Guid.NewGuid(),
                    UserGuid         = UserGuid,
                    CompanyGuid      = CompanyGuid,
                    CreationTime     = DateTime.UtcNow,
                    CreationUserGuid = UserGuid,
                    ScenarioId       = scenario.ScenarioId,
                    ScenarioGuid     = scenario.Guid
                };

                newRecord = _mapper.Map(model, newRecord);

                try
                {
                    await _conditionService.Save(newRecord);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                    throw;
                }
            }

            return(CreatedAtAction(nameof(Post), _mapper.Map(newRecord, new ConditionResponse())));
        }