public async Task <IActionResult> PostAsync([FromBody] BusinessCreateModel model)
        {
            try
            {
                var bm = new BusinessModel
                {
                    Name            = model.BusinessName,
                    Code            = model.AddressPostCode,
                    AddressStreet   = model.AddressStreet,
                    AddressCity     = model.AddressCity,
                    AddressPostCode = model.AddressPostCode,
                    Contact1Name    = model.Contact1Name,
                    Contact1Email   = model.Contact1Email,
                    Contact1Mobile  = model.Contact1Mobile,
                    Contact2Email   = model.Contact2Email,
                    Contact2Name    = model.Contact2Name,
                    Contact2Mobile  = model.Contact2Name,
                    Status          = RegistrationStatus.Submitted,
                    BusinessTypeId  = 1
                };

                var k = await service.InsertBusinessAsync(bm);

                bm.Id = k.Id;
                foreach (var item in model.StakeHolders)
                {
                    var stk = new StakeHolderModel
                    {
                        BusinessId      = bm.Id,
                        SSN             = item.SSN,
                        FirstName       = item.FirstName,
                        LastName        = item.FirstName,
                        Email           = item.Email,
                        Mobile          = item.Mobile,
                        BirthDate       = item.BirthDate,
                        AddressStreet   = item.AddressStreet,
                        AddressCity     = item.AddressCity,
                        AddressPostCode = item.AddressPostCode,
                        SeedCapital     = item.SeedCapital,
                        BankName        = item.BankName,
                        AccountNumber   = item.AccountNumber
                    };

                    await stakeHolderService.InsertAsync(stk);
                }
                _emailService.SendEmailAsync(model.Contact1Email, null, "Business Search", "Hello " + model.Contact1Name + ", " +
                                             "your application has been recieved by Yellow Project " +
                                             "and our person will get accross to you. Thank you!");
                return(new OkResult());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
 public async Task <IActionResult> Post([FromBody] StakeHolderModel value)
 {
     try
     {
         return(Ok(await service.InsertAsync(value)));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Beispiel #3
0
        public async Task <StakeHolderForm> InsertAsync(StakeHolderModel model)
        {
            if (model.BusinessId < 1)
            {
                throw new ArgumentException("Please provide a valid business type");
            }
            var obj  = DataMapper.Map <StakeHolder, StakeHolderModel>(model);
            var item = await Task.Run(() => repo.Insert(obj));

            return(DataMapper.Map <StakeHolderForm, StakeHolder>(item));
        }
Beispiel #4
0
        public async Task <StakeHolderForm> UpdateAsync(StakeHolderModel model)
        {
            if ((await GetSingleAsync(model.Id)) is null)
            {
                throw new ArgumentException("Cannot locate business");
            }
            var item = DataMapper.Map <StakeHolder, StakeHolderModel>(model);

            await Task.Run(() => repo.Update(item));

            return(DataMapper.Map <StakeHolderForm, StakeHolder>(item));
        }
        public async Task <IActionResult> Put([FromBody] StakeHolderModel value)
        {
            try
            {
                await service.UpdateAsync(value);

                return(Ok());
            }
            catch
            {
                return(NotFound());
            }
        }