Beispiel #1
0
 public IActionResult Post([FromBody] AuthorModel newAuthor)
 {
     try
     {
         _authorServices.Add(newAuthor.ToDomainModel());
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("addAuthor", ex.GetBaseException().Message);
     }
     return(CreatedAtAction("Get", new { Id = newAuthor.Id }, newAuthor));
 }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "LastName,FirstName,DateOfBirth,DateOfDeath,AboutAuthor,UploadedFile")] AuthorDTO model)
        {
            if (ModelState.IsValid)
            {
                var author = DependencyResolver.Current.GetService <IAuthor>();
                //var author = new Author();
                Mapper.Map(model, author);

                if (model.UploadedFile != null)
                {
                    author.FileModelId = _fileServices.CheckDbAndUploadeFile(model.UploadedFile);
                }

                _services.Add(author);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Beispiel #3
0
 public Author Add(Author newAuthor)
 {
     return(_authorServices.Add(newAuthor));
 }