public ActionResult Agregar_Producto(String CódigoProd, String NombreProd, String DescripcionProd, String PrecioProd,
                                             String DescuentoProd, String IdProveedor1, String CantidadDisponibleProd, String CantidadMinimaProd,
                                             String IdTipoProducto1, HttpPostedFileBase ImagenProducto)
        {
            _oProductoBO = new BO.ProductoBO();
            _oFotoBO     = new BO.FotoBO();
            _oFotoModel  = new FotoModel();

            _oProductoBO.CódigoProd             = CódigoProd;
            _oProductoBO.NombreProd             = NombreProd;
            _oProductoBO.DescripcionProd        = DescripcionProd;
            _oProductoBO.PrecioProd             = Convert.ToDouble(PrecioProd);
            _oProductoBO.DescuentoProd          = Convert.ToDouble(DescuentoProd);
            _oProductoBO.IdProveedor1           = Convert.ToInt32(IdProveedor1);
            _oProductoBO.CantidadDisponibleProd = Convert.ToInt32(CantidadDisponibleProd);
            _oProductoBO.CantidadMinimaProd     = Convert.ToInt32(CantidadMinimaProd);
            _oProductoBO.IdTipoProducto1        = Convert.ToInt32(IdTipoProducto1);

            _oProductoModel.Agregar(_oProductoBO);

            if (ImagenProducto != null && ImagenProducto.ContentLength > 0)
            {
                _oFotoBO.ImagenFoto = new byte[ImagenProducto.ContentLength];
                ImagenProducto.InputStream.Read(_oFotoBO.ImagenFoto, 0, ImagenProducto.ContentLength);
                _oFotoBO.PrincipalFoto = true;
                _oFotoBO.IdProducto    = _oProductoModel.Buscar_IdProducto(CódigoProd);

                _oFotoModel.Agregar(_oFotoBO);
            }
            ViewBag.Agregado = true;
            Producto();
            return(View("Producto"));
        }
Beispiel #2
0
        public async Task <IComandoResultado> Editar([FromForm] FotoModel funcFoto)
        {
            EditarFotoAlunoComando comando = new EditarFotoAlunoComando();
            var util = new Util(_environment);

            if (!string.IsNullOrWhiteSpace(funcFoto.base64image))
            {
                byte[] arquivoB64 = Convert.FromBase64String(funcFoto.base64image.Replace("data:image/jpeg;base64,", ""));
                var    diretorio  = util.ObterCaminhoArquivo($"{funcFoto.Id}.jpg", "Aluno");
                System.IO.File.WriteAllBytes($"{diretorio}", arquivoB64);
                comando.Id   = funcFoto.Id;
                comando.Foto = $"{funcFoto.Id}.jpg";
            }
            else if (funcFoto.file.Length > 0)
            {
                string nomeArquivo = ContentDispositionHeaderValue.Parse(funcFoto.file.ContentDisposition).FileName.Trim('"');
                nomeArquivo = util.VerificarNomeArquivoCorreto(nomeArquivo);
                var extensao = nomeArquivo.Split('.')[1];
                using (FileStream output = System.IO.File.Create(util.ObterCaminhoArquivo($"{funcFoto.Id}.{extensao}", "Aluno")))
                {
                    var file = new FileInfo(output.Name);
                    await funcFoto.file.CopyToAsync(output);
                }
                comando.Id   = funcFoto.Id;
                comando.Foto = $"{funcFoto.Id}.{extensao}";
            }
            var resultado = await _manipuladorFoto.ManipuladorAsync(comando);

            return(resultado);
        }
