public IActionResult Create(BaseCustomerModel model)
        {
            //I'm using fluentApi vaildation attribute inside BaseCustomerModel class
            var customer = _customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #2
0
        public CustomerModel CreateCustomer(BaseCustomerModel model)
        {
            var addedCustomer = context.Customers.Add(model.ToDbModel());

            context.SaveChanges();

            return(addedCustomer.Entity.ToModel());
        }
Beispiel #3
0
 public static Customer ToDbModel(this BaseCustomerModel model)
 {
     return(new Customer
     {
         Name = model.Name,
         Type = model.Type
     });
 }
Beispiel #4
0
        public async Task <CustomerModel> CreateCustomerAsync(BaseCustomerModel model)
        {
            var customer = _mapper.Map <Customer>(model);
            await _context.Customers.AddAsync(customer);

            await _context.SaveChangesAsync();

            return(_mapper.Map <CustomerModel>(customer));
        }
        public async Task <IActionResult> Create([FromBody] BaseCustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var customer = await _customerService.CreateCustomerAsync(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #6
0
        public IActionResult Create(BaseCustomerModel customerModel)
        {
            if (customerModel.Name.Length < 5)
            {
                return(BadRequest("Name must be 5 characters long"));
            }

            var customer = customerService.CreateCustomer(customerModel);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #7
0
        public async Task <IActionResult> Create(BaseCustomerModel model)
        {
            var customer = await _customerService.CreateCustomer(model);

            if (customer.Code != (int)Errors.Success)
            {
                return(Error(customer.ErrorEnum));
            }

            return(Ok(customer));
        }
Beispiel #8
0
        public IActionResult Create(BaseCustomerModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                return(BadRequest("Name can't be empty."));
            }

            var customer = customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #9
0
        public IActionResult Create(BaseCustomerModel model)
        {
            if (model == null ||
                string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.Type) ||
                model.Name.Length < 5)
            {
                return(BadRequest("Valid customer detail is required"));
            }

            var customer = _customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #10
0
        public CustomerModel CreateCustomer(BaseCustomerModel model)
        {
            var addedCustomer = context.Customers.Add(new Customer
            {
                Name = model.Name,
                Type = model.Type
            });

            context.SaveChanges();

            return(new CustomerModel
            {
                CustomerId = addedCustomer.Entity.CustomerId,
                Name = addedCustomer.Entity.Name,
                Type = addedCustomer.Entity.Type
            });
        }
Beispiel #11
0
        public IActionResult Create(BaseCustomerModel model)
        {
            //Todo add something more robust for model validation, e.g. fluentvalidation
            if (model.Name.Length < 5)
            {
                return(BadRequest("Customer name must be at least 5 characters long"));
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                return(BadRequest("Customer name is required"));
            }

            var customer = customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #12
0
        public void CreateCustoimer_Should_Create_A_Customer()
        {
            //Arrange
            var model = new BaseCustomerModel
            {
                Name = "Anita",
                Type = 2
            };

            //Act
            var customer = _sut.CreateCustomer(model);

            //Assert
            Assert.IsInstanceOf <CustomerModel>(customer);
            Assert.AreEqual("Anita", customer.Name);
            Assert.AreEqual(CustomerType.Large, customer.Type);
            Assert.AreEqual(3, _context.Customers.Count());
        }
Beispiel #13
0
        public IActionResult Create(BaseCustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Customer is not valid"));
            }

            try
            {
                var customer = _customerService.CreateCustomer(model);

                return(Created($"customer/{customer.CustomerId}", customer));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #14
0
        public async Task <APIResponse> CreateCustomer(BaseCustomerModel model)
        {
            if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Type))
            {
                return(new APIResponse(Errors.CustomerInfo_Invalid));
            }
            if (model.Name.Length < 5)
            {
                return(new APIResponse(Errors.CustomerName_Invalid));
            }

            var entity = new Customer()
            {
                Name = model.Name, Type = model.Type
            };
            var result = await _repository.CreateCustomer(entity);

            return(new APIResponse(Errors.Success, (int)HttpStatusCode.OK)
            {
                Result = result
            });
        }
        public IActionResult Create(BaseCustomerModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                return(BadRequest("Name cannot be empty"));
            }
            if (!string.IsNullOrEmpty(model.Name) && model.Name.Length < 5)
            {
                return(BadRequest("Name must be at least 5 characters"));
            }
            if (string.IsNullOrEmpty(model.Type))
            {
                return(BadRequest("Type cannot be empty"));
            }
            if (!string.IsNullOrEmpty(model.Type) && (model.Type != "Small" && model.Type != "Large"))
            {
                return(BadRequest("Type must be either Small or Large"));
            }

            var customer = customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }
Beispiel #16
0
        public IActionResult Create(BaseCustomerModel model)
        {
            var customer = customerService.CreateCustomer(model);

            return(Created($"customer/{customer.CustomerId}", customer));
        }