コード例 #1
0
 public ActionResult Edit(AuthorEditModel model)
 {
     try
     {
         if (model.NewPhoto != null)
         {
             string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" +
                                              FilePathGenerator.GenerateFileName(model.NewPhoto.FileName));
             if (!string.IsNullOrEmpty(model.PhotoPath) && System.IO.File.Exists(model.PhotoPath))
             {
                 System.IO.File.Delete(model.PhotoPath);
             }
             model.NewPhoto.SaveAs(filepath);
             model.PhotoPath = filepath;
         }
         var author = model.ToServiceAuthor();
         service.UpdateAuthor(author);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(View("Error"));
     }
 }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] AuthorEditModel author)
        {
            if (ModelState.IsValid)
            {
                AuthorResultModel response = await this.authorService.UpdateAuthor(author.Id, author.Name, author.ImageUrl, author.Website, author.Description, author.Books);

                if (!response.Success)
                {
                    FailedResponseModel badResponse = new FailedResponseModel()
                    {
                        Errors = response.Errors
                    };

                    return(BadRequest(badResponse));
                }

                AuthorSuccessResponseModel successResponse = new AuthorSuccessResponseModel()
                {
                    Name = response.Name
                };

                return(Ok(successResponse));
            }

            return(BadRequest(new FailedResponseModel {
                Errors = ModelState.Values.SelectMany(x => x.Errors.Select(y => y.ErrorMessage))
            }));
        }
