Beispiel #1
0
 private void HandleAuthorRequest(AuthorRequest request)
 {
     Initials   = request.Initials?.Trim();
     FirstNames = request.FirstNames?.Trim();
     Prefix     = request.Prefix?.Trim();
     LastName   = request.LastName?.Trim();
 }
Beispiel #2
0
        public async Task <IActionResult> UpdateAuthor([FromRoute] int id, [FromBody] AuthorRequest authorRequest)
        {
            if (!await IsUserAdmin())
            {
                return(Forbid());
            }

            if (id != authorRequest.Id)
            {
                return(BadRequest("Wrong Id"));
            }

            var author = await _authorManager.GetAuthorWithVideos(id);

            if (author == null)
            {
                return(BadRequest("Author not found"));
            }

            _mapper.Map(authorRequest, author);
            await _authorManager.SaveChangesAsync();

            var response = _mapper.Map <AuthorResponse>(author);

            return(Ok(response));
        }
Beispiel #3
0
        public async Task <IActionResult> PutAuthorAsync([FromRoute] Guid id, [FromBody] AuthorRequest author)
        {
            author.Id = id;
            await service.UpdateAsync(mapper.Map <Author>(author));

            return(NoContent());
        }
        public object Any(BookSearchRequest request)
        {
            var q = AutoQuery.CreateQuery(request, base.Request);

            if (q.Params.Count < 1)
            {
                q.Where(x => 1 == 1);
            }

            var authorRequest = new AuthorRequest();
            var authorAuto    = AutoQuery.CreateQuery(authorRequest, base.Request)
                                .Join <BookAuthor>()
                                .Select <BookAuthor>(x => x.BookId)
                                .ClearLimits();

            var catRequest = new CategoryRequest();
            var catAuto    = AutoQuery.CreateQuery(catRequest, base.Request)
                             .Join <BookCategory>()
                             .Select <BookCategory>(x => x.BookId)
                             .ClearLimits();


            if (authorAuto.Params.Count > 0)
            {
                q.And <Book>(x => Sql.In(x.Id, authorAuto));
            }
            if (catAuto.Params.Count > 0)
            {
                q.And <Book>(x => Sql.In(x.Id, catAuto));
            }

            var results = AutoQuery.Execute(request, q);

            return(results);
        }
