public ActionResult Create(ClientListFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Subcontractors = db.SubContractors.ToList();
                return(View("ClientListForm", viewModel));
            }

            var client = new ClientList
            {
                Id = Guid.NewGuid(),
                SubcontractorId = viewModel.SubcontractorId,
                FirstName       = viewModel.FirstName,
                LastName        = viewModel.LastName,
                DOB             = viewModel.DOB,
                DueDate         = viewModel.DueDate,
                Active          = viewModel.Active,
                SubmittedDate   = DateTime.Now
            };

            db.ClientLists.Add(client);
            db.SaveChanges();

            return(RedirectToAction("Create", "ContractorForm"));
        }
        public ActionResult Create()
        {
            var subcontractorlist = new ClientListFormViewModel
            {
                Subcontractors = from s in db.SubContractors
                                 join a in db.Users on s.AdministratorId equals a.Id
                                 where s.SubcontractorId == a.SubcontractorId
                                 select s,
                Heading = "Add Client Information"
            };

            if (!User.IsInRole("Admin"))
            {
                var id        = User.Identity.GetUserId();
                var usersubid = db.Users.Find(id).SubcontractorId;
                var viewModel = new ClientListFormViewModel
                {
                    Subcontractors = db.SubContractors.ToList().Where(s => s.SubcontractorId == usersubid).ToList(),
                    Heading        = "Add Client Information"
                };

                return(View("ClientListForm", viewModel));
            }


            return(View("ClientListForm", subcontractorlist));
        }
        public ActionResult Edit(Guid?id)
        {
            var client    = db.ClientLists.Find(id);
            var viewModel = new ClientListFormViewModel
            {
                Heading        = "Edit Client Information",
                Id             = client.Id,
                Subcontractors = db.SubContractors.ToList().Where(s => s.SubcontractorId == client.SubcontractorId).ToList(),
                FirstName      = client.FirstName,
                LastName       = client.LastName,
                DOB            = client.DOB,
                DueDate        = client.DueDate,
                Active         = client.Active,
                SubmittedDate  = DateTime.Now
            };

            viewModel.SubcontractorId = client.SubcontractorId;
            viewModel.DOB             = client.DOB;
            viewModel.DueDate         = client.DueDate;

            return(View("ClientListForm", viewModel));
        }
        public ActionResult Update(ClientListFormViewModel viewModel)
        {
            //if (!ModelState.IsValid)
            //{
            //    viewModel.Subcontractors = db.SubContractors.ToList();
            //    return View("ClientListForm", viewModel);
            //}

            var client = db.ClientLists.SingleOrDefault(s => s.Id == viewModel.Id);

            {
                client.SubcontractorId = new Guid(Request["SubcontractorId"]);
                client.FirstName       = viewModel.FirstName;
                client.LastName        = viewModel.LastName;
                client.DOB             = viewModel.DOB;
                client.DueDate         = viewModel.DueDate;
                client.Active          = viewModel.Active;
            };

            db.SaveChanges();
            if (!User.IsInRole("Admin"))
            {
                if (client.Active)
                {
                    return(RedirectToAction("ActiveClients", "ClientList"));
                }
                return(RedirectToAction("NonActiveClients", "ClientList"));
            }
            else
            {
                if (client.Active)
                {
                    return(RedirectToAction("AllActiveClients", "ClientList"));
                }
                return(RedirectToAction("AllNonActiveClients", "ClientList"));
            }
        }