Beispiel #3
0
        public JsonResult UploadImmagineProfilo(HttpPostedFileBase file, string token)
        {
            PortaleWebViewModel utente = (Session["portaleweb"] as List <PortaleWebViewModel>).SingleOrDefault(m => m.Token == token);

            if (utente == null)
            {
                return(Json(new { Success = false, responseText = ErrorResource.HappyShopNotFound }));
            }
            FileUploadifive fileSalvato = UploadImmagine("/Uploads/Images/" + utente.Token + "/" + DateTime.Now.Year.ToString(), file);
            FotoModel       model       = new FotoModel();

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                int idAllegato = model.Add(db, fileSalvato.Nome);
                if (idAllegato > 0)
                {
                    // salvo allegato come immagine del profilo
                    utente.SetImmagineProfilo(db, idAllegato);
                    if (utente.Foto != null && utente.Foto.Count > 0)
                    {
                        string htmlGalleriaFotoProfilo = RenderRazorViewToString("PartialPages/_GalleriaFotoProfilo", new PortaleWebProfiloViewModel(utente));
                        return(Json(new { Success = true, responseText = htmlGalleriaFotoProfilo }));
                    }
                }
            }
            //Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            //return null;
            return(Json(new { Success = false, responseText = Language.ErrorFormatFile }));
        }
        public ActionResult Editar(TimeLineItemModel item)
        {
            var user = (UsuarioModel)Session["oUser"];

            using (MigxContext ctx = new MigxContext())
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    if (Request.Files[i].ContentLength > 0)
                    {
                        var file     = Request.Files[i];
                        var fileName = Path.GetFileName(file.FileName);
                        var extensao = Path.GetExtension(file.FileName);

                        FotoModel fotoInfo = new FotoModel();
                        fotoInfo.Id          = Guid.NewGuid();
                        fotoInfo.NomeArquivo = fileName;
                        fotoInfo.Extensao    = extensao;

                        var novoNome = Path.Combine(Server.MapPath("~/Content/Images/"), user.ID.ToString(), fotoInfo.Id + fotoInfo.Extensao); //Cria um novo nome baseado no Id e extensão.
                        file.SaveAs(novoNome);

                        fotoInfo.TimeLineID       = item.Id;
                        ctx.Entry(fotoInfo).State = System.Data.Entity.EntityState.Added;
                    }
                }

                item.UsuarioID        = user.ID;
                ctx.Entry(item).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }

            return(RedirectToAction("MeusDados", "Usuario"));
        }
Beispiel #5
0
        public async Task <IActionResult> EditarFoto([FromForm] FotoModel funcFoto)
        {
            try
            {
                var util = new Util(_environment);
                EditarFotoAlunoComando comando = new EditarFotoAlunoComando();
                if (funcFoto.file.Length > 0)
                {
                    string nomeArquivo = ContentDispositionHeaderValue.Parse(funcFoto.file.ContentDisposition).FileName.Trim('"');

                    nomeArquivo = util.VerificarNomeArquivoCorreto(nomeArquivo);
                    var extensao = nomeArquivo.Split('.')[1];
                    using (FileStream output = System.IO.File.Create(util.ObterCaminhoArquivo($"{funcFoto.Id}.{extensao}", "Aluno")))
                    {
                        var file = new FileInfo(output.Name);
                        await funcFoto.file.CopyToAsync(output);
                    }

                    comando.Id   = funcFoto.Id;
                    comando.Foto = $"{funcFoto.Id}.{extensao}";
                }

                var resultado = await _manipuladorFoto.ManipuladorAsync(comando);

                return(Json(resultado));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.ExpectationFailed;
                return(Json(ex.Message));
            }
        }
Beispiel #6
0
        // POST: odata/Foto
        public IHttpActionResult Post(FotoModel fotoModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Foto.Add(fotoModel);
            db.SaveChanges();

            return(Created(fotoModel));
        }
Beispiel #7
0
        // DELETE: odata/Foto(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            FotoModel fotoModel = db.Foto.Find(key);

            if (fotoModel == null)
            {
                return(NotFound());
            }

            db.Foto.Remove(fotoModel);
            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #8
