// GET: Admin/Users public ActionResult Index() { UserF _UserFunc = new UserF(); List <Account> allUserAndRoles = _UserFunc.getAllUserAndRoles(); return(View(allUserAndRoles)); }
public ActionResult Index(Registry model) { if (ModelState.IsValid) { var dao = new UserF(); if (dao.CheckEmail(model.Email)) { ModelState.AddModelError("", "Email đã tồn tại"); } else { var cus = new User(); cus.Name = model.Name; cus.Email = model.Email; cus.Phone = model.Password; cus.Address = model.Address; cus.Password = model.Password; var result = dao.Insert(cus); if (result) { RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Đăng ký không thành công"); } } } return(View()); }
public ActionResult Index(Account model, string ReturnUrl) { if (String.IsNullOrEmpty(model.Email)) { ModelState.AddModelError("", "Chưa nhập email"); return(View("Index", model)); } var acc = new UserF().Login(model.Email, model.Password); if (acc == null) { Session[Common.Session.LoginSession] = null; ModelState.AddModelError("", "Người dùng không tồn tại"); return(View("Index", model)); } else { Session[Common.Session.LoginSession] = acc; if (string.IsNullOrEmpty(ReturnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(ReturnUrl)); } } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { var dao = new UserF(); if (dao.CheckUserName(model.UserName)) { ModelState.AddModelError("", "Tên đăng nhập đã tồn tại"); } else if (dao.CheckSDT(model.SDT)) { ModelState.AddModelError("", "Số điện thoại đã tồn tại"); } else { var user = new NguoiDung(); user.TenNguoiDung = model.TenNguoiDung; user.UserName = model.UserName; user.Pass = model.Pass; user.DiaChi = model.DiaChi; user.SDT = model.SDT; var result = dao.Insert(user); if (result > 0) { ViewBag.Success = "Đăng ký thành công"; model = new RegisterModel(); } else { ModelState.AddModelError("", "Đăng ký không thành công"); } } } return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new UserF(); var result = dao.Login(model.UserName, model.Pass); if (result) { var user = dao.GetById(model.UserName); var userSession = new UserLogin(); /// userSession.UserName = user.UserName; userSession.UserName = "******"; userSession.MaNguoiDung = user.MaNguoiDung; Session.Add(CommonConstants.USER_SESSION, userSession); // return RedirectToAction("Index", "Home"); return(Redirect("/Admin")); } else { ModelState.AddModelError("", "Đăng nhập không thành công."); } } return(View("Login")); }
public ActionResult Login(User User) { Account Account = new UserF().Login(User.Username, User.Password); if (Account == null) { return(View()); } Session["DangNhap"] = Account; if (Account.Roles.Contains("Admin")) { return(RedirectToAction("Index", "Home", new { area = "Admin" })); } else { return(RedirectToAction("Index", "Home")); } }
// GET: Admin/User public ActionResult Index() { var model = new UserF().Users.ToList(); return(View(model)); }
public User[] ListAll1() { var model = new UserF().Users.ToArray(); return(model); }
public List <User> ListAll() { var model = new UserF().Users.ToList(); return(model); }
public ActionResult TaiKhoan(long MaNguoiDung) { var model = new UserF().GHUser(MaNguoiDung); return(View(model)); }
public ActionResult PlanDePago(PlanViewModel model) { try { //Verificar si es modelo es correcto if (!ModelState.IsValid) { using (var db = new FinanzasEntities()) { List <compraInteligente> listado = db.compraInteligente.Where(x => x.user.id.Equals(UserF.id)).OrderByDescending(x => x.fecha).ToList(); model.Planes = listado; ViewBag.vehiculoId = new SelectList(db.vehiculo.ToList(), "id", "modelo"); ViewData["id"] = UserF.name; return(View(model)); } } if (model.Fecha <= DateTime.Now) { using (var db = new FinanzasEntities()) { List <compraInteligente> listado = db.compraInteligente.Where(x => x.user.id.Equals(UserF.id)).OrderByDescending(x => x.fecha).ToList(); model.Planes = listado; ViewBag.vehiculoId = new SelectList(db.vehiculo.ToList(), "id", "modelo"); ViewData["id"] = UserF.name; return(View(model)); } } int idC = 0; using (var db = new FinanzasEntities()) { double tasaPeriodo = 0f; if (model.tipoTasa == 1) //TEA { model.TEA = Convert.ToDecimal(model.Tasa); } else { tasaPeriodo = Math.Pow((1 + (((double)model.Tasa / 100) / 360)), 360) - 1; model.TEA = Convert.ToDecimal(tasaPeriodo * 100); } #region CalcularPlan compraInteligente oCompra = new compraInteligente(); oCompra.fecha = model.Fecha; oCompra.inicial = Convert.ToDecimal((model.cuotaInicial / 100) * model.valor); oCompra.moneda = model.moneda; oCompra.monto = Convert.ToDecimal(model.valor); oCompra.periodo_pago = model.periodo; oCompra.TCEA = Convert.ToDecimal(0); oCompra.TEA = model.TEA; oCompra.VAN = Convert.ToDecimal(0); oCompra.vehiculoId = model.vehiculoId; oCompra.idUser = UserF.id; oCompra.user = db.user.Find(UserF.id); oCompra.vehiculo = db.vehiculo.Find(model.vehiculoId); db.compraInteligente.Add(oCompra); db.SaveChanges(); #endregion /*Agregar detalle de compra*/ idC = (from d in db.compraInteligente orderby d.id descending select d.id).FirstOrDefault(); UserF.ci = idC; compraInteligente compra = (from d in db.compraInteligente where d.id == idC select d).FirstOrDefault(); vehiculo car = db.vehiculo.Find(compra.vehiculoId); DateTime fechaIni = oCompra.fecha; double Sfinal = Math.Round(Convert.ToDouble(compra.monto - compra.inicial), 2); double TEP = UserF.TEfectivaP((double)compra.TEA); double cuota = UserF.CalcCuota(TEP, compra.periodo_pago, Sfinal); //redondear a 2 double segDes = Math.Round(0.00050 * Sfinal, 2); //redondear a 2 double segRie = Math.Round(((Convert.ToDouble((car.segRiesgo) / 100)) * Convert.ToDouble(compra.monto)) / 12, 2); //redondear a 2 double inter, amort; #region CalcularDetallePlan(pg=s) for (int i = 0; i <= oCompra.periodo_pago; i++) { detalle oDetalle = new detalle(); if (i == 0) { oDetalle.n = i; oDetalle.fecha = fechaIni; oDetalle.TEP = 0; oDetalle.plazoGracia = "_"; oDetalle.saldoInicial = 0; oDetalle.interes = 0; oDetalle.cuota = 0; oDetalle.amortizacion = 0; oDetalle.seguroDesgrav = 0; oDetalle.seguroRiesgo = 0; oDetalle.saldoFinal = 0; oDetalle.flujo = Convert.ToDecimal(Sfinal); oDetalle.compraId = idC; oDetalle.compraInteligente = compra; db.detalle.Add(oDetalle); db.SaveChanges(); } else { oDetalle.n = i; oDetalle.fecha = fechaIni.AddMonths(1); oDetalle.TEP = Convert.ToDecimal(TEP * 100); oDetalle.plazoGracia = "s"; oDetalle.saldoInicial = Convert.ToDecimal(Sfinal); inter = Convert.ToDouble((oDetalle.TEP / 100) * oDetalle.saldoInicial); oDetalle.interes = Math.Round(Convert.ToDecimal(inter), 2); oDetalle.cuota = Math.Round(Convert.ToDecimal(cuota), 2); amort = cuota - inter; oDetalle.amortizacion = Math.Round(Convert.ToDecimal(amort), 2); oDetalle.seguroDesgrav = Convert.ToDecimal(segDes); oDetalle.seguroRiesgo = Convert.ToDecimal(segRie); oDetalle.saldoFinal = Math.Round(Convert.ToDecimal(Sfinal - amort), 2); oDetalle.flujo = Convert.ToDecimal(cuota + segDes + segRie); oDetalle.compraId = idC; oDetalle.compraInteligente = compra; db.detalle.Add(oDetalle); db.SaveChanges(); //actualizo datos fechaIni = oDetalle.fecha; Sfinal = Sfinal - amort; } #endregion } } return(Redirect(Url.Content("~/Home/DetallePrevio"))); } catch (Exception) { PlanViewModel model2 = new PlanViewModel(); using (var db = new FinanzasEntities()) { List <compraInteligente> listado = db.compraInteligente.Where(x => x.user.id.Equals(UserF.id)).OrderByDescending(x => x.fecha).ToList(); model2.Planes = listado; ViewBag.vehiculoId = new SelectList(db.vehiculo.ToList(), "id", "modelo"); } ViewBag.Message = "Aplicacion para plan de pago"; ViewData["id"] = UserF.name; return(View(model2)); } }
public ActionResult DetallePrevio(PlanViewModel model) { double VAN = 0; double TCEA = 0; int idC = UserF.ci; PlanViewModel modelP = new PlanViewModel(); using (var db = new FinanzasEntities()) { compraInteligente compra = (from d in db.compraInteligente where d.id == idC select d).FirstOrDefault(); double Sfinal = Math.Round(Convert.ToDouble(compra.monto - compra.inicial), 2); List <detalle> listado = db.detalle.Where(x => x.compraId.Equals(idC)).ToList(); modelP.cuotaInicial = (float)Convert.ToDouble(compra.inicial); modelP.moneda = compra.moneda; modelP.periodo = compra.periodo_pago; modelP.Tasa = Convert.ToDouble(compra.TEA); modelP.valor = (float)Convert.ToDouble(compra.monto); modelP.carro = (from d in db.vehiculo where d.id == compra.vehiculoId select d).FirstOrDefault(); modelP.Detalle = listado; double inter, amort, cuota, TEP; double TEP2 = UserF.TEfectivaP((double)compra.TEA); double[] Flujo = new double[modelP.periodo + 1]; Flujo[0] = Sfinal; if ((model.pgP == "" || model.pgP == null) && (model.pgT == "" || model.pgT == null)) { for (int r = 1; r <= compra.periodo_pago; r++) { Flujo[r] = -Convert.ToDouble(listado[r].flujo); } } else { List <int> PGP2 = new List <int>(); List <int> PGT2 = new List <int>(); PGP2.Add(0); PGT2.Add(0); if (model.pgT != null) { string[] PGT = model.pgT.Split(','); for (int i = 0; i < PGT.Length; i++) { PGT2.Add(Convert.ToInt32(PGT[i])); } } if (model.pgP != null) { string[] PGP = model.pgP.Split(','); for (int i = 0; i < PGP.Length; i++) { PGP2.Add(Convert.ToInt32(PGP[i])); } } #region CalculoActualizado for (int i = 1; i <= modelP.periodo; i++) { detalle oDetalle = (from d in db.detalle where d.compraId == idC & d.n == i select d).FirstOrDefault(); if (PGT2.Contains(i)) { oDetalle.plazoGracia = "t"; oDetalle.saldoInicial = Convert.ToDecimal(Sfinal); inter = Convert.ToDouble((oDetalle.TEP / 100) * oDetalle.saldoInicial); oDetalle.interes = Math.Round(Convert.ToDecimal(inter), 2); oDetalle.cuota = 0; oDetalle.amortizacion = 0; oDetalle.saldoFinal = Math.Round(Convert.ToDecimal(Sfinal + inter), 2); oDetalle.flujo = oDetalle.seguroDesgrav + oDetalle.seguroRiesgo; Flujo[i] = -Convert.ToDouble(oDetalle.flujo); db.Entry(oDetalle).State = EntityState.Modified; db.SaveChanges(); Sfinal = Sfinal + inter; //Calcular con plazo de gracia total } else if (PGP2.Contains(i)) { oDetalle.plazoGracia = "p"; oDetalle.saldoInicial = Convert.ToDecimal(Sfinal); inter = Convert.ToDouble((oDetalle.TEP / 100) * oDetalle.saldoInicial); oDetalle.interes = Math.Round(Convert.ToDecimal(inter), 2); oDetalle.cuota = Math.Round(Convert.ToDecimal(inter), 2); amort = 0; oDetalle.amortizacion = 0; oDetalle.saldoFinal = Math.Round(Convert.ToDecimal(Sfinal - amort), 2); oDetalle.flujo = oDetalle.seguroDesgrav + oDetalle.seguroRiesgo + oDetalle.cuota; Flujo[i] = -Convert.ToDouble(oDetalle.flujo); db.Entry(oDetalle).State = EntityState.Modified; db.SaveChanges(); Sfinal = Sfinal - amort; //Calcular con plazo de gracia Parcial } else { oDetalle.saldoInicial = Convert.ToDecimal(Sfinal); inter = Convert.ToDouble((oDetalle.TEP / 100) * oDetalle.saldoInicial); oDetalle.interes = Math.Round(Convert.ToDecimal(inter), 2); TEP = Convert.ToDouble(oDetalle.TEP) / 100; cuota = UserF.CalcCuotaNc(TEP, modelP.periodo, i, Sfinal); oDetalle.cuota = Math.Round(Convert.ToDecimal(cuota), 2); amort = cuota - inter; oDetalle.amortizacion = Math.Round(Convert.ToDecimal(amort), 2); oDetalle.saldoFinal = Math.Round(Convert.ToDecimal(Sfinal - amort), 2); oDetalle.flujo = oDetalle.seguroDesgrav + oDetalle.seguroRiesgo + oDetalle.cuota; Flujo[i] = -Convert.ToDouble(oDetalle.flujo); db.Entry(oDetalle).State = EntityState.Modified; db.SaveChanges(); Sfinal = Sfinal - amort; //Calculo normal } } #endregion } //TCEA Y VAN double TIR = Financial.IRR(ref Flujo, 0.1); TCEA = Math.Pow((1 + TIR), 12) - 1; double VA = 0; for (int j = 1; j <= compra.periodo_pago; j++) { VA += Flujo[j] / (Math.Pow((1 + TEP2), j)); } VAN = Flujo[0] + VA; compra.TCEA = Convert.ToDecimal(TCEA) * 100; compra.VAN = Math.Round(Convert.ToDecimal(VAN), 2); db.Entry(compra).State = EntityState.Modified; db.SaveChanges(); // } return(Redirect(Url.Content("~/Home/PlanDePago"))); }
public ActionResult TaiKhoan() { var model = new UserF().GHUser(); return(View(model)); }