示例#1
0
        //
        // POST: /IngoingInvoice/Delete/5
        public ActionResult Delete(int id)
        {
            IngoingInvoice ingoingInvoice = ctx.IngoingInvoices.Where(o => o.IdIngoingInvoice == id).First();
            string         currUserId     = User.Identity.GetUserId();

            //redirects user to the 403 page if he is trying to change data that is not his own
            if (ingoingInvoice.ApplicationUserId != currUserId)
            {
                throw new HttpException(403, "Forbidden");
            }
            try
            {
                // TODO: Add delete logic here

                ctx.IngoingInvoices.Remove(ingoingInvoice);


                ctx.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Error", "Shared"));
            }
        }
示例#2
0
        public ActionResult Create(IngoingInvoiceViewModel ingoingInvoiceView)
        {
            try
            {
                // TODO: Add insert logic here
                string currUserId = User.Identity.GetUserId();

                decimal  amount = Convert.ToDecimal(ingoingInvoiceView.Amount);
                DateTime date   = Convert.ToDateTime(ingoingInvoiceView.Date);

                IngoingInvoice ingoingInvoice = new IngoingInvoice()
                {
                    ApplicationUserId  = currUserId,
                    DateIngoingInvoice = date,
                    InvoiceClassNumber = ingoingInvoiceView.InvoiceClassNumber,
                    SupplierInfo       = ingoingInvoiceView.SupplierInfo,
                    Amount             = amount
                };


                ctx.IngoingInvoices.Add(ingoingInvoice);
                ctx.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Error", "Shared"));
            }
        }
示例#3
0
        //
        // GET: /IngoingInvoice/Edit/5
        public ActionResult Edit(int id)
        {
            IngoingInvoice ingoingInvoice = ctx.IngoingInvoices.Where(i => i.IdIngoingInvoice == id).First();

            string currUserId = User.Identity.GetUserId();

            //redirects user to the 403 page if he is trying to change data that is not his own
            if (ingoingInvoice.ApplicationUserId != currUserId)
            {
                throw new HttpException(403, "Forbidden");
            }

            IngoingInvoiceViewModel ingoingInvoiceView = new IngoingInvoiceViewModel()
            {
                Id = ingoingInvoice.IdIngoingInvoice,
                ApplicationUserId = ingoingInvoice.ApplicationUserId,
                Date = ingoingInvoice.DateIngoingInvoice.ToShortDateString(),
                InvoiceClassNumber = ingoingInvoice.InvoiceClassNumber,
                SupplierInfo       = ingoingInvoice.SupplierInfo,
                Amount             = ingoingInvoice.Amount.ToString()
            };

            return(View(ingoingInvoiceView));
        }