Exemple #1
0
        public IActionResult Post([FromBody] InsuranceProviderViewModel insuranceProviderViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Create the InsuranceProvider
            var newInsuranceProvider = _mapper.Map <InsuranceProviderViewModel, InsuranceProvider>(insuranceProviderViewModel);

            _unitOfWork.InsuranceProviders.Add(newInsuranceProvider);
            // Commit changes to the database to get InsuranceProviderId
            _unitOfWork.SaveChanges();

            CreatedAtRouteResult result = CreatedAtRoute("Get", new { controller = "InsuranceProviders", id = newInsuranceProvider.Id }, newInsuranceProvider);

            return(result);
        }
Exemple #2
0
        public IActionResult Put(int id, [FromBody] InsuranceProviderViewModel insuranceProviderViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Get the InsuranceProvider to Edit
            var _insuranceProvider = _unitOfWork.InsuranceProviders
                                     .GetSingle(id);

            if (_insuranceProvider == null)
            {
                return(NotFound());
            }
            else
            {
                _insuranceProvider.AddressLine1 = insuranceProviderViewModel.AddressLine1;
                _insuranceProvider.AddressLine2 = insuranceProviderViewModel.AddressLine2;
                _insuranceProvider.DistrictId   = insuranceProviderViewModel.DistrictId;
                _insuranceProvider.EmailAddress = insuranceProviderViewModel.EmailAddress;
                _insuranceProvider.Fax          = insuranceProviderViewModel.Fax;
                _insuranceProvider.ProviderCode = insuranceProviderViewModel.ProviderCode;
                _insuranceProvider.ProviderName = insuranceProviderViewModel.ProviderName;
                //_insuranceProvider.Status = insuranceProviderViewModel.Status;
                _insuranceProvider.Telephone1 = insuranceProviderViewModel.Telephone1;
                _insuranceProvider.Telephone2 = insuranceProviderViewModel.Telephone2;
                _insuranceProvider.Telephone3 = insuranceProviderViewModel.Telephone3;
                _insuranceProvider.Website    = insuranceProviderViewModel.Website;

                // Put logic to handle inputer, maker, checker
            }

            insuranceProviderViewModel = _mapper.Map <InsuranceProvider, InsuranceProviderViewModel>(_insuranceProvider);

            return(new NoContentResult());
        }