Exemplo n.º 1
0
        public ActionResult AddClient(ClientVM c)
        {
            ITrainerRepo trepo = TrainerRepoFactory.Create();
            IClientRepo  repo  = ClientRepoFactory.Create();

            if (ModelState.IsValid)
            {
                c.Trainers = new List <Trainer>();

                var client = new Client
                {
                    Trainers       = new List <Trainer>(),
                    ClientName     = c.ClientName,
                    StartingWeight = c.StartingWeight,
                    CurrentWeight  = c.CurrentWeight,
                    FitnessGoals   = c.FitnessGoals,
                };
                foreach (var trainerID in c.SelectedTrainerID)
                {
                    client.Trainers.Add(trepo.GetTrainerById(trainerID));
                }
                repo.AddClient(client);
            }

            else
            {
                return(View(c));
            }
            return(RedirectToAction("ClientList"));
        }
Exemplo n.º 2
0
        public ActionResult <ClientModel> AddNewClient(ClientViewModel client)
        {
            var clientAdd = new ClientModel()
            {
                Id          = client.Id,
                ClientName  = client.ClientName,
                Cnp         = client.Cnp,
                DateOfBirth = client.DateOfBirth,
                PhoneNumber = client.PhoneNumber,
                Address     = client.Address,
                UserId      = client.UserId,
            };

            _clientRepo.AddClient(clientAdd);
            return(clientAdd);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> RegisterClient(ClientCreateDto client)
        {
            if (await _clientRepo.ClientExists(client.Email))
            {
                return(StatusCode(400, new { Error = $"{client.Email} is a registered client already" }));
            }

            var _client = await _clientRepo.AddClient(client);

            if (_client == null)
            {
                return(StatusCode(500, new { Error = "Could not register client." }));
            }
            else
            {
                //send mail to customer
                _emailer.SendEmailToClient(client);

                return(StatusCode(201, _mapper.Map <ClientDisplayDto>(_client)));
            }
        }