Beispiel #1
0
        public async Task <CustomerDto> UpdateCustomerAsync(CustomerDto model)
        {
            var entity = await _customerRepository
                         .UpdateAsync(model.ToEntity());

            return(entity != null?entity.ToViewModel() : new CustomerDto());
        }
Beispiel #2
0
        public async Task <CustomerDto> CreateCustomerAsync(CustomerDto model)
        {
            var entity = await _customerRepository
                         .InsertAsync(model.ToEntity());

            return(entity.ToViewModel());
        }
        public CustomerDto Add(CustomerDto command)
        {
            var objNewCustomer = command.ToEntity();
            var objNewOrders   = command.TableOrderDtos.ToEntity();

            try
            {
                _unitOfWork.BeginTransaction();

                var existingWithSameName = _customerRepository.FindByName(command.FirstName, command.LastName);
                if (existingWithSameName != null)
                {
                    throw new Exception("User already exists with this name");
                }

                command.Id = (int)_customerRepository.Insert(objNewCustomer);

                _orderRepository.AddRang(command.Id, objNewOrders);

                _unitOfWork.CommitTransaction();
            }
            catch (Exception ex)
            {
                _unitOfWork.RollbackTransaction();

                throw ex;
            }

            var objNewOrdersCommand = objNewOrders.ToModel();

            return(new CustomerDto(command.Id, command.FirstName,
                                   command.LastName, command.City,
                                   command.Country, command.Phone, objNewOrdersCommand.ToList()));
        }
        public virtual CustomerDto UpdateCustomer(CustomerDto model)
        {
            var customer = _customerService.GetCustomerById(model.Id);

            customer = model.ToEntity(customer);
            _customerService.UpdateCustomer(customer);
            SaveCustomerAttributes(model, customer);
            SaveCustomerRoles(model, customer);

            //activity log
            _customerActivityService.InsertActivity("EditCustomer", customer.Id, _localizationService.GetResource("ActivityLog.EditCustomer"), customer.Id);

            return(customer.ToModel());
        }
        public IHttpActionResult Post([FromBody] CustomerDto customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            customer.CustomerId = _customerService.Add(customer.ToEntity());
            if (customer.CustomerId > 0)
            {
                string uri = Url.Link("DefaultApi", new { id = customer.CustomerId });
                return(Created(uri, customer));
            }

            return(BadRequest());
        }
        public IHttpActionResult Put(int id, [FromBody] CustomerDto customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = _customerService.Get(id);

            if (entity == null)
            {
                return(NotFound());
            }

            _customerService.Update(id, customer.ToEntity(entity));

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public virtual CustomerDto InsertCustomer(CustomerDto model)
        {
            var customer = model.ToEntity();

            customer.CreatedOnUtc        = DateTime.UtcNow;
            customer.LastActivityDateUtc = DateTime.UtcNow;
            if (string.IsNullOrEmpty(customer.Username))
            {
                customer.Username = customer.Email;
            }

            _customerService.InsertCustomer(customer);
            SaveCustomerAttributes(model, customer);
            SaveCustomerRoles(model, customer);

            //activity log
            _customerActivityService.InsertActivity("AddNewCustomer", customer.Id, _localizationService.GetResource("ActivityLog.AddNewCustomer"), customer.Id);
            return(customer.ToModel());
        }