public void UpdateClientChecklistItem(int checklistId, bool isChecked, string type, string value, string enrollmentId, string currentUser, string userName)
        {
            string completed = isChecked ? "Y" : "N";

            ClientChecklist item = this._context.Client_Checklist.Where(r => r.ClientChecklistId == checklistId).First();

            if (item != null)
            {
                item.IndCompleted = completed;
                item.CurrentUser  = currentUser;

                if (type == "Text" || type == "Date")
                {
                    item.CommentValue = value;
                }
                else
                {
                    item.CommentValue = null;
                }
            }

            this._context.Client_Checklist.Attach(item);

            if (!string.IsNullOrEmpty(enrollmentId))
            {
                int                eid      = Convert.ToInt32(enrollmentId);
                string             status   = isChecked ? "checked" : "unchecked";
                string             text     = "Client tasklist item " + item.Text + " is " + status + " by " + userName;
                EnrollmentActivity activity = new EnrollmentActivity()
                {
                    Action       = text,
                    EnrollmentId = eid,
                    CurrentUser  = currentUser
                };

                this._context.Enrollment_Activity.Add(activity);
            }
            this._context.SaveChanges();
        }
        public void AddCandidate(AddCandidateViewModel model, int productOwnerId)
        {
            var owner = this._context.Product_Owner.Where(r => r.ProductOwnerId == productOwnerId).First();
            //Add a Candidate
            Candidate candidate = new Candidate
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                //Gender = model.Gender.ToString(),
                Gender         = "M",
                Email          = model.Email,
                AddressLine1   = model.Address,
                City           = model.City,
                State          = model.State,
                Zip            = model.Zip,
                ProductOwnerId = productOwnerId,
                ProductOwner   = owner
            };

            if (!string.IsNullOrEmpty(model.SSN))
            {
                candidate.SSN = model.SSN.Replace("-", "");
            }

            if (!string.IsNullOrEmpty(model.Phone))
            {
                candidate.Phone = model.Phone.Replace("-", "").Replace("(", "").Replace(")", "");
            }

            this._context.Candidate.Add(candidate);

            int years  = Convert.ToInt32(model.Duration.Split('-')[0]);
            int months = Convert.ToInt32(model.Duration.Split('-')[1]);

            Enrollment enrollment = new Enrollment()
            {
                Internal       = model.Internal,
                JobTitle       = model.JobTitle,
                DurationYears  = years,
                DurationMonths = months,
                PayRate        = Convert.ToDecimal(model.PayRate),
                //StartDate = model.StartDate,
                //EndDate = model.EndDate,
                OnboardedIndicator = "N",
                ActiveIndicator    = "Y",
                EmploymentTypeCode = "1",
                TaxStatusCode      = model.TaxStatus,
                ClientId           = Convert.ToInt32(model.Client),
                ClientContactId    = Convert.ToInt32(model.ClientContact),
                //VendorContactId = Convert.ToInt32(model.VendorContact)
            };

            if (!string.IsNullOrEmpty(model.BillRate) && model.Internal != "Internal")
            {
                enrollment.BillRate = Convert.ToDecimal(model.BillRate);
            }

            if (!string.IsNullOrEmpty(model.PortfolioManager) && model.Internal != "Internal")
            {
                enrollment.ProtfolioManagerId = Convert.ToInt32(model.PortfolioManager);
            }

            if (!string.IsNullOrEmpty(model.EndClient) && model.Internal != "Internal")
            {
                enrollment.EndClientId = Convert.ToInt32(model.EndClient);
            }

            if (!string.IsNullOrEmpty(model.Vendor) && model.Internal != "Internal")
            {
                if (model.TaxStatus != "W2" && model.TaxStatus != "1099")
                {
                    enrollment.VendorId = Convert.ToInt32(model.Vendor);
                }
            }

            enrollment.Candidate = candidate;
            //enrollment.EmploymentType = candidate;
            //enrollment.TaxStatus = candidate;
            //enrollment.Client = candidate;
            //enrollment.ClientContact = candidate;
            //enrollment.EndClient = candidate;
            //enrollment.Vendor = candidate;
            //enrollment.VendorContact = candidate;

            this._context.Enrollment.Add(enrollment);

            EnrollmentActivity activity = new EnrollmentActivity()
            {
                Action     = "Candidate Created",
                Enrollment = enrollment
            };

            this._context.Enrollment_Activity.Add(activity);

            //Add Enrollment Checklist
            var enrollmentChecklist = this._context.Ref_Checklist.Where(r => r.EmploymentType == model.TaxStatus).Select(r => new { r.Text, r.CommentType, r.IsActive });

            foreach (var taskItem in enrollmentChecklist)
            {
                Checklist item = new Checklist
                {
                    Text         = taskItem.Text,
                    IndCompleted = "N",
                    IsActive     = taskItem.IsActive,
                    CommentType  = taskItem.CommentType,
                    Enrollment   = enrollment
                };

                this._context.Checklist.Add(item);
            }

            //Add Vendor Checklist
            if (enrollment.VendorId != 0)
            {
                var vendorChecklist = this._context.Ref_Checklist.Where(r => r.EmploymentType == "C2C").Select(r => new { r.Text, r.CommentType, r.IsActive });
                foreach (var taskItem in vendorChecklist)
                {
                    Checklist item = new Checklist
                    {
                        Text         = taskItem.Text,
                        IndCompleted = "N",
                        IsActive     = taskItem.IsActive,
                        CommentType  = taskItem.CommentType,
                        Enrollment   = enrollment
                    };

                    this._context.Checklist.Add(item);
                }

                int vendorCount = this._context.Vendor_Checklist.Where(r => r.VendorId == enrollment.VendorId).Count();

                if (vendorCount == 0)
                {
                    var vendorLookup = this._context.Ref_Checklist.Where(r => r.EmploymentType == "V").Select(r => new { r.Text, r.CommentType, r.IsActive });
                    foreach (var taskItem in vendorLookup)
                    {
                        VendorChecklist item = new VendorChecklist
                        {
                            Text         = taskItem.Text,
                            IndCompleted = "N",
                            IsActive     = taskItem.IsActive,
                            CommentType  = taskItem.CommentType,
                            VendorId     = Convert.ToInt32(model.Vendor)
                        };

                        this._context.Vendor_Checklist.Add(item);
                    }
                }
            }

            //Add Client Checklist
            if (enrollment.ClientId != 0)
            {
                var clientChecklist = this._context.Ref_Checklist.Where(r => r.ClientId == enrollment.ClientId).Select(r => new { r.Text, r.CommentType, r.IsActive });

                foreach (var taskItem in clientChecklist)
                {
                    ClientChecklist item = new ClientChecklist
                    {
                        Text         = taskItem.Text,
                        IndCompleted = "N",
                        IsActive     = taskItem.IsActive,
                        CommentType  = taskItem.CommentType,
                        Enrollment   = enrollment
                    };

                    this._context.Client_Checklist.Add(item);
                }
            }

            this._context.SaveChanges();
        }