コード例 #1
0
        public async Task <IActionResult> UpdateAsync([FromBody] MovieDataModel model)
        {
            var result = await repository.UpdateAsync(model);

            if (result.Ok)
            {
                return(Ok(result));
            }

            return(BadRequest(result.Message));
        }
コード例 #2
0
        public async Task <Result> CreateAsync(MovieDataModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.MovieId))
            {
                return(new Result(false, "MovieId should not be provided during creation"));
            }

            model.MovieId  = Convert.ToString(Guid.NewGuid());
            model.CreateAt = DateTime.UtcNow;

            await collection.InsertOneAsync(model);

            return(new Result(true));
        }
コード例 #3
0
        public async Task <Result> UpdateAsync(MovieDataModel model)
        {
            if (string.IsNullOrWhiteSpace(model.MovieId))
            {
                return(new Result(false, "MovieId must be provided during update"));
            }

            var document = await GetAsync(model.MovieId);

            if (document == null)
            {
                return(new Result(false, "Movie not found"));
            }

            model.CreateAt = document.CreateAt;

            await collection.ReplaceOneAsync
            (
                Builders <MovieDataModel> .Filter.Eq(doc => doc.MovieId, model.MovieId),
                model
            );

            return(new Result(true));
        }