示例#1
0
        public async Task <string> Update(EconomicOperators economicOperators)
        {
            string deleted;

            try
            {
                deleted = await _economicOperatorService.DeleteEO(economicOperators.Id);
            }
            catch
            {
                throw new Exception("No se puede modificar el EO");
            }

            if (deleted != "")
            {
                var result = await _context.EconomicOperators.AddAsync(economicOperators);

                await _context.SaveChangesAsync();

                return(result.Entity.Id);
            }
            else
            {
                throw new Exception("Error actualizando el EO");
            }
        }
示例#2
0
        public async Task <string> Handle(UpdateEOCommand request, CancellationToken cancellationToken)
        {
            EORequestDTO dto = request.Request;

            try
            {
                dto.ValidateObject("La request no puede ser null");
                LocalValidations(dto);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            var eo = new EconomicOperators();

            try
            {
                eo = new EconomicOperators
                {
                    Id          = dto.Id,
                    Name        = dto.Name,
                    Description = dto.Description,
                    Address     = dto.Address,
                    ZipCode     = dto.ZipCode,
                    City        = dto.City,
                    Country     = dto.Country,
                    ActiveFrom  = dto.ActiveFrom
                };
            }
            catch
            {
                throw new Exception("Error al formatear el EO");
            }

            try
            {
                var added = _eoRepository.Add(eo).Result;
                return(added);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#3
0
        public async Task <string> Add(EconomicOperators economicOperators)
        {
            var exist = await _economicOperatorService.GetEOById(economicOperators.Id);

            if (exist == null)
            {
                try
                {
                    var result = await _context.EconomicOperators.AddAsync(economicOperators);

                    await _context.SaveChangesAsync();

                    return(result.Entity.Id);
                }
                catch
                {
                    throw new Exception("Error creando el EO");
                }
            }
            else
            {
                throw new Exception("Ya existe este EO");
            }
        }