예제 #1
0
        public ViewModels.Customer Add(BindingModels.Customer customerBindingModel)
        {
            if (customerBindingModel == null)
            {
                throw new ArgumentNullException(nameof(customerBindingModel));
            }

            var customerEntity = AutoMapper.Mapper.Map <Entities.Customer>(customerBindingModel);
            var addedCustomer  = _unitOfWork.RepositoryFor <Entities.Customer>().Insert(customerEntity);

            _unitOfWork.SaveChanges();

            return(AutoMapper.Mapper.Map <ViewModels.Customer>(addedCustomer));
        }
예제 #2
0
        public IHttpActionResult Put([FromUri] Guid id, [FromBody] BindingModels.Customer customerBindingModel)
        {
            if (id != customerBindingModel.Id)
            {
                return(BadRequest("Customer ID is not same."));
            }

            bool result = _customersManager.Update(customerBindingModel);

            if (result)
            {
                return(Ok());
            }
            return(NotFound());
        }
예제 #3
0
        public bool Update(BindingModels.Customer customerBindingModel)
        {
            if (customerBindingModel == null)
            {
                throw new ArgumentNullException(nameof(customerBindingModel));
            }

            var  customerEntity = AutoMapper.Mapper.Map <Entities.Customer>(customerBindingModel);
            bool result         = _unitOfWork.RepositoryFor <Entities.Customer>().Update(customerEntity);

            if (result)
            {
                _unitOfWork.SaveChanges();
            }

            return(result);
        }
예제 #4
0
        public IHttpActionResult Post([FromBody] BindingModels.Customer customerBindingModel)
        {
            var result = _customersManager.Add(customerBindingModel);

            return(Ok(result));
        }