Example #1
0
        public void AddJob(JobPoco job, ServiceDetailPoco service)
        {
            using (var context = new eBikeContext())
            {
                Job           newJob     = new Job();
                ServiceDetail newService = new ServiceDetail();
                var           existing   = context.Coupons.Find(service.CouponID);
                if (existing == null && service.CouponID != 0)
                {
                    throw new Exception("Coupon is not valid");
                }

                newService.JobHours    = service.JobHours;
                newService.Description = service.Description;
                if (service.CouponID == 0 || existing.CouponID != service.CouponID)
                {
                    newService.CouponID = null;
                }
                else
                {
                    newService.CouponID = service.CouponID;
                }
                newService.Comments = service.Comments;

                newJob.EmployeeID            = (int)job.EmployeeID;
                newJob.CustomerID            = job.CustomerID;
                newJob.JobDateIn             = job.JobDateIn;
                newJob.ShopRate              = job.ShopRate;
                newJob.StatusCode            = job.StatusCode;
                newJob.VehicleIdentification = job.VehicleIdentification;
                context.Jobs.Add(newJob).ServiceDetails.Add(newService);
                context.SaveChanges();
            }
        }
Example #2
0
        protected void AddJobButton_Click(object sender, EventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                JobController control        = new JobController();
                JobPoco newJob               = new JobPoco();
                ServiceDetailPoco newService = new ServiceDetailPoco();
                int customerId               = int.Parse(CustomerDDL.SelectedValue);
                if (employeeId == null)
                {
                    throw new Exception("Please sign in as valid employee");
                }

                if (customerId == 0)
                {
                    throw new Exception("please select a valid Customer");
                }

                bool success = (decimal.TryParse(ShopRateTB.Text, out decimal shoprate));
                if (!success)
                {
                    throw new Exception("Must enter a valid shop rate value (default 80)");
                }
                if (string.IsNullOrWhiteSpace(VehicleTB.Text))
                {
                    throw new Exception("Please enter a vehical identifaction");
                }

                success = decimal.TryParse(HoursTB.Text, out decimal hours);
                if (success && hours > 0)
                {
                    newService.JobHours = hours;
                }
                else
                {
                    throw new Exception("Must enter a valid decimal greater than 0 for hours.");
                }
                newJob.EmployeeID            = employeeId;
                newJob.CustomerID            = customerId;
                newJob.JobDateIn             = DateTime.Today;
                newJob.StatusCode            = "I";
                newJob.ShopRate              = shoprate;
                newJob.VehicleIdentification = VehicleTB.Text;

                newService.Description = DescriptionTB.Text;
                newService.CouponID    = int.Parse(CouponDDL.SelectedValue);
                newService.Comments    = CommentsTB.Text;

                control.AddJob(newJob, newService);

                DescriptionTB.Text      = "";
                HoursTB.Text            = "";
                CouponDDL.SelectedIndex = 0;
                CommentsTB.Text         = "";

                NewJobButton.Visible       = true;
                NewJobCustomer.Visible     = false;
                currentJobListForm.Visible = true;
                NewJobForm.Visible         = false;
                currentJobForm.Visible     = false;
                AddServiceButton.Visible   = true;
                AddJobButton.Visible       = false;


                JobGridView.DataSource = control.ListCurrentJobs();
                JobGridView.DataBind();
            });
        }