public string FazerDenuncia(string model) { FazerDenunciaViewModel denunciaCliente = JsonConvert.DeserializeObject <FazerDenunciaViewModel>(model); return("entrou"); }
public string FazerDenuncia(FazerDenunciaViewModel model) { try { using (var context = new ApplicationDBContext()) { Denuncia denuncia = new Denuncia { Comentarios = model.Comentarios, ConvenioId = model.ConvenioId, Data = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time")), UsuarioId = model.UsuarioId }; context.Denuncia.Add(denuncia); if (!string.IsNullOrEmpty(model.UsuarioId)) { Usuario usuario = context.Usuario.Include(x => x.Denuncias) .FirstOrDefault(x => x.FacebookId == model.UsuarioId); if (usuario != null) { usuario.Pontuacao += 10; if (usuario.Denuncias == null) { usuario.Denuncias = new List <Denuncia>(); } usuario.Denuncias.Add(denuncia); } else { Usuario usu = new Usuario { FacebookId = model.UsuarioId, Pontuacao = 10, Nome = "Usuário Teste", Email = "Email Teste", Denuncias = new List <Denuncia> { denuncia } }; context.Usuario.Add(usu); } } context.SaveChanges(); int count = 1; foreach (var foto in model.ListaFotos) { var array = System.Convert.FromBase64String(foto.Replace("\n", string.Empty)); var fileName = denuncia.Id.ToString() + "_" + count++ + ".jpg"; string path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/ImagensDenuncias/"), fileName); // nome do arquivo using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) { fileStream.Write(array, 0, array.Length); } context.DenunciaFoto.Add(new DenunciaFoto { DenunciaId = denuncia.Id, Arquivo = fileName }); } context.SaveChanges(); } } catch (Exception ex) { return("500"); } return("200"); }