Beispiel #1
0
        public IActionResult Put(int id, [FromBody] Cinema cinema)
        {
            if (cinema == null)
            {
                return(NotFound(new { status = "error", message = "Cinema information cannot be empty" }));
            }
            if (cinema.Id != id)
            {
                return(NotFound(new { status = "error", message = "Cinema ID and the request ID must match" }));
            }

            if (ModelState.IsValid)
            {
                var updatedCinema = repo.Update(cinema);
                if (updatedCinema != null)
                {
                    return(Ok(new
                    {
                        status = "success",
                        message = "Cinema has successfully updated",
                        data = new { cinema = updatedCinema }
                    }
                              ));
                }
            }
            return(NotFound(new
            {
                status = "fail",
                message = "Failed to update cinema",
                data = ModelState.Values.Select(v => v.Errors)
            }));
        }
Beispiel #2
0
        public async Task <CinemaDomainModel> UpdateCinema(CinemaDomainModel updateCinema)
        {
            Data.Cinema cinema = new Data.Cinema()
            {
                Id   = updateCinema.Id,
                Name = updateCinema.Name
            };

            var data = _cinemasRepository.Update(cinema);

            if (data == null)
            {
                return(null);
            }
            _cinemasRepository.Save();

            CinemaDomainModel domainModel = new CinemaDomainModel()
            {
                Id   = data.Id,
                Name = data.Name
            };

            return(domainModel);
        }