0
        public HttpResponseMessage Put(int Id, string cultura, FotoModel foto)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        Foto      _foto           = fotoRepository.GetById(new string[] {}, (p => p.Id == Id));
                        FotoModel _fotoPorDefecto = new FotoModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _fotoPorDefecto = AutoMapper.Mapper.Map <FotoModel, FotoModel>(foto, _fotoPorDefecto);

                        _fotoPorDefecto.Nombre      = _foto.Nombre;
                        _fotoPorDefecto.Descripcion = _foto.Descripcion;

                        var command = AutoMapper.Mapper.Map <FotoModel, CreateOrUpdateFotoCommand>(_fotoPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <FotoModel, CreateOrUpdateFotoCommand>(foto);
                        var result  = commandBus.Submit(command);
                    }
                    Foto_Idioma _fotoIdioma   = foto_IdiomaRepository.GetMany(t => t.IdRegistro == foto.Id && t.Cultura == cultura).FirstOrDefault();
                    var         commandIdioma = AutoMapper.Mapper.Map <Foto_IdiomaModel, CreateOrUpdateFoto_IdiomaCommand>(new Foto_IdiomaModel {
                        Id = (_fotoIdioma != null ? _fotoIdioma.Id : (int)0), IdRegistro = foto.Id, Cultura = cultura, Nombre = foto.Nombre, Descripcion = foto.Descripcion
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <FotoModel>(HttpStatusCode.OK, foto));
                }
                else
                {
                    var errors = new Dictionary <string, IEnumerable <string> >();
                    foreach (var keyValue in ModelState)
                    {
                        errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty)));
                    }
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            } catch (Exception _excepcion) {
                log.Error(_excepcion);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
            }
        }
Beispiel #9
0
 public HttpResponseMessage Post(string cultura, FotoModel foto)
 {
     try {
         if (ModelState.IsValid)
         {
             if (foto.Id == 0)
             {
                 var command = AutoMapper.Mapper.Map <FotoModel, CreateOrUpdateFotoCommand>(foto);
                 var result  = commandBus.Submit(command);
                 if (result.Success)
                 {
                     var commandIdioma = AutoMapper.Mapper.Map <Foto_IdiomaModel, CreateOrUpdateFoto_IdiomaCommand>(new Foto_IdiomaModel {
                         IdRegistro = command.Id, Cultura = cultura, Nombre = command.Nombre, Descripcion = command.Descripcion
                     });
                     var resultIdioma = commandBus.Submit(commandIdioma);
                     if (resultIdioma.Success)
                     {
                         foto = AutoMapper.Mapper.Map <CreateOrUpdateFotoCommand, FotoModel>(command);
                         var    response = Request.CreateResponse <FotoModel>(HttpStatusCode.Created, foto);
                         string uri      = Url.Route(null, new { Id = foto.Id });
                         response.Headers.Location = new Uri(Request.RequestUri, uri);
                         return(response);
                     }
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.BadRequest, "No se puede insertar el registro porque ya existe otro con la misma clave. Por favor, revísela."));
             }
         }
         else
         {
             var errors = new Dictionary <string, IEnumerable <string> >();
             foreach (var keyValue in ModelState)
             {
                 errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty)));
             }
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
        public ActionResult AdicionarItem(TimeLineItemModel item)
        {
            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            var user   = (UsuarioModel)Session["oUser"];
            var userId = user.ID;

            Directory.CreateDirectory(Path.Combine(Server.MapPath("~/Content/Images/"), userId.ToString())); //Cria o diretório caso ele não exista.

            item.UsuarioID = userId;
            item.Fotos     = new List <FotoModel>();
            for (int i = 0; i < Request.Files.Count; i++)
            {
                if (Request.Files[i].ContentLength > 0)
                {
                    var file     = Request.Files[i];
                    var fileName = Path.GetFileName(file.FileName);
                    var extensao = Path.GetExtension(file.FileName);

                    FotoModel fotoInfo = new FotoModel();
                    fotoInfo.Id          = Guid.NewGuid();
                    fotoInfo.NomeArquivo = fileName;
                    fotoInfo.Extensao    = extensao;

                    var novoNome = Path.Combine(Server.MapPath("~/Content/Images/"), userId.ToString(), fotoInfo.Id + fotoInfo.Extensao); //Cria um novo nome baseado no Id e extensão.
                    file.SaveAs(novoNome);

                    item.Fotos.Add(fotoInfo);
                }
            }

            using (MigxContext ctx = new MigxContext())
            {
                ctx.Itens.Add(item);
                ctx.SaveChanges();
            }

            return(RedirectToAction("MeusDados", "Usuario"));
        }
