Ejemplo n.º 1
0
        public async Task <IActionResult> CreateClient(VMRegister vm) // Gets users identity then creates a client
        {
            if (ModelState.IsValid)
            {
                UserIdentity user = new UserIdentity();
                string       name = HttpContext.User.Identity.Name;
                user = await userManager.FindByNameAsync(name);

                Client client = new Client
                {
                    FirstName    = vm.FirstName,
                    LastName     = vm.LastName,
                    CompanyName  = vm.CompanyName,
                    Street       = vm.Street,
                    City         = vm.City,
                    State        = vm.State,
                    Zipcode      = vm.Zipcode,
                    PhoneNumber  = vm.PhoneNumber,
                    UserIdentity = user,
                    Email        = user.Email
                };

                clientRepo.Create(client);
                return(RedirectToAction("UserPage", "User"));
            }
            else
            {
                return(View(vm));
            }
        }
Ejemplo n.º 2
0
        public IActionResult AdminCreateClient(VMAdminCreateClient vm)
        {
            if (ModelState.IsValid)
            {
                Client client = new Client
                {
                    FirstName    = vm.FirstName,
                    LastName     = vm.LastName,
                    CompanyName  = vm.CompanyName,
                    Street       = vm.Street,
                    City         = vm.City,
                    State        = vm.State,
                    Zipcode      = vm.Zipcode,
                    PhoneNumber  = vm.PhoneNumber,
                    UserIdentity = vm.User,
                    Email        = vm.Email,
                };

                clientRepo.Create(client);
                return(RedirectToAction("AdminPage", "Admin"));
            }
            else
            {
                return(View(vm));
            }
        }
Ejemplo n.º 3
0
        public IActionResult Create(Client client)
        {
            if (!ModelState.IsValid)
            {
                return(View(client));
            }

            _clientRepo.Create(client);

            return(RedirectToAction("List"));
        }
Ejemplo n.º 4
0
        public IActionResult  Create(CreateClientViewModel _clientModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(_clientModel));
                }
                var clientModel = _mapper.Map <Client>(_clientModel);
                if (_clientRepo.IsClientExist(_clientModel.Name))
                {
                    return(Json(BadRequest("Client Already Exist")));
                }
                _clientRepo.Create(clientModel);

                return(Json(Ok()));
            }
            catch (Exception ex)
            {
                return(Json(BadRequest("Error Saving Client" + ex)));
            }
        }
Ejemplo n.º 5
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));
        }