Esempio n. 1
0
        public async Task <ActionResult> PutCustomer(int id, [FromBody] CustomersForUpdate customer)
        {
            _orm.OpenConn();
            if (!await _orm.CustomerExist(id))
            {
                return(NotFound());
            }

            var customerFromDB = await _orm.GetCustomerById(id);

            //Map from customerFromDB (Source) to customer (Destination)
            //Apply Updated fields values to that dto
            //Map from customer (Source) to customerFromDB (Destination)
            //aka. copying values from source to destination
            _mapper.Map(customer, customerFromDB);

            if (await _orm.UpdateCustomer(customerFromDB) == 0)
            {
                return(BadRequest());
            }

            await _orm.CloseConn();

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <OrderDto> > CreateOrderForCustomer(int customerID, OrderForCreateDto orderForCreateDto)
        {
            //Change status to waiting for treatment of order
            orderForCreateDto.StatusID = 1;
            _orm.OpenConn();
            if (!await _orm.CustomerExist(customerID))
            {
                return(NotFound());
            }
            Order orderFromDB = _mapper.Map <Order>(orderForCreateDto);

            orderFromDB.CustomerID = customerID;
            Order result = await _orm.CreateOrderAndOrderLines(orderFromDB);

            OrderDto orderDto = _mapper.Map <OrderDto>(result);
            await _orm.CloseConn();

            return(CreatedAtRoute("GetOrder", new { customerID = customerID, orderID = orderDto.Ordernumber }, orderDto));
        }