Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            BillModels billModels = db.Bill.Find(id);

            db.Bill.Remove(billModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "BillId,BillName,BillCompany,BillDate,BillPrice,UserId")] BillModels billModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(billModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.Users, "Id", "Email", billModels.UserId);
     return(View(billModels));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "BillId,BillName,BillCompany,BillDate,BillPrice,UserId")] BillModels billModels)
        {
            if (ModelState.IsValid)
            {
                billModels.UserId = User.Identity.GetUserId();
                db.Bill.Add(billModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "Email", billModels.UserId);
            return(View(billModels));
        }
Beispiel #4
0
        // GET: User/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillModels billModels = db.Bill.Find(id);

            if (billModels == null)
            {
                return(HttpNotFound());
            }
            return(View(billModels));
        }
Beispiel #5
0
        // GET: User/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillModels billModels = db.Bill.Find(id);

            if (billModels == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.Users, "Id", "Email", billModels.UserId);
            return(View(billModels));
        }
        public void CreateNewBill(FormCollection form, int taxi, string ApplicationUser, string ApplicationUserID)
        {
            int     article  = Convert.ToInt32(form["articles"]);
            int     tax      = taxi;
            string  quantity = form["quantity"];
            decimal realTax  = Decimal.Divide(tax, 100);

            //Get tax ID
            int taxID = (from t in db.Tax where t.Percentage == tax select t.ID).FirstOrDefault();

            //Create new bill header
            var newBill = new BillModels
            {
                AccountDate      = DateTime.Now,
                PaymentDate      = DateTime.Now.AddDays(30),
                InvoiceCreator   = ApplicationUser,
                InvoiceRecipient = ApplicationUser
            };

            db.Bills.Add(newBill);
            db.SaveChanges();


            //Create new BillArticle - articles on bill

            var articleDetails = db.Article.Where(u => u.ID == article).Select(u => u).FirstOrDefault();

            var newBillArticle = new BillArticleModels
            {
                BillID            = newBill.ID,
                ArticleID         = Convert.ToInt32(form["articles"]),
                UserID            = ApplicationUserID,
                TaxID             = taxID,
                Quantity          = Convert.ToInt32(form["quantity"]),
                PricePerUnitNoTax = articleDetails.Price,
                FullPriceAllNoTax = articleDetails.Price * Convert.ToInt32(form["quantity"])
            };

            db.BillArticleModels.Add(newBillArticle);
            db.SaveChanges();
        }