예제 #1
0
        public IActionResult CreateProject(int bidID)
        {
            VMCreateProject projectVM = new VMCreateProject();                     //creates vm to pass to view
            Bid             b         = bidrepo.GetBidByID(bidID);                 //gets appropriate bid from database
            Client          c         = clientRepo.GetClientByEmail(b.User.Email); //looks for client from database

            if (c == null)                                                         //if client not found
            {
                //create client
                Client altC = new Client();
                altC.Email        = b.User.Email;
                altC.FirstName    = b.User.FirstName;
                altC.LastName     = b.User.LastName;
                altC.PhoneNumber  = b.User.PhoneNumber;
                altC.UserIdentity = b.User;
                clientRepo.Create(altC);

                //finds created client, now in database
                Client createdClient = clientRepo.GetClientByEmail(altC.Email);

                b.User.ClientCreated = true; //confirms client now exists

                //adds bid and client info to project object
                projectVM.BidID    = bidID;
                projectVM.LastName = b.User.LastName;
                projectVM.ClientID = createdClient.ClientID;
                projectVM.Email    = b.User.Email;
            }
            else //if client is found
            {
                //adds client and bid to project
                projectVM.BidID    = bidID;
                projectVM.ClientID = c.ClientID;
                projectVM.LastName = b.User.LastName;
                projectVM.Email    = b.User.Email;
            }

            return(View(projectVM));
        }
예제 #2
0
        public IActionResult CreateProject(VMCreateProject projectVM)
        {
            //if model requirements fulfilled
            if (ModelState.IsValid)
            {
                //finds user in Clients based on Email from user
                Client client = clientRepo.GetClientByEmail(projectVM.Email);

                if (clientRepo.ContainsClient(client) == true) //(client != null)
                {
                    //if client is entered and found

                    //searches for open bid for given client
                    Bid bid = bidrepo.GetBidByID(projectVM.BidID);

                    if (bid != null)
                    {
                        //create project
                        Project project = new Project
                        {
                            ProjectID        = projectVM.ProjectID,
                            Client           = clientRepo.GetClientById(projectVM.ClientID),
                            ProjectName      = projectVM.ProjectName,
                            StartDate        = projectVM.StartDate,
                            OriginalEstimate = projectVM.Estimate,
                            Bid           = bidrepo.GetBidByID(projectVM.BidID),
                            ProjectStatus = "Started", StatusDate = DateTime.Today
                        };
                        project.TotalCost = project.OriginalEstimate;

                        //if client and bid are valid
                        if (project.Client != null && project.Bid != null)
                        {
                            //add project to database
                            projectRepo.ProjectUpdate(project);
                        }
                        else
                        {
                            ModelState.AddModelError("Email", "Either the attributed Client or Bid is invalid");
                        }

                        return(RedirectToAction("AdminPage", "Admin"));
                    }
                    else
                    {
                        //if bid not found
                        ModelState.AddModelError("Email", "Could not find open bid for client tied to that email");
                    }
                }
                else
                {
                    //if user not found
                    ModelState.AddModelError("LastName", "There is no client found in the system with that e-mail");
                }
            }
            else
            {
                //if model not valid
                ModelState.AddModelError("Email", "Please make sure all fields are filled");
            }

            return(View(projectVM));
        }