Ejemplo n.º 1
0
        public ActionResult RemoveAll()
        {
            MovimentosRepository repo = new MovimentosRepository(db);

            userId = GetUserId();
            repo.RemoveAll(userId);
            string fullPath = Request.MapPath("~/App_Data/uploads/" + User.Identity.Name);

            System.IO.DirectoryInfo di = new DirectoryInfo(fullPath);
            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                dir.Delete(true);
            }
            return(RedirectToAction("Upload"));
        }
Ejemplo n.º 2
0
        public ActionResult Upload(HttpPostedFileBase upload)
        {
            ApplicationDbContext db         = new ApplicationDbContext();
            MovimentosRepository repo       = new MovimentosRepository(db);
            List <Movimento>     movimentos = new List <Movimento>();

            userId = GetUserId();
            var path = "";

            if (upload != null && upload.ContentLength > 0)
            {
                // extract only the filename
                var fileName = Path.GetFileName(upload.FileName);
                // store the file inside ~/App_Data/uploads folder

                var  fh     = "~/App_Data/uploads/" + User.Identity.Name + "/";
                bool exists = System.IO.Directory.Exists(Server.MapPath(fh));

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(fh));
                }
                path = Path.Combine(Server.MapPath(fh) + fileName);
                upload.SaveAs(path);

                ConnexionExcel ConxObject = new ConnexionExcel(path);
                //Query a worksheet with a header row

                var query1 = from a in ConxObject.UrlConnexion.Worksheet <Movimento>(0)
                             select a;
                foreach (var result in query1)
                {
                    if (!String.IsNullOrEmpty(result.Descricao))
                    {
                        //Viola o Liskov Substituion Principle
                        Tipo         t;
                        Departamento d = Departamento.Escolha;
                        if (result.Descricao.Contains("LEV") && result.Valor < 0)
                        {
                            t = Tipo.Levantamento;
                            d = Departamento.Levantamento;
                        }
                        else if ((result.Descricao.Contains("TRF") || result.Descricao.Contains("TRANS")) && result.Valor < 0)
                        {
                            t = Tipo.Transferencia;
                        }
                        else if ((result.Descricao.Contains("TRF") || result.Descricao.Contains("TRANS") || result.Descricao.Contains("DEP")) && result.Valor > 0)
                        {
                            t = Tipo.Deposito;
                        }
                        else if (result.Descricao.Contains("REFORCO") && result.Valor < 0)
                        {
                            t            = Tipo.Deposito;
                            result.Valor = 0;
                        }
                        else if (result.Valor > 0)
                        {
                            t = Tipo.Recebido;
                        }
                        else
                        {
                            t = Tipo.Pagamento;
                        }
                        Movimento m = new Movimento //Viola Dependency Inversion Principle
                        {
                            DataTime     = result.DataTime,
                            Descricao    = result.Descricao,
                            Valor        = result.Valor,
                            Saldo_Atual  = result.Saldo_Atual,
                            Tipo         = t,
                            Dono         = userId,
                            Departamento = d
                        };
                        movimentos.Add(m);
                        repo.Insert(m);
                    }
                }
                repo.Commit();
            }
            return(View());
        }
Ejemplo n.º 3
0
 public MovimentosController()
 {
     db = new MovimentosRepository();
 }