Exemple #1
0
        public IActionResult AddQuote(QuoteDto quote)
        {
            if (quote.AuthorId == 0)
            {
                return(BadRequest(new
                {
                    success = false,
                    message = "Author ID is not specified"
                }));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            var quoteFromDto = AutoMapperConversion.ToQuote(quote);

            var newQuote = quoteData.Add(quoteFromDto);

            quoteData.Commit();

            return(new OkObjectResult(new
            {
                success = true,
                message = "Quote Added Successfully",
                data = newQuote
            }));
        }
Exemple #2
0
        public IActionResult UpdateQuote(long Id, QuoteDto quote)
        {
            if (quote.AuthorId == 0)
            {
                return(BadRequest(new
                {
                    success = false,
                    message = "Author ID is not specified"
                }));
            }

            var existingQuote = quoteData.GetByIdNoTracking(Id);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data. "));
            }

            var quoteFromDto = AutoMapperConversion.ToQuote(quote);

            quoteFromDto.Id = existingQuote.Id;
            var updatedQuote = quoteData.Update(quoteFromDto);

            quoteData.Commit();

            return(new OkObjectResult(new
            {
                success = true,
                message = "Quote Updated Successfully",
                data = updatedQuote
            }));
        }