public async Task <ResponseResult> InsertAsync(AttachmentInsertionDto dto)
        {
            var exist = await _repository.GetAsync(dto.SimCardId);

            if (exist == null)
            {
                var deviceExist = await _repository.GetAsync(dto.AssetId, dto.AppId);

                if (deviceExist == null)
                {
                    return(new ResponseResult
                    {
                        StatusCode = 200,
                        Message = await _repository.InsertAsync(dto.SimCardId, dto.AssetId, dto.AppId, dto.UserId, dto.Username)
                    });
                }
                return(new ResponseResult
                {
                    StatusCode = 409,
                    Message = "Device have a sim. Please detuched first."
                });
            }
            return(new ResponseResult
            {
                StatusCode = 409,
                Message = "Simcard already attached with a device."
            });
        }
 public async Task <IActionResult> Put(AttachmentInsertionDto model)
 {
     return(await CheckAndExecuteModel(async() =>
     {
         var response = await _service.InsertOrUpdateAsync(model);
         return Ok(response);
     }));
 }
 public async Task <IActionResult> Post(AttachmentInsertionDto model)
 {
     return(await CheckAndExecuteModel(async() =>
     {
         var response = await _service.InsertAsync(model);
         return StatusCode(response.StatusCode, response.Message);
     }));
 }
        public async Task <Attachment> InsertOrUpdateAsync(AttachmentInsertionDto dto)
        {
            var exist = await _repository.GetAsync(dto.SimCardId);

            if (exist == null)
            {
                return(await _repository.InsertAsync(dto.SimCardId, dto.AssetId, dto.AppId, dto.UserId, dto.Username));
            }
            else
            {
                return(_repository.Update(dto.SimCardId, dto.AssetId, dto.AppId, dto.UserId, dto.Username, exist));
            }
        }