public ActionResult Create(documento documento)
        {
            LoadFormJuri();

            try
            {
                if (validate(documento))
                    return View(documento);

                if (UploadFile(ref documento))
                {
                    DocumentoRepository.Create(documento);
                    return RedirectToAction("List", new { message = "Dados cadastrados com sucesso!" });
                }
                else
                {
                    throw new Exception("Ocorreu um erro ao criar o registro");
                }
            }
            catch
            {
                if (!FileServerHelper.DeleteFile(documento.path))
                {
                    throw new Exception("Não foi possível excluir o arquivo");
                }
                else
                {
                    return View(documento);
                }
            }
        }
 public void Save(documento entity)
 {
     DataModel.Entry(entity).State = entity.id_documento == 0 ?
        EntityState.Added :
        EntityState.Modified;
     DataModel.SaveChanges();
 }
 public ActionResult List(documento entity, String message)
 {
     ViewData["message"] = message;
     if (string.IsNullOrEmpty(entity.nome_documento) && (entity.fk_id_juri.Equals(0)))
     {
         return View(DocumentoRepository.GetAll());
     }
     else
     {
         return View(DocumentoRepository.GetAllByCriteria(entity.nome_documento, entity.fk_id_juri));
     }
 }
        public bool ExistDependences(documento entity)
        {
            bool retorno = false;

            return retorno;
        }
        public bool validate(documento entity)
        {
            bool retorno = false;

            if (string.IsNullOrEmpty(entity.nome_documento))
            {
                ModelState.AddModelError("nome_documento", "Campo obrigatório");
                retorno = true;
            }
            if (string.IsNullOrEmpty(entity.path))
            {
                ModelState.AddModelError("path", "Campo obrigatório");
                retorno = true;
            }

            return retorno;
        }
        private bool UploadFile(ref documento documento)
        {
            if (Request.Files != null && Request.Files[0].ContentLength > 0)
            {
                string path = String.Empty;

                if (!FileServerHelper.UploadFile(Request.Files[0].InputStream,
                                                Request.Files[0].FileName, ref path))
                {
                    throw new Exception("Não foi possível salvar o arquivo");
                }
                else
                {
                    documento.path = path;
                    return true;
                }
            }
            else
            {
                throw new Exception("O arquivo informado está vazio");
            }
        }
        public ActionResult Delete(int id, documento documento)
        {
            try
            {
                documento = DocumentoRepository.GetOne(id);

                if (ExistDependences(documento))
                    return View(documento);

                if (!FileServerHelper.DeleteFile(documento.path))
                {
                    throw new Exception("Não foi possível salvar o arquivo");
                }
                else
                {
                    DocumentoRepository.Delete(documento);
                }

                return RedirectToAction("List", new { message = "Dados excluídos com sucesso!" });
            }
            catch
            {
                return View();
            }
        }
 public void Delete(documento entity)
 {
     DataModel.documento.Remove(entity);
     DataModel.SaveChanges();
 }
 public void Edit(documento entity)
 {
     Save(entity);
 }
 public void Create(documento entity)
 {
     Save(entity);
 }