static void Main(string[] args) { #region Take() Explained //List<string> names = new List<string> //{ // "Martin", // "Ivo", // "Dejan", // "Stefan", // "Irina", // "Mimi", // "Marko", //}; //var namesStartWithM = names.Where(x => x.StartsWith('M')) // .OrderByDescending(x => x) // .Take(1) // .FirstOrDefault(); //Console.WriteLine(namesStartWithM); #endregion try { string allPostsUrl = "https://api.posts/posts/all"; string singlePostUrl = "https://api.posts/posts/martin"; List <Post> allPosts = PostClient.GetAll(allPostsUrl); Post singlePost = PostClient.Get(singlePostUrl); allPosts.ForEach(x => Console.WriteLine(x.Title)); Console.WriteLine("________________________________"); Console.WriteLine($"Single post: {singlePost.Title}"); } catch (BadRequestException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Message: {ex.Message} | StatusCode: {ex.StatusCode}"); } catch (NotFoundException ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine($"Message: {ex.Message} | StatusCode: {ex.StatusCode}"); } catch (Exception ex) { Console.WriteLine($"Message: {ex.Message}"); } Console.WriteLine("This will work after the exception is thrown!"); Console.ReadLine(); }
public ActionResult GetImage(int id) { PostClient post = new PostClient(); var imagen = post.Get(id); try { return(File(imagen.Logo, "image/jpg")); } catch (Exception e) { return(null); } }
public ActionResult EditarPost(Post c, HttpPostedFileBase imagenSisi) { PostClient postClient = new PostClient(); if (imagenSisi != null && imagenSisi.ContentLength > 0) { byte[] imagenData = null; using (var bynaryImage = new BinaryReader(imagenSisi.InputStream)) { imagenData = bynaryImage.ReadBytes(imagenSisi.ContentLength); } c.Logo = imagenData; } else { var imagen = postClient.Get(c.Id); c.Logo = imagen.Logo; } if (c.NombreCategoria == 0) { return(EditarPost("Debes seleccionar una Categoria.")); } else if (c.NombrePais == 0 || c.NombreCiudad == 0) { return(EditarPost("Debes seleccionar un pais y su ciudad correspondiente.")); } else if (c.NombreTipoTrabajo == 0) { return(EditarPost("Debes seleccionar un tipo de Trabajo.")); } else { if (ModelState.IsValid) { postClient.Update(c); return(RedirectToAction("ProfileAcc")); } else { return(View(c)); } } }
static void Main(string[] args) { try { string allPostUrl = "https://api.posts/posts/all"; string singlePostUrl = "https://api.posts/posts/martin"; List <Post> allPosts = PostClient.GetAll(allPostUrl); Post singlePost = PostClient.Get(singlePostUrl); allPosts.ForEach(x => { Console.WriteLine($"Title: {x.Title}"); Console.WriteLine($"Content: {x.Content}"); Console.WriteLine($"Post by: {x.CreatedBy}"); Console.WriteLine("--------------------------------"); }); Console.WriteLine("---------------- Single post with id: 1 -------------------"); Console.WriteLine($"Title: {singlePost.Title}"); Console.WriteLine($"Content: {singlePost.Content}"); Console.WriteLine($"Post by: {singlePost.CreatedBy}"); Console.WriteLine("--------------------------------"); } catch (BadRequestException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Message: {ex.Message} | StatusCode: {ex.StatusCode}"); } catch (NotFoundException ex) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Message: {ex.Message} | StatusCode: {ex.StatusCode}"); } catch (Exception ex) { Console.WriteLine($"Message: {ex.Message}"); } Console.ReadLine(); }
public async Task <IActionResult> OnGet(string id) { Post = await _postClient.Get(id); return(Page()); }