public ActionResult Edit(int?id)
        {
            ProjectInfo proj = db.ProjectInfo.Where(p => p.ProjectID == (id ?? 0)).FirstOrDefault();

            if (proj == null)
            {
                return(HttpNotFound());
            }
            ProjectLeadInfo pli = db.ProjectLeadInfo.Where(p => p.ProjectID == (id ?? 0)).FirstOrDefault() ?? new ProjectLeadInfo();

            var siteCoID = siteusercompanyid;

            ViewBag.Clients               = new SelectList(db.GetContactsBySiteCoID(siteCoID).ToList(), "ViewID", "Customer");
            ViewBag.Builders              = new SelectList(db.GetBuildersBySiteCoID(siteCoID).ToList(), "ViewID", "Builder");
            ViewBag.ProjectStatus         = new SelectList(db.GetLeadStatusBySiteCoID(siteCoID), "ViewID", "Status");
            ViewBag.Types                 = new SelectList(repo.GetCoLeadTypes(siteCoID), "LeadTypeID", "LeadType");
            ViewBag.Probabilities         = new SelectList(db.GetLeadProbabilityBySiteCoID(siteCoID), "ViewID", "LeadProp");
            ViewBag.Phases                = new SelectList(db.GetLeadStagesBySiteCoID(siteCoID), "ViewID", "LeadStage");
            ViewBag.Priorities            = new SelectList(db.GetLeadRatingsBySiteCoID(siteCoID), "ViewID", "LeadRating");
            ViewBag.Systems               = new SelectList(db.GetLeadSystemsBySiteCoID(siteCoID), "ViewID", "LeadSystems");
            ViewBag.ProjectCommunications = db.GetProjectCommByProjectID(id ?? 0).ToList();

            var siteUsers = db.GetSiteUsersBySiteCoID(siteCoID).ToList();

            ViewBag.SiteUsers = new SelectList(siteUsers, "ViewID", "User", siteusercompanyid);

            LeadModels.NewLead model = new LeadModels.NewLead();

            model = new LeadModels.NewLead()
            {
                Address1      = proj.ProjectAddress1,
                Address2      = proj.ProjectAddress2,
                Budget        = pli.LeadBudget,
                City          = proj.ProjectCity,
                ClientID      = proj.ContactID,
                CloseDate     = pli.LeadCloseDate,
                BuilderID     = proj.BuilderID,
                Site          = proj.Site,
                Lot           = proj.Lot,
                Email         = proj.ProjectEmail,
                Phone         = proj.ProjectPhone,
                JobNumber     = proj.ProjectNumber,
                LeadID        = proj.ProjectID,
                LeadName      = proj.ProjectName,
                LeadPhaseID   = pli.StageID,
                PriorityID    = pli.RatingID,
                ProbabilityID = pli.LeadProbabilityID,
                SalesPersonID = proj.SalesID,
                State         = proj.ProjectState,
                Country       = proj.ProjectCountry,
                StatusID      = proj.ProjectStatusID,
                TypeID        = pli.LeadTypeID,
                Zip           = proj.ProjectZip,
                SystemID      = pli.LeadSystemTypeID
            };

            return(View("_Edit", model));
        }
        private int SaveLead(Models.LeadModels.NewLead Model)
        {
            int siteCoID = siteusercompanyid;

            var lead = new ProjectInfo()
            {
                ProjectID = Model.LeadID ?? 0,
                SiteCoID  = siteCoID,
                //ProjectTypeID = Model.TypeID,
                ProjectName     = Model.LeadName,
                ProjectNumber   = Model.JobNumber ?? "",
                ProjectStatusID = Model.StatusID,
                ContactID       = Model.ClientID,
                ProjectAddress1 = Model.Address1,
                ProjectAddress2 = Model.Address2,
                ProjectCity     = Model.City,
                ProjectState    = Model.State,
                ProjectCountry  = Model.Country,
                ProjectZip      = Model.Zip,
                ProjectPhone    = Model.Phone,
                ProjectEmail    = Model.Email,
                DateUploaded    = DateTime.Now,
                BuilderID       = Model.BuilderID,
                Site            = Model.Site,
                Lot             = Model.Lot,
                SalesID         = Model.SalesPersonID,
                ProjectTypeID   = 6
            };

            ProjectLeadInfo pli = new ProjectLeadInfo()
            {
                SiteCoID          = siteCoID,
                ProjectID         = Model.LeadID,
                StatusID          = Model.StatusID,
                LeadTypeID        = Model.TypeID,
                LeadBudget        = Model.Budget,
                RatingID          = Model.PriorityID,
                LeadProbabilityID = Model.ProbabilityID,
                LeadCloseDate     = Model.CloseDate,
                StageID           = Model.LeadPhaseID,
                LeadSystemTypeID  = Model.SystemID,
                LeadDateModified  = DateTime.Now
            };

            using (TransactionScope tran = new TransactionScope())
            {
                var projectId = repo.SaveProjectInfo(lead);
                var pliId     = repo.AddProjectLeadInfo(pli, projectId);
                repo.SaveProjectCommunications(projectId, Model.ProjectCommunicationIDs.Where(p => p > 0));

                tran.Complete();

                return(projectId);
            }
        }
        public ActionResult Edit(int?id)
        {
            ProjectInfo proj = db.ProjectInfo.Where(p => p.ProjectID == (id ?? 0)).FirstOrDefault();

            if (proj == null)
            {
                return(HttpNotFound());
            }
            ProjectLeadInfo pli = db.ProjectLeadInfo.Where(p => p.ProjectID == (id ?? 0)).FirstOrDefault() ?? new ProjectLeadInfo();

            var siteCoID  = siteusercompanyid;
            var siteUsers = db.GetSiteUsersBySiteCoID(siteCoID).ToList();

            ViewBag.Clients       = new SelectList(db.GetContactsBySiteCoID(siteCoID).ToList(), "ViewID", "Customer");
            ViewBag.ProjectStatus = new SelectList(db.GetQuoteStatusBySiteCoID(siteCoID), "ViewID", "Status");
            ViewBag.SiteUsers     = new SelectList(siteUsers, "ViewID", "User");
            ViewBag.Builders      = new SelectList(db.GetBuildersBySiteCoID(siteCoID).ToList(), "ViewID", "Builder");

            LoadAdditionalDropdownData();
            LoadAdditionalGridData(id ?? 0);

            ViewBag.ProjectStages = db.GetProjectStagesByProjectID(id).ToList();

            QuoteModels.NewQuote model = new QuoteModels.NewQuote();

            model = new QuoteModels.NewQuote()
            {
                QuoteID          = proj.ProjectID,
                Address1         = proj.ProjectAddress1,
                Address2         = proj.ProjectAddress2,
                City             = proj.ProjectCity,
                ClientID         = proj.ContactID,
                Email            = proj.ProjectEmail,
                JobPhone         = proj.ProjectPhone,
                JobNumber        = proj.ProjectNumber,
                SalesPersonID    = proj.SalesID,
                State            = proj.ProjectState,
                Country          = proj.ProjectCountry,
                StatusID         = proj.ProjectStatusID,
                Zip              = proj.ProjectZip,
                DesignerID       = proj.DesignerID,
                ProjectManagerID = proj.PmID,
                QuoteName        = proj.ProjectName,
                BuilderID        = proj.BuilderID,
                Site             = proj.Site,
                Lot              = proj.Lot,
                StartDate        = proj.ProjectStartDate
            };

            return(View("_Edit", model));
        }