protected void AddServiceButton_Click(object sender, EventArgs e) { if (IsValid) { if (string.IsNullOrEmpty(CustomerName.Text) || string.IsNullOrEmpty(ContactNumber.Text)) { MessageUserControl.ShowInfo("Empty Required Field", "Missing Customer Name or Contact Number."); } else { string customer = CustomerName.Text; string contactinfo = ContactNumber.Text; string comments = Comments.Text; if (JobID == null) { MessageUserControl.TryRun(() => { JobController sysmgr = new JobController(); UserManager usrmgr = new UserManager(); ApplicationUser currentuser = (ApplicationUser)usrmgr.Users .Where(u => u.EmployeeID != null) .Select(x => x.UserName == User.Identity.Name.ToString()); List <Customer> exists = new List <Customer>(); Customer currentcustomer = exists.Find(c => c.ContactPhone == contactinfo); Job newjob = new Job(); newjob.JobDateIn = DateTime.Today; newjob.Customer.ContactPhone = ContactNumber.Text; newjob.EmployeeID = currentuser.EmployeeID.Value; newjob.Customer.CustomerID = currentcustomer.CustomerID; newjob.VehicleIdentification = "Bike"; newjob.ShopRate = decimal.Parse("50.00"); newjob.StatusCode = "O"; CurrentJobServiceDetails newServ = new CurrentJobServiceDetails(); newServ.Comments = Comments.Text; if (int.Parse(CouponDDL.SelectedValue) != 0) { newServ.CouponID = int.Parse(CouponDDL.SelectedValue); } newServ.Description = Description.Text; newServ.Hours = decimal.Parse(Hours.Text); sysmgr.Add_Job(newjob, newServ); }); } else { MessageUserControl.TryRun(() => { JobDetailsController sysmgr = new JobDetailsController(); JobDetail newjobdetail = new JobDetail(); newjobdetail.Comments = comments; if (int.Parse(CouponDDL.SelectedValue) != 0) { newjobdetail.CouponID = int.Parse(CouponDDL.SelectedValue); } else { newjobdetail.CouponID = null; } newjobdetail.Description = Description.Text; newjobdetail.JobID = int.Parse (JobID.Text); newjobdetail.JobHours = decimal.Parse(Hours.Text); sysmgr.Add_Service(newjobdetail); }); } } } }