Beispiel #11
0
        public async Task <IComandoResultado> Editar([FromForm] FotoModel funcFoto)
        {
            string nomeArquivo = ContentDispositionHeaderValue.Parse(funcFoto.file.ContentDisposition).FileName.Trim('"');

            nomeArquivo = this.VerificarNomeArquivoCorreto(nomeArquivo);
            var extensao = nomeArquivo.Split('.')[1];

            using (FileStream output = System.IO.File.Create(this.ObterCaminhoArquivo($"{funcFoto.Id}.{extensao}")))
            {
                var file = new FileInfo(output.Name);
                await funcFoto.file.CopyToAsync(output);
            }
            EditarFotoFuncionarioComando comando = new EditarFotoFuncionarioComando();

            comando.Id   = funcFoto.Id;
            comando.Foto = $"{funcFoto.Id}.{extensao}";
            var resultado = await _editarFotoManipulador.ManipuladorAsync(comando);

            return(resultado);
        }
        public JsonResult ExcluirFoto(Guid idFoto)
        {
            var user = (UsuarioModel)Session["oUser"];

            using (MigxContext ctx = new MigxContext())
            {
                FotoModel foto = ctx.Fotos.SingleOrDefault(ft => ft.Id == idFoto);

                var path = Path.Combine(Server.MapPath("~/Content/Images/"), user.ID.ToString(), foto.Id + foto.Extensao);

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                ctx.Fotos.Remove(foto);
                ctx.SaveChanges();
            }

            return(Json(true));
        }
Beispiel #13
0
        public void AddFotos()
        {
            string[] arxiusDirectori = Directory.GetFiles(_rutaImatges);
            string   nom;

            foreach (string nomArxiu in arxiusDirectori)
            {
                nom = Path.GetFileName(nomArxiu);

                FotoModel f = new FotoModel
                {
                    Client     = "003",
                    Expedient  = "",
                    Arxiu_foto = nom
                };

                Fotos.Add(f);
            }

            TotalImatges = arxiusDirectori.Length;
        }
Beispiel #14
0
        public bool PostStatus(FotoModel input)//, string Name, byte[]FotoData)
        {
            TimesheetEntities entities = new TimesheetEntities();

            try
            {
                string[] nameParts = input.Name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                string   first     = nameParts[0];
                string   last      = nameParts[1];



                Employee existing = (from ts in entities.Employees
                                     where (ts.FirstName == first) && (ts.LastName == last)

                                     select ts).FirstOrDefault();

                if (existing != null)
                {
                    existing.EmployeePicture = input.Fotodata;
                }
                else
                {
                    return(false);
                }

                entities.SaveChanges();
            }
            catch
            {
                return(false);
            }
            finally
            {
                entities.Dispose();
            }

            return(true);
        }
Beispiel #15
0
        public IHttpActionResult Patch([FromODataUri] int key, Delta <FotoModel> patch)
        {
            Validate(patch.GetEntity());

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

            FotoModel fotoModel = db.Foto.Find(key);

            if (fotoModel == null)
            {
                return(NotFound());
            }

            patch.Patch(fotoModel);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FotoModelExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(fotoModel));
        }
 // Terceira Etapa (Setamos as Fotos)
 public AmigoBuilder SetarFoto(FotoModel foto_)
 {
     _novoAmigo.Fotos.Add(foto_);
     return this;
 }
 // Terceira Etapa (Setamos as Fotos)
 public AmigoBuilder SetarFoto(FotoModel foto_)
 {
     _novoAmigo.Fotos.Add(foto_);
     return(this);
 }