Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
        // JobsController class
        public void AddServiceDetail(ServiceDetailPoco item)
        {
            using (var context = new eBikeContext())
            {
                ServiceDetail newItem  = new ServiceDetail();
                var           existing = context.Coupons.Find(item.CouponID);
                if (existing == null && item.CouponID != 0)
                {
                    throw new Exception("Coupon is not valid");
                }

                if (item.JobHours <= 0)
                {
                    throw new Exception("Job Hours must be greater than 0");
                }

                newItem.JobID       = item.JobID;
                newItem.JobHours    = item.JobHours;
                newItem.Description = item.Description;
                newItem.Comments    = item.Comments;
                if (item.CouponID == 0 || existing.CouponID != item.CouponID)
                {
                    newItem.CouponID = null;
                }
                else
                {
                    newItem.CouponID = item.CouponID;
                }

                context.ServiceDetails.Add(newItem);
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        protected void AddServiceButton_Click(Object sender, EventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                JobController control = new JobController();


                ServiceDetailPoco newItem = new ServiceDetailPoco();

                newItem.Description = DescriptionTB.Text;
                newItem.JobID       = int.Parse(JobNumberLabel.Text);

                bool success = decimal.TryParse(HoursTB.Text, out decimal hours);
                if (success)
                {
                    newItem.JobHours = hours;
                }
                else
                {
                    throw new Exception("Must enter a valid decimal for hours.");
                }

                newItem.CouponID = int.Parse(CouponDDL.SelectedValue);

                newItem.Comments = CommentsTB.Text;

                control.AddServiceDetail(newItem);

                List <ServiceDetailPoco> serviceDetail = control.ListServiceDetails(int.Parse(JobNumberLabel.Text));
                CurrentJobGridView.DataSource          = serviceDetail;
                CurrentJobGridView.DataBind();

                DescriptionTB.Text      = "";
                HoursTB.Text            = "";
                CouponDDL.SelectedIndex = 0;
                CommentsTB.Text         = "";
            }, "Service Added", "Service was successfully added to job");
        }
Exemplo n.º 4
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();
            });
        }