Ejemplo n.º 1
0
        public async Task <TypedResult <CountryDTO> > Update(UpdateRegionCountry regionCountry)
        {
            try
            {
                if (regionCountry.Id.Equals(Guid.Empty))
                {
                    throw new InvalidOperationException(ErrorMessages.ID_IS_REQUIRED);
                }
                RegionCountry existsRecord = await regionCountryRepo.FindById(regionCountry.Id);

                if (existsRecord == null)
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_DOES_NOT_EXISTS);
                }

                existsRecord.Title = regionCountry.Title;
                RegionCountry result = await regionCountryRepo.Update(existsRecord);

                return(new TypedResult <CountryDTO>(_mapper.Map <CountryDTO>(result)));
            }
            catch (Exception ex)
            {
                return(new TypedResult <CountryDTO>(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <TypedResult <Boolean> > Remove(Guid Id)
        {
            try
            {
                RegionCountry existsRecord = await regionCountryRepo.FindById(Id);

                if (existsRecord == null)
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_DOES_NOT_EXISTS);
                }
                Boolean result = await regionCountryRepo.Delete(Id);

                return(new TypedResult <Boolean>(result));
            }
            catch (Exception ex)
            {
                return(new TypedResult <Boolean>(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task <TypedResult <CountryDTO> > Add(InsertRegionCountry regionCountry)
        {
            try
            {
                RegionCountry existsRecord = (await regionCountryRepo.GetList(condition: x => x.Title.Equals(regionCountry.Title))).FirstOrDefault();
                if (existsRecord != null)
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_ALREADY_EXISTS);
                }

                RegionCountry entity = _mapper.Map <RegionCountry>(regionCountry);
                RegionCountry result = await regionCountryRepo.Add(entity);

                return(new TypedResult <CountryDTO>(_mapper.Map <CountryDTO>(result)));
            }
            catch (Exception ex)
            {
                return(new TypedResult <CountryDTO>(ex));
            }
        }