public IHttpActionResult EditById(int id, AmigoBindModel inputModel) { var amigo = new AmigoBindModel().CriarAmigo(inputModel); amigo.Id = id; var amigo_editado = AmigoService.Editar(amigo); return(Ok(amigo_editado)); }
public IHttpActionResult Register(AmigoBindModel model) { var amigo = new AmigoBindModel().CriarAmigo(model); var cadastrou = AmigoService.Salvar(amigo); if (cadastrou != null) { return(Ok()); } return(BadRequest()); }
public async Task <ActionResult> Create(AmigoBindModel model) { int id = int.Parse(Request.Form["PaisesList"].ToString()); string nomepais = GetNomePaisById(id); AmigoBindModel amigo = new AmigoBindModel() { Nome = model.Nome, SobreNome = model.SobreNome, Email = model.Email, Telefone = model.Telefone, Aniversario = model.Aniversario, NomePais = nomepais, NomeEstado = model.NomeEstado }; try { if (ModelState.IsValid) { using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { client.BaseAddress = new Uri("http://localhost:49572/"); client.DefaultRequestHeaders.Accept.Clear(); content.Add(new StringContent(JsonConvert.SerializeObject(amigo))); if (Request.Files.Count > 0) { byte[] fileBytes; using (var inputStream = Request.Files[0].InputStream) { var memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } fileBytes = memoryStream.ToArray(); } var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); fileContent.Headers.ContentDisposition.FileName = Request.Files[0].FileName.Split('\\').Last(); content.Add(fileContent); } var response = await client.PostAsync("/api/amigos", content); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Amigos")); } else { return(View("Error")); } } } } } catch { return(View("Index")); } return(View("Index")); }