Пример #1
0
        public async Task PutDirector(string id, PutDirectorModel putDirectorModel)
        {
            try
            {
                DateTime birth = Convert.ToDateTime(putDirectorModel.Birth);

                Director director = await _context.Directors.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));

                director.FirstName   = putDirectorModel.FirstName;
                director.LastName    = putDirectorModel.LastName;
                director.Birth       = birth;
                director.Nationality = putDirectorModel.Nationality;
                director.Description = putDirectorModel.Description;

                await _context.SaveChangesAsync();
            }
            catch (MovieMindException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PutDirector", "400");
            }
        }
Пример #2
0
        public async Task <IActionResult> PutDirector(string id, PutDirectorModel putDirectorModel)
        {
            try
            {
                if (!Guid.TryParse(id, out Guid directorId))
                {
                    throw new GuidException("Invalid id", this.GetType().Name, "PutDirector", "400");
                }

                await _directorRepository.PutDirector(id, putDirectorModel);

                return(NoContent());
            }
            catch (MovieMindException e)
            {
                if (e.MovieMindError.Status.Equals("404"))
                {
                    return(NotFound(e.MovieMindError));
                }
                else
                {
                    return(BadRequest(e.MovieMindError));
                }
            }
        }
Пример #3
0
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Edit(string id, PutDirectorModel putDirectorModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "director");

                if (ModelState.IsValid)
                {
                    await _moviemindAPIService.PutModel <PutDirectorModel>(id, putDirectorModel, "Directors");

                    return(RedirectToRoute(new { action = "Index", controller = "Directors" }));
                }

                return(View(putDirectorModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(putDirectorModel)));
            }
        }
Пример #4
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "director");

                GetDirectorModel getDirectorModel = await _moviemindAPIService.GetModel <GetDirectorModel>(id, "Directors");

                PutDirectorModel putDirectorModel = new PutDirectorModel
                {
                    FirstName   = getDirectorModel.FirstName,
                    LastName    = getDirectorModel.LastName,
                    Birth       = getDirectorModel.Birth,
                    Description = getDirectorModel.Description,
                    Nationality = getDirectorModel.Nationality
                };

                return(View(putDirectorModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }