Exemple #1
0
        public override IPost CreatePost(IPost aPost)
        {
            var Post = new LostAnimalPost()
            {
                Title       = aPost.Title,
                Description = aPost.Description
            };

            return(Post);
        }
        public async Task <IActionResult> getLostAnimal(int id)
        {
            try
            {
                LostAnimalPost lostAnimal = await _context.LostAnimalPosts.FindAsync(id);

                object response = new { success = true, data = lostAnimal };
                return(Ok(response));
            }
            catch
            {
                return(NotFound(notFound.TemplateResponse($"Nao existe o post com o id {id}")));
            }
        }
        public async Task <IActionResult> Create(LostAnimalPost aLostAnimalPost)
        {
            try
            {
                var postLostAnimal = (LostAnimalPost)lost_factory.CreatePostFromPostFactory(aLostAnimalPost);
                postLostAnimal.Contact  = aLostAnimalPost.Contact;
                postLostAnimal.Location = aLostAnimalPost.Location;
                postLostAnimal.Date     = aLostAnimalPost.Date;
                postLostAnimal.Image    = aLostAnimalPost.Image;
                await _context.LostAnimalPosts.AddAsync(postLostAnimal);

                await _context.SaveChangesAsync();

                object response = new { sucess = true, data = postLostAnimal };
                return(Ok(response));
            }
            catch
            {
                return(BadRequest(notFound.TemplateResponse("Não foi possivel realizar a sua ação")));
            }
        }