public IActionResult CreateAuthor(CreateAuthorRequest request) { var command = mapper.Map <CreateAuthorCommand>(request); command.CreatedBy = CurrentAccountId; return(HandleCommandResult(appExecutor.Dispatch(command))); }
public static CreateAuthorRequest ConvertToCreateNationalityRequest(this AuthorViewModel model) { CreateAuthorRequest request = new CreateAuthorRequest(); request.Name = model.Name; request.NationalityId = model.Nationality.NationalityId; return(request); }
public IActionResult CreateAuthor([FromBody] CreateAuthorRequest request) { Author author = new Author(); author.Name = request.Name; author.IsActive = true; _authorService.Add(author); return(Ok()); }
public async Task <IActionResult> AddAuthorAsync([FromBody] CreateAuthorRequest AuthorRequest) { (bool succeed, string message, CreateAuthorResponse AuthorResponse) = await Mediator.Send(AuthorRequest); if (succeed) { return(Ok(AuthorResponse.ToResponse())); } return(BadRequest(message.ToResponse(false, message))); }
public void AnAuthorGivenByTheApplicationUser() { _request = new CreateAuthorRequest() { Name = "author name", LastName = " author last name", Born = 1999, Photo = "this is an url" }; }
public async Task <AuthorViewModel> CreateNewAuthor([FromBody] CreateAuthorRequest request) { var cmd = new CreateAuthorCommand(request.FirstName, request.LastName); var author = new Author(cmd); await _dbContext.Authors.AddAsync(author); await _dbContext.SaveChangesAsync(); return(new AuthorViewModel(author)); }
public async Task <ActionResult> AddAuthor(CreateAuthorRequest author) { if (author == null) { return(BadRequest()); } await _authorService.AddAuthorAsync(author); return(Ok(author)); }
public static Author ConvertToAuthor(this CreateAuthorRequest createRequest) { Author author = new Author(); author.Name = createRequest.Name; author.Nationality = new Nationality() { NationalityId = createRequest.NationalityId }; return(author); }
public async Task AddAuthorAsync(CreateAuthorRequest author) { if (author == null) { throw new ArgumentNullException(nameof(author)); } author.Id = Guid.NewGuid(); _context.Authors.Add(author.ToEntity()); await _context.SaveChangesAsync(); }
public Guid CreateAuthor(CreateAuthorRequest request) { if (!new CreateAuthorRequestValidator().Validate(request).IsValid) { throw new Exception("CreateAuthor validation error"); } Persistence.BeginTransaction(); var author = new Author(request); Persistence.Create(author); Persistence.Commit(); return(author.Id); }
public JsonResult CreateAuthorIfNotExistsFor(CreateAuthorRequest model) { var request = $"{AppSettings.Api}createAuthorIfNotExistsFor".PostJsonToUrl( new { apikey = AppSettings.ApiKey, name = model.Name, authorMapper = model.AuthorMapper }); var responce = JsonConvert.DeserializeObject <CreateAuthorResponce>(request); return(Json(responce)); }
public ActionResult <AuthorDTO> Post([FromBody] CreateAuthorRequest newAuthor) { using var conn = new SqlConnection(_connString); var sql = "InsertAuthor"; int newId = conn.QuerySingle <int>(sql, new { name = newAuthor.Name }, commandType: System.Data.CommandType.StoredProcedure); var authorDto = new AuthorDTO { Id = newId, Name = newAuthor.Name }; return(Ok(authorDto)); }
public async Task <IActionResult> CreateAsync([FromBody] CreateAuthorRequest createAuthorRequest) { var author = new Author { FullName = createAuthorRequest.FullName, Biography = createAuthorRequest.Biography, }; await this.authorService.CreateAuthorAsync(author); var baseUrl = $"{this.HttpContext.Request.Scheme}://{this.HttpContext.Request.Host.ToUriComponent()}"; var locationUrl = baseUrl + "/" + ApiRoutes.Authors.Get.Replace("{AuthorId}", author.Id.ToString()); return(this.Created(locationUrl, author)); }
public ActionResult Create(AuthorSinglePageViewModel model) { CreateAuthorRequest request = model.AuthorViewModel.ConvertToCreateNationalityRequest(); CreateAuthorResponse response = _authorService.CreateAuthor(request); if (response.Success) { return(RedirectToAction("Index")); } else { model.Success = false; model.Message = response.Message; return(View(model)); } }
public ActionResult <AuthorDTO> Post([FromBody] CreateAuthorRequest newAuthor) { // https://stackoverflow.com/a/8270264 var sql = "INSERT Authors (name) VALUES (@name);SELECT CAST(scope_identity() AS int)"; using var conn = new SqlConnection(_connString); int newId = conn.QuerySingle <int>(sql, new { name = newAuthor.Name }); var authorDto = new AuthorDTO { Id = newId, Name = newAuthor.Name }; return(Ok(authorDto)); }
public ActionResult<AuthorDTO> Post([FromBody] CreateAuthorRequest newAuthor) { using var conn = new SqlConnection(_connString); var sql = "INSERT Authors (name) VALUES (@name);SELECT CAST(scope_identity() AS int)"; var cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@name", newAuthor.Name); conn.Open(); int newId = (int)cmd.ExecuteScalar(); var authorDto = new AuthorDTO { Id = newId, Name = newAuthor.Name }; return Ok(authorDto); }
public CreateAuthorResponse CreateAuthor(CreateAuthorRequest request) { CreateAuthorResponse response = new CreateAuthorResponse(); try { Author author = request.ConvertToAuthor(); _authorRepository.Create(author); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public ActionResult <AuthorDTO> Post([FromBody] CreateAuthorRequest newAuthor) { var author = new Author { Name = newAuthor.Name }; _dbContext.Authors.Add(author); _dbContext.SaveChanges(); var authorDto = new AuthorDTO { Id = author.Id, Name = author.Name }; return(Ok(authorDto)); }
public ActionResult <AuthorDTO> Post([FromBody] CreateAuthorRequest newAuthor) { using var conn = new SqlConnection(_connString); var sql = "InsertAuthor"; var cmd = new SqlCommand(sql, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", newAuthor.Name); conn.Open(); int newId = (int)cmd.ExecuteScalar(); var authorDto = new AuthorDTO { Id = newId, Name = newAuthor.Name }; return(Ok(authorDto)); }
public static AuthorEntity ToEntity(this CreateAuthorRequest author) { if (author == null) { return(null); } return(new AuthorEntity { FirstName = author.FirstName, LastName = author.LastName, DateOfBirth = author.DateOfBirth, MainCategory = author.MainCategory, Courses = author.Courses.Select(x => new CourseEntity { Title = x.Title, Description = x.Description, AuthorId = author.Id }).ToList() }); }
public static AuthorBuilder BuildAuthorByRequest(this AuthorBuilder authorBuilder, CreateAuthorRequest request) { return(authorBuilder? .WithFirstName(request?.FirstName) .WithLastName(request?.LastName) .WithUsername(request?.Username) .WithPassword(request?.Password) .WithEmail(request?.Email) .WithBio(request?.Bio) .WithAvatar(request?.Avatar)); }
public Author(CreateAuthorRequest request) : this() { HandleAuthorRequest(request); }