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"));
        }
예제 #2
0
        public JsonResult RecusarEmprestimo(int IdEmprestimo)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }

            UsuarioModel user = (UsuarioModel)Session["oUser"];

            using (MigxContext ctx = new MigxContext())
            {
                EmprestimoModel remover = new EmprestimoModel()
                {
                    ID = IdEmprestimo,
                    UsuarioIDSolicitadoPara = user.ID
                };

                ctx.Emprestimos.Add(remover);
                ctx.Entry <EmprestimoModel>(remover).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Json(true));
        }
예제 #3
0
        public JsonResult RecusarAmizade(int IdSolicitacao)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }

            UsuarioModel user = (UsuarioModel)Session["oUser"];

            using (MigxContext ctx = new MigxContext())
            {
                SolicitacaoAmizadeModel remover = new SolicitacaoAmizadeModel()
                {
                    Id = IdSolicitacao,
                    UsuarioSolicitadoParaID = user.ID
                };

                ctx.SolicitoesAmizade.Add(remover);
                ctx.Entry <SolicitacaoAmizadeModel>(remover).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Json(true));
        }