[HttpPost("")] //  ./api/customers
        public IActionResult Create([FromBody] CustomerCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {   //rules failed, return a well formed error
                _logger.LogWarning("Customer Create failed due to validation");
                return(new ValidationFailedResult(ModelState));
            }

            var customer = new Customer
            {
                FirstName              = model.FirstName,
                LastName               = model.LastName,
                EmailAddress           = model.EmailAddress,
                PhoneNumber            = model.PhoneNumber,
                PreferredContactMethod = model.PreferredContactMethod,
                LastContactDate        = DateTime.UtcNow
            };

            _customerData.Add(customer);
            _customerData.Commit();
            Response.Headers.Add("ETag", "\"" + customer.LastContactDate.ToString() + "\"");
            return(Ok(new CustomerDisplayViewModel(customer))); //includes new auto-assigned id
        }
        public IActionResult Create(AgreementViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newAgreement = new Agreement();
                newAgreement.Amount            = model.Amount;
                newAgreement.AgreementDuration = model.AgreementDuration;
                newAgreement.BaseRateCode      = model.BaseRateCode;
                newAgreement.Margin            = model.Margin;
                newAgreement.BaseRate          = _baseRateReposirory.GetRate(model.BaseRateCode).Result;

                var customer = _customerData.GetAllCustomers().FirstOrDefault(c => c.PersonalId == model.Customer.PersonalId);

                if (customer == null)
                {
                    var newCustomer = new Customer();
                    newCustomer.FirstName  = model.Customer.FirstName;
                    newCustomer.LastName   = model.Customer.LastName;
                    newCustomer.PersonalId = model.Customer.PersonalId;
                    newCustomer.Agreements.Add(newAgreement);
                    newCustomer = _customerData.Add(newCustomer);
                    _customerData.Save();

                    return(RedirectToAction("AgreementDetails", new { id = newCustomer.Agreements.Max(a => a.Id) }));
                }

                customer.Agreements.Add(newAgreement);
                _customerData.Save();

                return(RedirectToAction("AgreementDetails", new { id = customer.Agreements.Max(a => a.Id) }));
            }

            return(View());
        }
        public IActionResult Post([FromBody] Customer customer)
        {
            customerData.Add(customer);
            customerData.Commit();

            // This does the same as our responsemessage extension
            return(CreatedAtRoute("GetCustomer",
                                  new { id = customer.Id },
                                  customer));
        }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] CustomerViewModel customerViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            _customerData.Add(_mapper.Map <Customer>(customerViewModel));
            await _uow.Commit();

            return(Ok());
        }
Esempio n. 5
0
        public IActionResult Create(Customer model)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customer
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    PhoneNumber     = model.PhoneNumber,
                    OptInNewsletter = model.OptInNewsletter,
                    Type            = model.Type
                };
                _customerData.Add(customer);

                return(RedirectToAction(nameof(Details), new { id = customer.Id }));
            }
            return(View());
        }
Esempio n. 6
0
        [HttpPost("")] //  ./api/customers
        public IActionResult Create([FromBody] CustomerCreateViewModel model)
        {
            var customer = new Customer
            {
                FirstName              = model.FirstName,
                LastName               = model.LastName,
                EmailAddress           = model.EmailAddress,
                PhoneNumber            = model.PhoneNumber,
                PreferredContactMethod = model.PreferredContactMethod,
                LastContactDate        = DateTime.UtcNow
            };

            _customerData.Add(customer);
            _customerData.Commit();

            Response.Headers.Add("ETag", "\"" + customer.LastContactDate.ToString() + "\"");
            return(Ok(new CustomerDisplayViewModel(customer)));
        }
        public IActionResult Create(CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            { //the validation attributes all pass
                var customer = new Customer
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    PhoneNumber     = model.PhoneNumber,
                    OptInNewsletter = model.OptInNewsletter,
                    Type            = model.Type
                };
                _customerData.Add(customer);

                return(RedirectToAction(nameof(Details), new { id = customer.Id }));
            }
            //one or more validations did not pass.
            return(View());
        }
        [HttpPost("")] //  ./api/customers
        public IActionResult Create([FromBody] CustomerCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(new ValidationFailedResult(ModelState));
            }

            var customer = new Customer
            {
                FirstName              = model.FirstName,
                LastName               = model.LastName,
                EmailAddress           = model.EmailAddress,
                PhoneNumber            = model.PhoneNumber,
                PreferredContactMethod = model.PreferredContactMethod
            };

            _customerData.Add(customer);
            _customerData.Commit();
            return(Ok(new CustomerDisplayViewModel(customer))); //includes new auto-assigned id
        }
        public async Task <IActionResult> Create(CustomerModel customerModel)
        {
            if (ModelState.IsValid)
            {
                var newCustomer = new Customer();
                newCustomer.Name           = customerModel.Name;
                newCustomer.Email          = customerModel.Email;
                newCustomer.PrimaryPhone   = customerModel.PrimaryPhone;
                newCustomer.AlternatePhone = customerModel.AlternatePhone;
                newCustomer.Address1       = customerModel.Address1;
                newCustomer.Address2       = customerModel.Address2;
                newCustomer.Address3       = customerModel.Address3;
                newCustomer.City           = customerModel.City;
                newCustomer.State          = customerModel.State;
                newCustomer.Country        = customerModel.Country;
                newCustomer.Zip            = customerModel.Zip;
                newCustomer = _customerdata.Add(newCustomer);

                _customerdata.Commit();

                return(RedirectToAction("Index"));
            }
            return(View());
        }