public ActionResult Create(AuthorCreateModel model) { try { if (ModelState.IsValid) { int id; if (model.Photo != null) { string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" + FilePathGenerator.GenerateFileName(model.Photo.FileName)); model.Photo.SaveAs(filepath); id = service.AddAuthor(model.ToServiceAuthor(filepath)); } else { id = service.AddAuthor(model.ToServiceAuthor()); } return(RedirectToAction("Details", new { id = id })); } return(View(model)); } catch (Exception ex) { logger.Error(ex); return(View("Error")); } }
public async Task <ObjectResult> Post([FromBody] Book book) { _logger.LogInformation("Add book"); Result response = null; if (book != null && book.Author != null) { response = await authorService.AddAuthor(new Author { Name = book.Author }); if (response == null || response.Code != 200) { _logger.LogInformation("Can't find or add author"); book.Author = null; } } response = await bookService.AddBook(book); if (response == null) { return(StatusCode(500, "Internal error")); } return(StatusCode(response.Code, response.Message)); }
public ActionResult AddAuthor(AuthorBookViewModel model) { Author author = new Author { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, AddedDate = DateTime.UtcNow, IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(), ModifiedDate = DateTime.UtcNow, Books = new List <Book> { new Book { Name = model.BookName, ISBN = model.ISBN, Publisher = model.Publisher, IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(), AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow } } }; authorService.AddAuthor(author); return(RedirectToAction("Index")); }
public IActionResult AddAuthor([FromForm] IFormFile file, [FromForm] string model) { var author = JsonConvert.DeserializeObject <AuthorModel>(model); if (author == null) { return(BadRequest()); } //if (!ModelState.IsValid) // throw new InvalidModelStateException(ModelState); if (file != null) { using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); author.ImageUrl = Convert.ToBase64String(fileBytes); } } _authorService.AddAuthor(author); return(Ok(true)); }
public int Post(AuthorCreateModel model) { if (!ModelState.IsValid) { throw new Exception("Form is invalid."); } return(_authorService.AddAuthor(model, _userManager.GetUserId(User))); }
public IActionResult Post([FromBody] Author author) { if (author == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } _authorService.AddAuthor(author); return(StatusCode(StatusCodes.Status201Created)); }
public IActionResult Create(Author author) { if (ModelState.IsValid) { _authourService.AddAuthor(author); } //return View(); return(RedirectToAction(nameof(Index))); }
public ActionResult AddAuthor(string authorName) { var author = new Author(); author.Name = authorName; authorService.AddAuthor(author); return(Json(new { authorId = author.Id })); }
public async Task <IActionResult> AddAuthor(AuthorDto authorDto) { var author = _mapper.Map <Author>(authorDto); author = await _authorService.AddAuthor(author); var authorToReturn = _mapper.Map <AuthorDto>(author); return(CreatedAtRoute("GetAuthor", new { authorId = author.Id }, authorToReturn)); }
public async Task <Author> Handle(CreateAuthorMutation request, CancellationToken cancellationToken) { var author = new Author { Name = request.Name }; _authorService.AddAuthor(author); return(author); }
public ActionResult <AuthorReadDto> AddAuthor(AuthorAddDto theAuthor) { var authorContent = _mapper.Map <Author>(theAuthor); _authorRepo.AddAuthor(authorContent); var authorOutDto = _mapper.Map <AuthorReadDto>(authorContent); return(CreatedAtRoute(nameof(GetAuthorById), new { Id = authorOutDto.Id }, authorOutDto)); }
public IActionResult Create([FromBody] Author author) { if (ModelState.IsValid) { Guid obj = Guid.NewGuid(); author.id = obj.ToString(); _authorService.AddAuthor(author); return(Ok()); } return(BadRequest()); }
public ActionResult Post([FromBody] Author newItem) { if (newItem is null) { return(BadRequest()); } var item = _authorService.AddAuthor(newItem); return(Ok(item)); }
public async Task <IActionResult> AddAuthor(Author model) { var result = await _authorService.AddAuthor(model); if (!result.Item1) { return(BadRequest(new { message = result.Item2 })); } return(CreatedAtRoute("GetAuthorById", new { Id = model.Id.ToString() }, model)); }
public ActionResult Create(Author author) { if (ModelState.IsValid) { authorService.AddAuthor(author); return(RedirectToAction("Index")); } else { return(View(author)); } }
public async Task <IActionResult> Create(CreateAuthorVm vm) { if (ModelState.IsValid) { //var vm = new CreateAuthorVm(); var authorToAdd = new Author(); authorToAdd.Name = vm.Name; authorsService.AddAuthor(authorToAdd); return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> Add(AuthorViewModel viewModel) { var author = await _authorService.AddAuthor(viewModel); if (_authorService.IsSuccessful() == false) { AddModelError(_authorService.GetModelErrors()); return(View(nameof(Edit), author)); } return(RedirectToAction(nameof(Edit), new { author.AuthorId })); }
public override string Execute(IList <string> parameters) { var firstName = parameters[0]; var lastName = parameters[1]; var alias = parameters[2]; var author = this.DTOFactory.CreateAuthorDTO(firstName, lastName, alias); authorService.AddAuthor(author); return(Messages.AuthorAdded); }
public IActionResult AddAuthor([FromBody] AuthorModel author) { var result = _authorService.AddAuthor(author); if (result.State == ActionResultState.Error) { return(BadRequest(new { result.Errors })); } // For valid JSON response we use an empty object return(Ok(new { })); }
public async Task <ObjectResult> Post([FromBody] Author author) { _logger.LogInformation("Add author"); var response = await authorService.AddAuthor(author); if (response == null) { _logger.LogInformation("Internal gateway error"); return(StatusCode(500, "Internal error")); } return(StatusCode(response.Code, response.Message)); }
public async Task <IActionResult> Create(AuthorCreateVm vm) { if (ModelState.IsValid) { var newAuthor = new Author(); newAuthor.Name = vm.Name; authorservice.AddAuthor(newAuthor); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Error", "Home", "")); }
public IActionResult AddAuthor([FromForm] AuthorViewModel authorViewModel) { if (ModelState.IsValid) { _authorService.AddAuthor(authorViewModel.Nickname, authorViewModel.Email, 0); if (authorViewModel.ArticleContent != null) { _articleService.AddArticle(authorViewModel.Email, authorViewModel.ArticleTitle, authorViewModel.ArticleContent, DateTime.UtcNow); } return(Redirect(Url.Action("Index", "Home"))); } return(View(authorViewModel)); }
public Author AddAuthor(Author newAuthor, bool doRefresh = true) { Ensure.That(newAuthor, () => newAuthor).IsNotNull(); newAuthor = AddSkyhookData(newAuthor); newAuthor = SetPropertiesAndValidate(newAuthor); _logger.Info("Adding Author {0} Path: [{1}]", newAuthor, newAuthor.Path); // add metadata _authorMetadataService.Upsert(newAuthor.Metadata.Value); newAuthor.AuthorMetadataId = newAuthor.Metadata.Value.Id; // add the author itself return(_authorService.AddAuthor(newAuthor, doRefresh)); }
public ActionResult Create(AuthorVm vm) { try { var newAuthor = new Author { Name = vm.Name }; _authorService.AddAuthor(newAuthor); return(RedirectToAction(nameof(Index))); } catch (DbException) { return(View()); } }
public async Task <IActionResult> AddAuthor(AuthorDto authorDto) { try { var result = await Task.Run( () => _authorService.AddAuthor(authorDto)); // TODO var uri = Url.Link("GetAuthor", new { authorId = result }); return(Created(uri, authorDto)); } catch (InvalidDataException e) { return(BadRequest(e.Message.ToString())); } catch (DataAlreadyExistsException) { return(StatusCode((int)HttpStatusCode.Conflict)); } catch (Exception e) { return(BadRequest(e.Message.ToString())); } }
public async Task <HttpResponseMessage> AddAuthor(Author author) { try { Request = new HttpRequestMessage(); configuration = new HttpConfiguration(); Request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; var result = await _authorService.AddAuthor(author); bool status = false; if (result) { status = true; return(Request.CreateResponse(HttpStatusCode.OK, status)); } return(Request.CreateResponse(HttpStatusCode.OK, status)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to Create Author!")); } }
public async Task <ActionResult> Post([FromBody] Author author) { var newAuthor = await _authorService.AddAuthor(author); return(Ok(newAuthor.FullName + " Added")); }
public async Task AddAuthor([FromBody] AuthorDto request) { await _authorService.AddAuthor(request); }
public async Task <IActionResult> AddAuthor(Author author) { return(Ok(await _iauthorservice.AddAuthor(author))); }
public HttpResponseMessage PostAuthor(Author author) { var newAuthor = _authorService.AddAuthor(author); return(Request.CreateResponse(HttpStatusCode.OK, newAuthor)); }