Example #1
0
        public JsonResult Adjuntar(int UsuarioID, HttpPostedFileBase documento)
        {
            var respuesta = new Models.ResponseModel
            {
                respuesta = true,
                error     = ""
            };

            if (documento != null)
            {
                string adjunto = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(documento.FileName);
                documento.SaveAs(Server.MapPath("~/ImgProductos/" + adjunto));

                db.UsuarioImagen.Add(new UsuarioImagen {
                    UsuarioId = UsuarioID, Imagen = adjunto, Titulo = "Ejemplo", Descripcion = "Ejemplo"
                });
                db.SaveChanges();
            }
            else
            {
                respuesta.respuesta = false;
                respuesta.error     = "Debe adjuntar un documento";
            }

            return(Json(respuesta));
        }
Example #2
0
        public JsonResult EliminarImagen(int UsuarioImagenId)
        {
            var rpt = new Models.ResponseModel()
            {
                respuesta = true,
                error     = ""
            };
            var img = db.UsuarioImagen.Find(UsuarioImagenId);

            if (System.IO.File.Exists(Server.MapPath("~/ImgProductos/" + img.Imagen)))
            {
                System.IO.File.Delete(Server.MapPath("~/ImgProductos/" + img.Imagen));
            }

            db.UsuarioImagen.Remove(img);
            db.SaveChanges();

            return(Json(rpt));
        }
        public Epi.Web.MVC.Models.ResponseModel ConvertXMLToModel(Epi.Web.Enter.Common.DTO.SurveyAnswerDTO item, List <KeyValuePair <int, string> > Columns)
        {
            Epi.Web.MVC.Models.ResponseModel ResponseModel = new Models.ResponseModel();


            var MetaDataColumns = Epi.Web.MVC.Constants.Constant.MetaDaTaColumnNames();

            try
            {
                ResponseModel.Column0  = item.ResponseId;
                ResponseModel.IsLocked = item.IsLocked;
                IEnumerable <XElement> nodes;
                var document = XDocument.Parse(item.XML);
                if (MetaDataColumns.Contains(Columns[0].Value.ToString()))
                {
                    ResponseModel.Column1 = GetColumnValue(item, Columns[0].Value.ToString());
                }
                else
                {
                    nodes = document.Descendants().Where(e => e.Name.LocalName.StartsWith("ResponseDetail") && e.Attribute("QuestionName").Value == Columns[0].Value.ToString());
                    if (nodes.Count() > 0)
                    {
                        ResponseModel.Column1 = nodes.First().Value;
                    }
                }
                if (Columns.Count >= 2)
                {
                    if (MetaDataColumns.Contains(Columns[1].Value.ToString()))
                    {
                        ResponseModel.Column2 = GetColumnValue(item, Columns[1].Value.ToString());
                    }
                    else
                    {
                        nodes = document.Descendants().Where(e => e.Name.LocalName.StartsWith("ResponseDetail") && e.Attribute("QuestionName").Value == Columns[1].Value.ToString());
                        if (nodes.Count() > 0)
                        {
                            ResponseModel.Column2 = nodes.First().Value;
                        }
                    }
                }


                if (Columns.Count >= 3)
                {
                    if (MetaDataColumns.Contains(Columns[2].Value.ToString()))
                    {
                        ResponseModel.Column3 = GetColumnValue(item, Columns[2].Value.ToString());
                    }
                    else
                    {
                        nodes = document.Descendants().Where(e => e.Name.LocalName.StartsWith("ResponseDetail") && e.Attribute("QuestionName").Value == Columns[2].Value.ToString());
                        if (nodes.Count() > 0)
                        {
                            ResponseModel.Column3 = nodes.First().Value;
                        }
                    }
                }

                if (Columns.Count >= 4)
                {
                    if (MetaDataColumns.Contains(Columns[3].Value.ToString()))
                    {
                        ResponseModel.Column4 = GetColumnValue(item, Columns[3].Value.ToString());
                    }
                    else
                    {
                        nodes = document.Descendants().Where(e => e.Name.LocalName.StartsWith("ResponseDetail") && e.Attribute("QuestionName").Value == Columns[3].Value.ToString());
                        if (nodes.Count() > 0)
                        {
                            ResponseModel.Column4 = nodes.First().Value;
                        }
                    }
                }

                if (Columns.Count >= 5)
                {
                    if (MetaDataColumns.Contains(Columns[4].Value.ToString()))
                    {
                        ResponseModel.Column5 = GetColumnValue(item, Columns[4].Value.ToString());
                    }
                    else
                    {
                        nodes = document.Descendants().Where(e => e.Name.LocalName.StartsWith("ResponseDetail") && e.Attribute("QuestionName").Value == Columns[4].Value.ToString());
                        if (nodes.Count() > 0)
                        {
                            ResponseModel.Column5 = nodes.First().Value;
                        }
                    }
                }


                return(ResponseModel);
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }