public ModifyPosDeviceResponse ModifyPosDevice(ModifyPosDeviceRequest request)
        {
            ModifyPosDeviceResponse response = new ModifyPosDeviceResponse();

            PosDevice posDevice = _posDeviceRepository
                                  .FindBy(request.DeviceId);

            posDevice.Id           = request.DeviceId;
            posDevice.BrandId      = request.BrandId;
            posDevice.SerialNumber = request.SerialNumber;
            posDevice.Model        = request.Model;
            posDevice.PosTerminals = request.PosTerminals.ConvertToPosTerminals();


            if (posDevice.GetBrokenRules().Count() > 0)
            {
                response.Errors = posDevice.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _posDeviceRepository.Save(posDevice);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    response.Errors = new List <BusinessRule>();
                    response.Errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                }
            }


            return(response);
        }
        public CreatePosDeviceResponse CreatePosDevice(CreatePosDeviceRequest request)
        {
            CreatePosDeviceResponse response = new CreatePosDeviceResponse();
            PosDevice posDevice = new PosDevice();

            posDevice.BrandId      = request.BrandId;
            posDevice.SerialNumber = request.SerialNumber;
            posDevice.Model        = request.Model;
            posDevice.PosTerminals = request.PosTerminals.ConvertToPosTerminals();

            if (posDevice.GetBrokenRules().Count() > 0)
            {
                response.Errors = posDevice.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _posDeviceRepository.Add(posDevice);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    List <BusinessRule> errors = new List <BusinessRule>();
                    do
                    {
                        errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                        ex = ex.InnerException;
                    } while (ex != null);

                    response.Errors = errors;
                }
            }

            return(response);
        }
        public GetPosDeviceResponse GetPosDevice(GetPosDeviceRequest request)
        {
            GetPosDeviceResponse response = new GetPosDeviceResponse();

            PosDevice posDevice = _posDeviceRepository
                                  .FindBy(request.DeviceId);

            if (posDevice != null)
            {
                response.PosDeviceFound = true;
                response.PosDevice      = posDevice.ConvertToPosDeviceView();
            }
            else
            {
                response.PosDeviceFound = false;
            }


            return(response);
        }
 public static PosDeviceView ConvertToPosDeviceView(
     this PosDevice posDevice)
 {
     return(Mapper.Map <PosDevice,
                        PosDeviceView>(posDevice));
 }