public async Task Should_Save_ACompanyCorrectly() { using (IDbConnection conn = _sqlExecutor.OpenNewDbConnection()) { var companies = await conn.GetAsyncAll <SUBLICEN>(); SUBLICEN subl = companies.FirstOrDefault(); if (subl != null) { var code = subl.CODIGO; var company = await _companyDataService.GetAsyncCompanyDo(code); CompanyViewObject viewObject = company.Value; var dateNow = DateTime.Now.ToString("yyyyMMddHH:mm"); viewObject.ULTMODI = dateNow; var id = _companyDataService.GetNewId(); viewObject.CODIGO = id; company = _companyDataService.GetNewCompanyDo(id); company.Value = viewObject; bool saved = await _companyDataService.SaveAsync(company); var newItem = await _companyDataService.GetAsyncCompanyDo(id); Assert.IsTrue(saved); Assert.AreEqual(id, newItem.Value.CODIGO); } } }
/// <summary> /// Returns a company identifier /// </summary> /// <returns>Get a new identifier unique for the company</returns> public string GetNewId() { string id = string.Empty; using (var conn = SqlExecutor.OpenNewDbConnection()) { var sublicen = new SUBLICEN(); id = conn?.UniqueId <SUBLICEN>(sublicen); } return(id); }
/// <summary> /// Delete asynchronous data. /// </summary> /// <param name="data">Company data to be deleted.</param> /// <returns></returns> public async Task <bool> DeleteAsync(CompanyDto data) { bool retValue = false; SUBLICEN value = _mapper.Map <CompanyDto, SUBLICEN>(data); using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection()) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { retValue = await connection.DeleteAsync <SUBLICEN>(value); retValue = retValue && await DeleteOfficesAsync(connection, data.Offices).ConfigureAwait(false); scope.Complete(); } } return(retValue); }
/// <summary> /// Set the transfer objects. We create the transfer object from the entity. /// </summary> /// <param name="reader">GridReader reader of dapper results</param> /// <param name="office">Poco to check if there is a null parameter.</param> private void SetDataTransferObject(SqlMapper.GridReader reader, SUBLICEN company, ref CompanyDto dto) { // think about the GridReader. if (reader == null) { return; } if (!string.IsNullOrEmpty(company.CP)) { if (reader.IsConsumed) { return; } Helper.CityDto = MapperUtils.GetMappedValue <POBLACIONES, CityDto>(reader.Read <POBLACIONES>().FirstOrDefault(), _mapper); } if (!string.IsNullOrEmpty(company.NACIO)) { if (reader.IsConsumed) { return; } Helper.CountryDto = MapperUtils.GetMappedValue <Country, CountryDto>(reader.Read <Country>().FirstOrDefault(), _mapper); } if (!string.IsNullOrEmpty(company.PROVINCIA)) { if (reader.IsConsumed) { return; } Helper.ProvinciaDto = MapperUtils.GetMappedValue <PROVINCIA, ProvinciaDto>(reader.Read <PROVINCIA>().FirstOrDefault(), _mapper); } var listOfOffices = reader.Read <OFICINAS>().ToList(); dto.Offices = _mapper.Map <IEnumerable <OFICINAS>, IEnumerable <OfficeDtos> >(listOfOffices); }