Beispiel #1
0
        public ActionResult AddAccount(CreditCardViewModel cc)
        {
            var usId = Convert.ToInt32(Session["UserId"]);

            var not = db.Notifications.Where(u => u.NOT_U_Id == usId && u.NOT_Leido == false);
            ViewBag.noti = not;

            var numero = cc.CC_Entity + cc.CC_Office + cc.CC_ControlDigit + cc.CC_ANumber;

            var findCC = db.CreditCard.Where(u => u.CC_U_Id == usId);
            if (findCC.Count() > 1)
            {
                findCC.Single();
                try
                {
                    db.Entry(findCC).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("CreditCardInfo");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    RedirectToAction("ErrorPage", "Error");
                }
            }
            else
            {
                CreditCard newCC = new CreditCard();
                newCC.CC_AccountNumber = numero;
                newCC.CC_U_Id = usId;

                try
                {
                    db.CreditCard.Add(newCC);
                    db.SaveChanges();
                    return RedirectToAction("CreditCardInfo");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    RedirectToAction("ErrorPage", "Error");
                }
            }

            return View();
        }
Beispiel #2
0
        public ActionResult EditAccountNumber(CreditCardViewModel cc)
        {
            var usId = Convert.ToInt32(Session["UserId"]);

            var not = db.Notifications.Where(u => u.NOT_U_Id == usId && u.NOT_Leido == false);
            ViewBag.noti = not;
            ViewBag.CC_CT_Id = new SelectList(db.UserData, "CT_Id", "CT_Type");

            var number = cc.CC_Entity + cc.CC_Office + cc.CC_ControlDigit + cc.CC_ANumber;

            var ccUser = db.CreditCard.Find(cc.CC_Id);
            ccUser.CC_AccountNumber = number;

            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(ccUser).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("CreditCardInfo");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    RedirectToAction("ErrorPage", "Error");
                }

            }
            return View();
        }