Beispiel #1
0
        /*
        This will manually create a job to add to the job service
         * Used when the user creates a billpay job using the web site
         * */
        public void manualCreateBPayJob(int accountNumber, int payeeID, decimal amount, string period, DateTime schedDate)
        {
            //create a database record for the newly created job then  retrive the database geneted billpay id and pass
            //it to the createScheduledJobService so it can add the job to the job service
            Debug.WriteLine("Creating and Adding a Bew Bill Pay Record to the Billpay table");
            using (NWBAEntities db = new NWBAEntities())
            {
                BillPay newBillPayRecord = new BillPay();
                newBillPayRecord.AccountNumber = accountNumber;
                newBillPayRecord.PayeeID = payeeID;
                newBillPayRecord.Amount = amount;
                newBillPayRecord.Period = period;
                newBillPayRecord.ScheduleDate = schedDate;
                newBillPayRecord.ModifyDate = DateTime.Now;

                db.BillPays.Add(newBillPayRecord);
                db.SaveChanges();
                int billPayID = newBillPayRecord.BillPayID; //EF will update the entity object with the database generated identity

                //Now we can create a job and add it to the schduler since we have a BillpayID to identify the job
                createScheduledJobService(billPayID, accountNumber, payeeID, amount, period[0], schedDate);

            }
        }
        public ActionResult GridUpdate(int Customerid)
        {
            //Above, id passed in represents the unique primary key for each row, more properties can be passed in if
            // needed eg (int id,string CustomerName)

            //Creating another viewmodel so it can be used to data validation
            //need to assign it the customer id passed from the view so the object can be passed to the repositry method to add to db
            //TO BE IMPLEMENTED LATER, AT the moment, doing nothing major
            var customerObject = new EditProfile_ViewModel
            {
                CustomerID = Convert.ToInt32(Customerid)
            };

            //Perform model binding from the view to the newly created viewmodel then validate if passes data annotations
            //Reference: http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.tryupdatemodel%28v=vs.108%29.aspx
            if (TryUpdateModel(customerObject))
            {
                NWBAEntities db = new NWBAEntities();
                Debug.WriteLine("Update Validation Passed");
                Customer customerRecord = (from x in db.Customers
                                           where x.CustomerID.Equals(Customerid)
                                           select x).SingleOrDefault();

                customerRecord.CustomerName = customerObject.CustomerName;
                customerRecord.TFN = customerObject.TFN;
                customerRecord.Address = customerObject.Address;
                customerRecord.City = customerObject.City;
                customerRecord.State = customerObject.State;
                customerRecord.PostCode = customerObject.PostCode;
                customerRecord.Phone = customerObject.Phone;

                db.SaveChanges();
                Debug.WriteLine("Updated Record in DB");
                return RedirectToAction("ChangeUserDetails", this.GridRouteValues());
            }

            Debug.WriteLine("Update Validation Failed");
            return RedirectToAction("ChangeUserDetails", this.GridRouteValues());
        }