Beispiel #5
0
        public IActionResult Post([FromBody] AuthorRequest request)
        {
            MySqlConnection conn   = new MySqlConnection(_appSettings.ConnectionString);
            AuthorResult    result = new AuthorResult();

            try
            {
                conn.Open();

                using (MySqlCommand cmd = new MySqlCommand("insert into Author (Name) Values (@name)", conn))
                {
                    cmd.Parameters.AddWithValue("@name", request.Name);

                    cmd.ExecuteNonQuery();

                    using (MySqlCommand cmd2 = new MySqlCommand("SELECT last_insert_id()", conn))
                    {
                        result.AuthorID = (int)(ulong)cmd2.ExecuteScalar();
                    }
                }

                result.Name = request.Name;

                return(new OkObjectResult(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
            finally {
                conn.Dispose();
                conn.Close();
            }
        }
Beispiel #6
0
        public IActionResult Put(int AuthorID, [FromBody] AuthorRequest request)
        {
            MySqlConnection conn   = new MySqlConnection(_appSettings.ConnectionString);
            AuthorResult    result = new AuthorResult();

            try
            {
                conn.Open();

                using (MySqlCommand cmd = new MySqlCommand("update Author set name = @name where AuthorID = @AuthorId", conn))
                {
                    cmd.Parameters.AddWithValue("@name", request.Name);
                    cmd.Parameters.AddWithValue("@AuthorId", AuthorID);

                    cmd.ExecuteNonQuery();
                }

                result.AuthorID = AuthorID;
                result.Name     = request.Name;

                return(new OkObjectResult(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
Beispiel #7
0
        public IActionResult Put(int AuthorID, [FromBody] AuthorRequest request)
        {
            MySqlConnection conn = new MySqlConnection(_appSettings.ConnectionString);

            try
            {
                conn.Open();

                using (MySqlCommand cmd = new MySqlCommand("UPDATE Author SET Name = @name WHERE AuthorID = @authorID", conn))
                {
                    cmd.Parameters.AddWithValue("@name", request.Name);
                    cmd.Parameters.AddWithValue("@authorID", AuthorID);

                    cmd.ExecuteNonQuery();
                }

                return(new OkObjectResult(new AuthorResult {
                    AuthorID = AuthorID, Name = request.Name
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
            finally
            {
                conn.Dispose();
                conn.Close();
            }
        }
        public Response <Author> Create(AuthorRequest request)
        {
            try
            {
                var messages = request.Validate();

                if (messages != null && messages.Count > 0)
                {
                    return(ResponseBadRequest(messages.ToList()));
                }

                _repoAuthor.Add(new Author
                {
                    Birthdate = request.Birthdate,
                    LastName  = request.Lastname,
                    Name      = request.Name
                });

                return(ResponseSuccess(null));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception Method {nameof(AuthorBL)}.{nameof(Create)}");
                return(ResponseFail());
            }
        }
Beispiel #9
0
 /// <summary>
 /// From Author Request to Author Request pivot.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>Author Request pivot result.</returns>
 public static AuthorRequestPivot ToPivot(this AuthorRequest request)
 {
     return(new AuthorRequestPivot
     {
         AuthorPivot = request.AuthorDto?.ToPivot(),
         FindAuthorPivot = Utility.EnumToEnum <FindAuthorDto, FindAuthorPivot>(request.FindAuthorDto)
     });
 }
 public AuthorRequestBuilder()
 {
     _instance = new AuthorRequest
     {
         UserName = "******",
         Name     = "Gilmar Alcantara"
     };
 }
Beispiel #11
0
        public void Validate_Author_Tests(string userName, string name, bool result)
        {
            var authorReq = new AuthorRequest {
                UserName = userName, Name = name
            };
            var validate = new AuthorRequestValidator().Validate(authorReq);

            validate.IsValid.Should().Be(result);
        }
Beispiel #12
0
        public async Task <ActionResult <AuthorResponse> > Create([FromBody] AuthorRequest request)
        {
            var author = _mapper.Map <Author>(request);

            author = await _authorRepository.CreateAsync(author);

            var result = _mapper.Map <AuthorResponse>(author);

            return(CreatedAtRoute("GetAuthor", new { id = result.Id }, result));
        }
        public IActionResult Put(int AuthorID, [FromBody] AuthorRequest request)
        {
            AuthorResult result = new AuthorResult();

            //rotina de gravar dados no banco e selecionar Autor gravado para retornar (neste exemplo mokado)
            result.AuthorID = 6;
            result.Name     = request.Name;
            //rotina de gravar dados no banco e selecionar Autor gravado para retornar (neste exemplo mokado)

            return(new OkObjectResult(result));
        }
        public IActionResult Post([FromBody] AuthorRequest request)//em um verbo POST ou PUT você pode passar os parametros da chamada pelo Body usando a notation [FromBody] isso permite passar objeto JSON complexos
        {
            AuthorResult result = new AuthorResult();

            //rotina de gravar dados no banco e selecionar Autor gravado para retornar (neste exemplo mokado)
            result.AuthorID = 1;
            result.Name     = request.Name;
            //rotina de gravar dados no banco e selecionar Autor gravado para retornar (neste exemplo mokado)

            return(new OkObjectResult(result));
        }
        public void UpdateValidate_Author_Tests(string id, string title, string content, bool result)
        {
            var author = new AuthorRequest {
                UserName = "******", Name = "Gilmar"
            };

            var authorReq = new UpdateNewsRequest {
                Id = Guid.Parse(id), Title = title, Content = content, Author = author
            };
            var validate = new UpdateNewsRequestValidator().Validate(authorReq);

            validate.IsValid.Should().Be(result);
        }
Beispiel #16
0
        public override Task <AuthorResponse> Get(AuthorRequest request, ServerCallContext context)
        {
            Metadata md = context.RequestHeaders;

            foreach (var item in md)
            {
                System.Console.WriteLine($"{item.Key} : {item.Value}");
            }

            return(Task.FromResult(new AuthorResponse {
                Author = MockData.Authors.FirstOrDefault(x => x.Id == request.Id)
            }));
        }
Beispiel #17
0
            public void Dispose()
            {
                if (!_isDisposed)
                {
                    AuthorRequest?.Dispose();
                    RepositoryRequest?.Dispose();
                    _authorCertificate?.Dispose();
                    _repositoryCertificate?.Dispose();
                    _directory?.Dispose();

                    GC.SuppressFinalize(this);

                    _isDisposed = true;
                }
            }
        /// <summary>
        /// Delete Author
        /// </summary>
        /// <param name="request">author request.</param>
        /// <returns>Author message.</returns>
        public AuthorMessage DeleteAuthor(AuthorRequest request)
        {
            AuthorMessage message = new AuthorMessage();

            try
            {
                _serviceAuthor.DeleteAuthor(request.ToPivot());
                message.OperationSuccess = true;
            }
            catch (Exception e)
            {
                message.ErrorType    = ErrorType.TechnicalError;
                message.ErrorMessage = e.Message;
            }
            return(message);
        }
Beispiel #19
0
        public async Task <IActionResult> AddAuthor([FromBody] AuthorRequest authorRequest)
        {
            if (!await IsUserAdmin())
            {
                return(Forbid());
            }

            var author = _mapper.Map <Author>(authorRequest);

            _authorManager.AddAuthor(author);
            await _authorManager.SaveChangesAsync();

            var response = _mapper.Map <AuthorResponse>(author);

            return(CreatedAtAction(nameof(GetAuthorById), new { id = author.Id }, response));
        }
        public Response <Author> Update(string id, AuthorRequest request)
        {
            try
            {
                var messages = request.Validate();
                if (messages != null && messages.Count > 0)
                {
                    return(ResponseBadRequest(messages.ToList()));
                }

                if (string.IsNullOrEmpty(id) || !int.TryParse(id, out int idAuthor))
                {
                    return(ResponseBadRequest(new List <string> {
                        MessagesResponse.BadRequest
                    }));
                }

                var author = _repoAuthor.Get(idAuthor);

                if (author == null)
                {
                    return(ResponseFail(CodeResponse.NotFoundAuthor, new List <string> {
                        MessagesResponse.NotFoundAuthor
                    }));
                }

                _repoAuthor.Update(author, new Author {
                    Birthdate = request.Birthdate, LastName = request.Lastname, Name = request.Name
                });

                return(ResponseSuccess(null));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception Method {nameof(AuthorBL)}.{nameof(Update)}");
                return(ResponseFail());
            }
        }
        public IActionResult Post(AuthorRequest author)
        {
            //check if author already exists
            Author auth = _context.Authors.Where(u => u.Email == author.email).FirstOrDefault();

            if (auth == null)
            {
                Author newAuthor = new Author
                {
                    FirstName = author.firstName,
                    LastName  = author.lastName,
                    Email     = author.email
                };

                _context.Authors.Add(newAuthor);
                _context.SaveChanges();
                return(Ok(newAuthor.Id));
            }
            else
            {
                return(BadRequest("Author " + author.email + " already exists."));
            }
            //return Ok("Author blah blah already exists.");
        }
 public System.IAsyncResult BeginAuthorSearchRequest(AuthorRequest AuthorSearchRequest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("AuthorSearchRequest", new object[] {
         AuthorSearchRequest}, callback, asyncState);
 }
Beispiel #23
0
        public void SaveAuthor(AuthorRequest authorRequest)
        {
            Author author = new Author(authorRequest.Name);

            authorRepository.AddAuthor(author);
        }
Beispiel #24
0
        public async Task <IActionResult> PostAuthorAsync([FromBody] AuthorRequest author)
        {
            var id = await service.SaveAsync(mapper.Map <Author>(author));

            return(CreatedAtAction("GetAuthor", new { id }, null));
        }
Beispiel #25
0
 public void Post([FromBody] AuthorRequest authorRequest)
 {
     authorService.SaveAuthor(authorRequest);
 }
Beispiel #26
0
 public NewsRequestBuilder WithAuthor(AuthorRequest author)
 {
     _instance.Author = author;
     return(this);
 }
Beispiel #27
0
 public IActionResult Post([FromBody] AuthorRequest request)
 {
     return(Ok(_authorBL.Create(request)));
 }
Beispiel #28
0
 public IActionResult Put(string id, [FromBody] AuthorRequest request)
 {
     return(Ok(_authorBL.Update(id, request)));
 }
 public ProductInfo AuthorSearchRequest(AuthorRequest AuthorSearchRequest)
 {
     object[] results = this.Invoke("AuthorSearchRequest", new object[] {
         AuthorSearchRequest});
     return ((ProductInfo)(results[0]));
 }
Beispiel #30
0
 public async Task <AuthorBaseResponse> Upsert2(AuthorRequest author)
 {
     return(await service.UpsertEntityAsync <AuthorRequest, AuthorResponse>(author));
 }
Beispiel #31
0
 public void Put(int id, [FromBody] AuthorRequest authorRequest)
 {
     authorService.UpdateAuthor(id, authorRequest);
 }
Beispiel #32
0
 public void UpdateFrom(AuthorRequest source, EntityUpdateOptions options = null)
 {
     this.Name      = source.Name;
     this.BirthDate = source.BirthDate;
 }