コード例 #1
0
        public IHttpActionResult UpdatePregunta(int id, DTOPregunta pregunta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pregunta.idPregunta)
            {
                return(BadRequest());
            }

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

            DTOBaseResponse response = new DTOBaseResponse();

            try
            {
                BusinessLogic.Controllers.PreguntaController controller = new BusinessLogic.Controllers.PreguntaController();
                controller.UpdatePregunta(id, pregunta);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }
コード例 #2
0
        public IHttpActionResult CreatePregunta(DTOPregunta pregunta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DTOBaseResponse response = new DTOBaseResponse();
            int             idPregunta;

            try
            {
                BusinessLogic.Controllers.PreguntaController controller = new BusinessLogic.Controllers.PreguntaController();

                var Base64Image = pregunta.urlAyudaPregunta;

                if (Base64Image != "" && !Base64Image.StartsWith("http"))
                {
                    pregunta.urlAyudaPregunta = "Progress";
                }

                idPregunta = controller.CreatePregunta(pregunta);

                if (Base64Image != "" && !Base64Image.StartsWith("http"))
                {
                    var    bytes       = Convert.FromBase64String(Base64Image);
                    string nombreFile  = idPregunta + ".jpg";
                    var    GeneralPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "/images/ayuda/";

                    if (!Directory.Exists(GeneralPath))
                    {
                        Directory.CreateDirectory(GeneralPath);
                    }

                    string filePath = GeneralPath + nombreFile;
                    using (var imageFile = new FileStream(filePath, FileMode.Create))
                    {
                        imageFile.Write(bytes, 0, bytes.Length);
                        imageFile.Flush();
                    }
                    DTOPregunta UpdateUrlAyudaPregunta = new DTOPregunta
                    {
                        urlAyudaPregunta = nombreFile
                    };


                    controller.UpdatePregunta(idPregunta, UpdateUrlAyudaPregunta);
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }