Beispiel #1
0
        public async Task <int> AddAsync(SceneAddModel scene)
        {
            var project = _context.Projects.FirstOrDefault(c => c.ProjectId == scene.ProjectId);

            if (project == null)
            {
                throw new ExpectException("Could not find Project data which ProjectId equal to " + scene.ProjectId);
            }

            //SceneName must be unique
            var checkData = await _context.Scenes.Where(s => s.SceneName == scene.SceneName).ToListAsync();

            if (checkData.Count > 0)
            {
                throw new ExpectException("The data which SceneName equal to '" + scene.SceneName + "' already exist in system");
            }


            //Get UserInfo
            var user  = _loginUser.GetLoginUserInfo();
            var model = new Scene
            {
                ProjectId  = scene.ProjectId,
                SceneName  = scene.SceneName,
                Enable     = scene.Enable,
                Creator    = user.UserName,
                CreateDate = DateTime.Now
            };

            _context.Scenes.Add(model);
            await _context.SaveChangesAsync();

            return(model.SceneId);
        }
        public async Task <IActionResult> AddAsync([FromBody] SceneAddModel mScene)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelStateError()));
            }

            var sceneId = await _sceneRepository.AddAsync(mScene);

            return(CreatedAtRoute("GetBySceneIdAsync", new { controller = "Scenes", sceneId = sceneId }, mScene));
        }