Ejemplo n.º 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));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public IHttpActionResult Post([FromBody] BindingModels.Customer customerBindingModel)
        {
            var result = _customersManager.Add(customerBindingModel);

            return(Ok(result));
        }