コード例 #3
0
        public ActionResult Edit(AuthorEditModel model)
        {
            if (ModelState.IsValid)
            {
                var authors = db.Authors.Where(m => m.Id == model.Id)
                              .FirstOrDefault();

                if (authors != null)
                {
                    authors.Name = model.Name;
                }
                else
                {
                    authors = new Author
                    {
                        Name = model.Name
                    };

                    db.Authors.Add(authors);
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
コード例 #4
0
ファイル: AuthorsController.cs プロジェクト: Scyree/BookCore
        public IActionResult Edit(Guid id, [Bind("Name, Description")] AuthorEditModel authorEditModel)
        {
            var authorToBeEdited = _repository.GetAuthorById(id);

            if (authorToBeEdited == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(authorEditModel));
            }

            authorToBeEdited.Name        = authorEditModel.Name;
            authorToBeEdited.Description = authorEditModel.Description;

            try
            {
                _repository.EditAuthor(authorToBeEdited);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorExists(_repository.GetAuthorById(id).Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
 public void UpdateAuthor(AuthorEditModel model)
 {
     _authorRepository.Update(new DbAuthor
     {
         Id        = model.Id,
         BookId    = model.BookId,
         FirstName = model.AuthorFirstName,
         LastName  = model.AuthorLastName
     });
 }
コード例 #6
0
        public IHttpActionResult Put(AuthorEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _bookStoreManager.UpdateAuthor(model);

            return(Ok());
        }
コード例 #7
0
        public AuthorEditModel GetAuthorEditModel(int authorId)
        {
            var _dbModel   = dataManager.Authors.GetAuthorById(authorId);
            var _editModel = new AuthorEditModel()
            {
                Id      = _dbModel.Id,
                name    = _dbModel.Name,
                surname = _dbModel.Surname
            };

            return(_editModel);
        }
コード例 #8
0
 public static ServiceAuthor ToServiceAuthor(this AuthorEditModel author)
 {
     return(new ServiceAuthor()
     {
         ID = author.ID,
         Name = author.Name,
         BirthDate = author.BirthDate,
         DeathDate = author.DeathDate,
         Biography = author.Biography,
         Photo = author.PhotoPath
     });
 }
コード例 #9
0
        public async Task <IActionResult> Edit(AuthorEditModel collection)
        {
            if (ModelState.IsValid)
            {
                await m_authorService.Update(collection);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(collection));
            }
        }
コード例 #10
0
        public IActionResult upDate(int id)
        {
            var author = _repositoryAuthor.GetAuthorById(id);

            if (author == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            var authorViewModel = new AuthorEditModel();

            authorViewModel.Name = author.Name;
            authorViewModel.Age  = author.Age;
            return(View(authorViewModel));
        }
コード例 #11
0
 public IActionResult upDate(int id, AuthorEditModel model)
 {
     if (ModelState.IsValid)
     {
         var author = _repositoryAuthor.GetAuthorById(id);
         if (author == null)
         {
             return(RedirectToAction(nameof(Index)));
         }
         author.Name = model.Name;
         author.Age  = model.Age;
         author      = _repositoryAuthor.upDate(author);
         return(RedirectToAction(nameof(details), new { author.id }));
     }
     return(RedirectToAction(nameof(Index)));
 }
コード例 #12
0
        public IActionResult create(AuthorEditModel model)
        {//validação do servidor
            if (ModelState.IsValid)
            {
                var newAuthor = new Author();
                newAuthor.Name = model.Name;
                newAuthor.Age  = model.Age;
                newAuthor      = _repositoryAuthor.add(newAuthor);

                //forma errada pois  quando atualizava a tela salva novamente return View("details", newAuthor);
                return(RedirectToAction(nameof(details), new { id = newAuthor.id }));//é preciso um objeto
            }
            else
            {
                return(View());
            }
        }
コード例 #13
0
        public ActionResult Edit(int id)
        {
            var model = new AuthorEditModel();

            if (id > 0)
            {
                var author = db.Authors.Where(m => m.Id == id)
                             .FirstOrDefault();

                if (author != null)
                {
                    model.Id   = author.Id;
                    model.Name = author.Name;
                }
            }
            return(View(model));
        }
コード例 #14
0
        public AuthorViewModel SaveAuthorEditModelToDb(AuthorEditModel editModel)
        {
            Author author;

            if (editModel.Id != 0)
            {
                author = dataManager.Authors.GetAuthorById(editModel.Id);
            }
            else
            {
                author = new Author();
            }
            author.Id      = editModel.Id;
            author.Name    = editModel.name;
            author.Surname = editModel.surname;
            dataManager.Authors.SaveAuthor(author);
            return(AuthorDBModelToViewById(author.Id));
        }
コード例 #15
0
ファイル: AuthorsController.cs プロジェクト: Scyree/BookCore
        // GET: Authors/Edit/5
        public IActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var author = _repository.GetAuthorById(id.Value);

            if (author == null)
            {
                return(NotFound());
            }

            var authorEditModel = new AuthorEditModel(
                author.Name,
                author.Description
                );

            return(View(authorEditModel));
        }
コード例 #16
0
        public async Task <HttpResponseMessage> Edit([FromBody] AuthorEditModel model)
        {
            HttpResponseMessage returnMessage = new HttpResponseMessage();

            var role   = mapper.Map <AuthorDto>(model);
            var result = await service.EditAsync(role);

            if (result.IsSuccess)
            {
                string message = ($"Student Created - {result.Entity.Id}");
                returnMessage = new HttpResponseMessage(HttpStatusCode.Created);
                returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, message);
            }
            else
            {
                returnMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
                returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, result.GetErrorString());
            }


            return(returnMessage);
        }
コード例 #17
0
 public async Task Update(AuthorEditModel model)
 {
     await m_repository.Update(m_automapper.Map <Author>(model));
 }
コード例 #18
0
 public IActionResult AuthorCreate2(AuthorEditModel _editModel)
 {
     _servicesManager.Authors.SaveAuthorEditModelToDb(_editModel);
     return(View("AuthorCreate", _editModel));
 }
コード例 #19
0
        public IActionResult AuthorCreate()
        {
            AuthorEditModel _editModel = _servicesManager.Authors.CreateNewAuthorEditModel();

            return(View(_editModel));
        }
コード例 #20
0
 public IActionResult AuthorEdit2(AuthorEditModel _author)
 {
     _servicesManager.Authors.SaveAuthorEditModelToDb(_author);
     return(View("AuthorEdit", _author));
 }
コード例 #21
0
        public IActionResult AuthorEdit(int Id)
        {
            AuthorEditModel _editModel = _servicesManager.Authors.GetAuthorEditModel(Id);

            return(View(_editModel));
        }