Example #1
0
 public async Task <Client> CreateAsync(ClientCreation payload, int userId)
 {
     return(await _clientRespository.CreateAsync(new Client
     {
         CreateUserId = userId,
         Name = payload.Name,
     }));
 }
Example #2
0
 public async Task <Client> CreateAsync(ClientCreation payload, int userId)
 {
     return(await _clientService.CreateAsync(payload, userId));
 }
Example #3
0
        public ActionResult CreateClient(ClientCreation clientCreation)
        {
            if (ModelState.IsValid)
            {
                var clientEntity = new Client()
                {
                    ClientID             = clientCreation.client.ClientID,
                    ClientName           = clientCreation.client.ClientName,
                    ClientUsername       = clientCreation.client.ClientUsername,
                    ClientPassword       = clientCreation.client.ClientPassword,
                    ClientPrimaryPhone   = clientCreation.client.ClientPrimaryPhone,
                    ClientSecondaryPhone = clientCreation.client.ClientSecondaryPhone,
                    ClientEmail          = clientCreation.client.ClientEmail,
                    ClientBalance        = 100
                };
                var addressEntity = new Address()
                {
                    AddressLine1 = clientCreation.address.AddressLine1,
                    AddressLine2 = clientCreation.address.AddressLine2,
                    City         = clientCreation.address.City,
                    Country      = clientCreation.address.Country,
                    State        = clientCreation.address.State,
                    Zip          = clientCreation.address.Zip
                };
                var paymentInfoEntity = new PaymentInfo()
                {
                    CardNum    = clientCreation.paymentInfo.CardNum,
                    SecCode    = clientCreation.paymentInfo.SecCode,
                    NameOnCard = clientCreation.paymentInfo.NameOnCard,
                    ExpMonth   = clientCreation.paymentInfo.ExpMonth,
                    ExpYear    = clientCreation.paymentInfo.ExpYear
                };



                db.Client.Add(clientEntity);
                db.Address.Add(addressEntity);
                db.PaymentInfo.Add(paymentInfoEntity);
                db.SaveChanges();

                int newClient      = (int)clientEntity.ClientID;
                int newPaymentInfo = (int)paymentInfoEntity.PaymentInfoID;

                using (db)
                {
                    var address = db.Address.FirstOrDefault(x => x.AddressID == addressEntity.AddressID);

                    if (address == null)
                    {
                        throw new Exception("Invalid id: " + addressEntity.AddressID);
                    }

                    address.ClientID = newClient;

                    var client = db.Client.FirstOrDefault(x => x.ClientID == clientEntity.ClientID);

                    if (client == null)
                    {
                        throw new Exception("Invalid id: " + clientEntity.ClientID);
                    }

                    client.PaymentInfoID = newPaymentInfo;

                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Portal", new { id = newClient }));
            }

            return(View());
        }
Example #4
0
        public async Task <OkMessage <int> > PostAsync(ClientCreation payload)
        {
            var data = await _clientApplication.CreateAsync(payload, UserId);

            return(OkMessage(data.Id));
        }