public async Task <MtrContactos> Insert(MtrContactos mtrContactos) { await _unitOfWork.MtrContactosRepository.Add(mtrContactos); await _unitOfWork.SaveChangesAsync(); return(mtrContactos); }
public async Task <List <MtrContactos> > GetByEmailContactosCliente(MtrClienteQueryFilter filter) { if (filter.PageSize == 0) { filter.PageSize = 20; } if (filter.PageNumber == 0) { filter.PageNumber = 1; } string idCliente = filter.Codigo; if (idCliente == "000000") { idCliente = "0"; } else { var cliente = await _context.MtrCliente.Where(x => x.Codigo == idCliente).FirstOrDefaultAsync(); filter.Rif = cliente.NoRegTribut; } List <MtrContactos> contactos = new List <MtrContactos>(); if (filter.SearchText.Length > 0) { contactos = await _context.MtrContactos.Where(x => (x.IdCliente == idCliente || x.IdCliente == filter.Codigo)).OrderByDescending(x => x.FechaCreacion).ToListAsync(); contactos = contactos.Where(x => x.Rif == filter.Rif).OrderByDescending(x => x.FechaCreacion).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); contactos = contactos.Where(x => (x.Cargo.ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Nombre.ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Email.ToLower().Contains(filter.SearchText.Trim().ToLower()))).OrderByDescending(x => x.FechaCreacion).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); } else { contactos = await _context.MtrContactos.Where(x => (x.IdCliente == idCliente || x.IdCliente == filter.Codigo) && (x.Rif == filter.Rif) && (x.Email.Trim().Length > 0)).OrderByDescending(x => x.FechaCreacion).Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToListAsync(); } List <MtrContactos> result = new List <MtrContactos>(); MtrContactos resultItem = new MtrContactos(); foreach (var item in contactos) { var resultBusqueda = result.Where(x => x.Email.Trim() == item.Email.Trim()).FirstOrDefault(); if (resultBusqueda == null) { result.Add(item); } } return(result); }
public async Task <MtrContactos> Update(MtrContactos mtrContactos) { var contacto = await GetById(mtrContactos.IdContacto); if (contacto == null) { throw new Exception("Contacto No existe"); } _unitOfWork.MtrContactosRepository.Update(contacto); await _unitOfWork.SaveChangesAsync(); return(await GetById(contacto.IdContacto)); }
public async Task <ApiResponse <AppGeneralQuotesGetDto> > UpdateGeneralQuotes(AppGeneralQuotesUpdateDto appGeneralQuotesUpdateDto) { AppGeneralQuotesGetDto resultDto = new AppGeneralQuotesGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppGeneralQuotesGetDto> response = new ApiResponse <AppGeneralQuotesGetDto>(resultDto); try { AppGeneralQuotes appGeneralQuotes = await GetById(appGeneralQuotesUpdateDto.Id); if (appGeneralQuotes == null) { metadata.IsValid = false; metadata.Message = "Cotizacion No Existe!!! " + appGeneralQuotesUpdateDto.Cotizacion; response.Meta = metadata; response.Data = resultDto; return(response); } MtrCliente cliente = await _mtrClienteService.GetByIdAsync(appGeneralQuotesUpdateDto.IdCliente); if (cliente == null) { metadata.IsValid = false; metadata.Message = "Cliente No Existe!!! " + appGeneralQuotesUpdateDto.IdCliente; response.Meta = metadata; response.Data = resultDto; return(response); } MtrDirecciones direccionEntregarValidate = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesUpdateDto.IdDireccionEntregar); if (direccionEntregarValidate == null) { metadata.IsValid = false; metadata.Message = "Direccion Entregar No Existe!!! " + appGeneralQuotesUpdateDto.IdDireccionEntregar; response.Meta = metadata; response.Data = resultDto; return(response); } MtrContactos mtrContactosValidate = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesUpdateDto.IdContacto); if (mtrContactosValidate == null) { metadata.IsValid = false; metadata.Message = "Contacto No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } MtrCondicionPago condicionPagoValidate = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesUpdateDto.IdCondPago); if (condicionPagoValidate == null) { metadata.IsValid = false; metadata.Message = "Condicion de Pago No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } MtrTipoMoneda mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesUpdateDto.IdMtrTipoMoneda); if (mtrTipoMonedaFind == null) { metadata.IsValid = false; metadata.Message = "Moneda No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } if (appGeneralQuotesUpdateDto.OrdenCompra.Length > 16) { metadata.IsValid = false; metadata.Message = "Longitud Maxima de Orden de Compra es 16 !!! "; response.Meta = metadata; response.Data = resultDto; return(response); } if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotesUpdateDto.Rif = cliente.NoRegTribut; appGeneralQuotesUpdateDto.RazonSocial = cliente.Nombre; appGeneralQuotesUpdateDto.Direccion = cliente.Direccion + " " + cliente.Direccion1; } appGeneralQuotes.Rif = appGeneralQuotesUpdateDto.Rif; appGeneralQuotes.RazonSocial = appGeneralQuotesUpdateDto.RazonSocial; appGeneralQuotes.Direccion = appGeneralQuotesUpdateDto.Direccion; appGeneralQuotes.IdCliente = appGeneralQuotesUpdateDto.IdCliente; if (appGeneralQuotesUpdateDto.IdCliente == "000000") { appGeneralQuotes.IdMunicipio = appGeneralQuotesUpdateDto.IdMunicipio; var municipio = await _unitOfWork.Winy243Repository.GetById(appGeneralQuotesUpdateDto.IdMunicipio); if (municipio != null) { appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio; } } else { var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregarValidate.Estado, direccionEntregarValidate.Municipio); if (municipio != null) { appGeneralQuotes.IdMunicipio = municipio.Recnum; appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio; } } if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotes.IdVendedor = cliente.Vendedor1.Trim(); } else { appGeneralQuotes.IdVendedor = appGeneralQuotesUpdateDto.UsuarioActualiza; } appGeneralQuotes.Observaciones = appGeneralQuotesUpdateDto.Observaciones; appGeneralQuotes.IdCondPago = appGeneralQuotesUpdateDto.IdCondPago; appGeneralQuotes.IdContacto = appGeneralQuotesUpdateDto.IdContacto; appGeneralQuotes.IdDireccionFacturar = (decimal)cliente.IdDireccion; appGeneralQuotes.IdDireccionEntregar = appGeneralQuotesUpdateDto.IdDireccionEntregar; appGeneralQuotes.OrdenCompra = appGeneralQuotesUpdateDto.OrdenCompra; appGeneralQuotes.UsuarioActualiza = appGeneralQuotesUpdateDto.UsuarioActualiza; appGeneralQuotes.FechaActualiza = DateTime.Now; appGeneralQuotes.Proximo = 0; appGeneralQuotes.IdMtrTipoMoneda = appGeneralQuotesUpdateDto.IdMtrTipoMoneda; if (appGeneralQuotesUpdateDto.FechaPostergada != null) { appGeneralQuotes.FechaPostergada = appGeneralQuotesUpdateDto.FechaPostergada; } if (appGeneralQuotesUpdateDto.ObservacionPostergar != "" && appGeneralQuotesUpdateDto.ObservacionPostergar != null) { appGeneralQuotes.ObservacionPostergar = appGeneralQuotesUpdateDto.ObservacionPostergar; } else { appGeneralQuotesUpdateDto.ObservacionPostergar = ""; } appGeneralQuotes.FijarPrecioBs = appGeneralQuotesUpdateDto.FijarPrecioBs; AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotes.IdEstatus); MtrVendedor vendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotes.IdVendedor); if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotes.SearchText = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{cliente.Nombre.Trim()}{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}"; } else { appGeneralQuotes.SearchText = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}"; appGeneralQuotes.IdDireccionEntregar = 1; appGeneralQuotes.IdDireccionFacturar = 1; } AppGeneralQuotes AppGeneralQuotesUpdated = await Update(appGeneralQuotes); //await _cotizacionService.IntegrarCotizacion(AppGeneralQuotesUpdated.Id); if (AppGeneralQuotesUpdated != null) { resultDto = _mapper.Map <AppGeneralQuotesGetDto>(AppGeneralQuotesUpdated); MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(resultDto.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); resultDto.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(resultDto.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); resultDto.MtrClienteDto = mtrClienteDto; } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(resultDto.IdContacto); if (mtrContactos != null) { MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); resultDto.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); resultDto.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); resultDto.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(resultDto.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); resultDto.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(resultDto.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); resultDto.MtrTipoMonedaDto = mtrTipoMonedaDto; } metadata.IsValid = true; metadata.Message = $"Cotizacion: {resultDto.Cotizacion} Actualizada Satisfactoriamente!!"; } else { metadata.IsValid = false; metadata.Message = "Registro No actualizado"; } response.Meta = metadata; response.Data = resultDto; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }
public async Task <AppGeneralQuotesGetDto> GetAppGeneralQuotes(AppGeneralQuotesQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; AppGeneralQuotes quotes = await _unitOfWork.AppGeneralQuotesRepository.GetByCotizacions(filters.Cotizacion); if (quotes != null) { AppGeneralQuotesGetDto appGeneralQuotesGetDto = _mapper.Map <AppGeneralQuotesGetDto>(quotes); MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotesGetDto.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); appGeneralQuotesGetDto.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(appGeneralQuotesGetDto.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); appGeneralQuotesGetDto.MtrClienteDto = mtrClienteDto; } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesGetDto.IdContacto); if (mtrContactos != null) { //MtrContactosDto mtrContactosDto = new MtrContactosDto(); //mtrContactosDto.IdContacto = mtrContactos.IdContacto; //mtrContactosDto.Cargo = mtrContactos.Email; MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); appGeneralQuotesGetDto.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); appGeneralQuotesGetDto.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); appGeneralQuotesGetDto.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesGetDto.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); appGeneralQuotesGetDto.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesGetDto.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); appGeneralQuotesGetDto.MtrTipoMonedaDto = mtrTipoMonedaDto; } var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(appGeneralQuotesGetDto.Id); if (actualizar) { await _unitOfWork.SaveChangesAsync(); } AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotesGetDto.IdEstatus); if (appStatusQuote != null) { AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote); appGeneralQuotesGetDto.AppStatusQuoteGetDto = appStatusQuoteDto; } appGeneralQuotesGetDto.PorcFlete = await GetFleteByIdDireccionEntrega(appGeneralQuotesGetDto.IdDireccionEntregar); var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(appGeneralQuotesGetDto.Id); appGeneralQuotesGetDto.PermiteAdicionarDetalle = permiteAdicionarDetalle; appGeneralQuotesGetDto.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(appGeneralQuotesGetDto.Id); ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(appGeneralQuotesGetDto.Id); if (listDetail != null) { appGeneralQuotesGetDto.AppDetailQuotesGetDto = listDetail.Data; } return(appGeneralQuotesGetDto); } else { return(null); } }
public async Task <PagedList <AppGeneralQuotesGetDto> > GetAllAppGeneralQuotes(AppGeneralQuotesQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; List <AppGeneralQuotes> quotes = await _unitOfWork.AppGeneralQuotesRepository.GetAll(filters); if (quotes.Count > 0) { List <AppGeneralQuotesGetDto> appGeneralQuotesGetDto = _mapper.Map <List <AppGeneralQuotesGetDto> >(quotes); foreach (AppGeneralQuotesGetDto item in appGeneralQuotesGetDto) { MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(item.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); item.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(item.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); item.MtrClienteDto = mtrClienteDto; if (item.IdCliente == "000000") { item.MtrClienteDto.Descripcion = item.IdCliente.Trim() + "-" + item.RazonSocial.Trim() + " RIF: " + item.Rif.ToString(); } } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(item.IdContacto); if (mtrContactos != null) { MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); item.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); item.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); item.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(item.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); item.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(item.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); item.MtrTipoMonedaDto = mtrTipoMonedaDto; } var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(item.Id); if (actualizar) { await _unitOfWork.SaveChangesAsync(); } AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(item.IdEstatus); if (appStatusQuote != null) { AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote); item.AppStatusQuoteGetDto = appStatusQuoteDto; } if (item.IdCliente == "000000") { var municipio = await _unitOfWork.Winy243Repository.GetById(item.IdMunicipio); if (municipio != null) { item.PorcFlete = municipio.PorcFlete; MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio); item.MunicipioGetDto = municipioGetDto; } } else { item.PorcFlete = await GetFleteByIdDireccionEntrega(item.IdDireccionEntregar); var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregar.Estado, direccionEntregar.Municipio); if (municipio != null) { item.IdMunicipio = municipio.Recnum; item.descripcionMunicipio = municipio.DescMunicipio; MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio); item.MunicipioGetDto = municipioGetDto; } } var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(item.Id); item.PermiteAdicionarDetalle = permiteAdicionarDetalle; item.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(item.Id); ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(item.Id); if (listDetail != null) { item.AppDetailQuotesGetDto = listDetail.Data; } item.FechaString = item.Fecha.ToString("dd/MM/yyyy"); } PagedList <AppGeneralQuotesGetDto> pagedResult = PagedList <AppGeneralQuotesGetDto> .Create(appGeneralQuotesGetDto, filters.PageNumber, filters.PageSize); return(pagedResult); } else { return(null); } }
public async Task <ApiResponse <ContactoGetDto> > GetContactoById(ContactoQueryFilter filter) { ContactoGetDto resultDto = new ContactoGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <ContactoGetDto> response = new ApiResponse <ContactoGetDto>(resultDto); try { MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById((long)filter.IdContacto); if (mtrContactos != null) { SapContactos sapContactos = await _unitOfWork.SapContactoRepository.GetById(mtrContactos.IdContacto); ContactoGetDto contactoGetDto = new ContactoGetDto(); if (sapContactos.TitleMedi == "Señor") { contactoGetDto.Tratamiento = 1; } else { contactoGetDto.Tratamiento = 2; } contactoGetDto.Poder = sapContactos.Parvo; contactoGetDto.Nombre = mtrContactos.Nombre; contactoGetDto.Departamento = sapContactos.Abtnr; contactoGetDto.Telefono = mtrContactos.Telefono1; contactoGetDto.Celular = mtrContactos.Celular; contactoGetDto.Fax = mtrContactos.Fax; contactoGetDto.Email = mtrContactos.Email; contactoGetDto.IdContacto = mtrContactos.IdContacto; contactoGetDto.IdCliente = mtrContactos.IdCliente; contactoGetDto.Rif = mtrContactos.Rif; contactoGetDto.Cargo = sapContactos.Pafkt; metadata.IsValid = true; metadata.Message = ""; response.Data = contactoGetDto; response.Meta = metadata; return(response); } else { metadata.IsValid = false; metadata.Message = "Contacto No existe"; response.Data = null; response.Meta = metadata; return(response); } response.Data = null; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }
public async Task <ApiResponse <bool> > UpdateContactoAllTables(ContactoUpdateDto dto) { bool resultDto = new bool(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <bool> response = new ApiResponse <bool>(resultDto); try { SapTratamientoContacto sapTratamientoContacto = await _unitOfWork.SapTratamientoContactoRepository.GetById(dto.Tratamiento); if (sapTratamientoContacto == null) { metadata.IsValid = false; metadata.Message = "Tratamiento no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapDepartamentoContacto sapDepartamentoContacto = await _unitOfWork.SapDepartamentoContactoRepository.GetById(dto.Departamento); if (sapDepartamentoContacto == null) { metadata.IsValid = false; metadata.Message = "Departamento no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapCargoContacto sapCargoContacto = await _unitOfWork.SapCargoContactoRepository.GetById(dto.Cargo); if (sapCargoContacto == null) { metadata.IsValid = false; metadata.Message = "Cargo no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapPoderContacto sapPoderContacto = await _unitOfWork.SapPoderContactoRepository.GetById(dto.Poder); if (sapPoderContacto == null) { metadata.IsValid = false; metadata.Message = "Poder no existe!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Rif)) { metadata.IsValid = false; metadata.Message = "Rif Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Nombre)) { metadata.IsValid = false; metadata.Message = "Nombre Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Celular)) { metadata.IsValid = false; metadata.Message = "Celular Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Telefono)) { metadata.IsValid = false; metadata.Message = "Telefono Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Email)) { metadata.IsValid = false; metadata.Message = "Telefono Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } var newIdContacto = await _unitOfWork.SapContactoRepository.NextId(); string FlagProcesado = ""; if (dto.IdCliente == "0") { FlagProcesado = "X"; } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById((long)dto.IdContacto); if (mtrContactos == null) { metadata.IsValid = false; metadata.Message = "Contacto No existe"; response.Data = false; response.Meta = metadata; return(response); } else { mtrContactos.Rif = dto.Rif; mtrContactos.Nombre = dto.Nombre; mtrContactos.Cargo = sapCargoContacto.Descripcion; mtrContactos.Area = sapDepartamentoContacto.Descripcion; mtrContactos.Telefono1 = dto.Telefono; mtrContactos.Celular = dto.Celular; mtrContactos.Email = dto.Email; mtrContactos.Fax = dto.Fax; mtrContactos.Inactivo = false; mtrContactos.FechaCreacion = DateTime.Now; mtrContactos.Usuario = dto.UsuarioConectado; _unitOfWork.MtrContactosRepository.Update(mtrContactos); SapContactos sapContactos = await _unitOfWork.SapContactoRepository.GetById(mtrContactos.IdContacto); if (sapContactos != null) { sapContactos.Parnr = ""; sapContactos.TitleMedi = sapTratamientoContacto.NombreTratamiento; sapContactos.Name1 = dto.Apellido; sapContactos.Namev = dto.Nombre; sapContactos.Pafkt = sapCargoContacto.Codigo; sapContactos.Abtnr = sapDepartamentoContacto.Codigo; sapContactos.Telf1 = dto.Telefono; sapContactos.Telf2 = dto.Celular; sapContactos.StmpAddr = dto.Email; sapContactos.Fax = dto.Fax; sapContactos.Pavip = "3";//Activo if (dto.FechaNacimiento != null) { sapContactos.Gbdat = dto.FechaNacimiento.Value.Year.ToString() + dto.FechaNacimiento.Value.Month.ToString() + dto.FechaNacimiento.Value.Day.ToString(); } sapContactos.Parvo = sapPoderContacto.Codigo; sapContactos.Nmail = "X"; sapContactos.Procesado = FlagProcesado; sapContactos.FechaCreacion = DateTime.Now; sapContactos.UsuarioCreacion = dto.UsuarioConectado; _unitOfWork.SapContactoRepository.Update(sapContactos); } Wsmy265 wsmy265 = await _unitOfWork.Wsmy265Repository.GetById(mtrContactos.IdContacto); if (wsmy265 != null) { wsmy265.Rif = dto.Rif; wsmy265.Nombre = dto.Nombre + " " + dto.Apellido; wsmy265.Cargo = sapCargoContacto.Descripcion; wsmy265.Area = sapDepartamentoContacto.Descripcion; wsmy265.TelefonoOficina1 = dto.Telefono; wsmy265.TelefonoCelular = dto.Celular; wsmy265.Email = dto.Email; wsmy265.Fax = dto.Fax; wsmy265.Inactivo = ""; if (dto.FechaNacimiento != null) { wsmy265.FechaCumpleanos = dto.FechaNacimiento.Value.Year.ToString() + dto.FechaNacimiento.Value.Month.ToString() + dto.FechaNacimiento.Value.Day.ToString(); } wsmy265.TomaDecision = sapPoderContacto.Id; wsmy265.AceptaEmail = "X"; wsmy265.Usuario = dto.UsuarioConectado; _unitOfWork.Wsmy265Repository.Update(wsmy265); } await _unitOfWork.SaveChangesAsync(); } response.Data = true; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = false; response.Meta = metadata; return(response); } }
public async Task <ApiResponse <bool> > CreateContactoAlTables(ContactoCreateDto dto) { bool resultDto = new bool(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <bool> response = new ApiResponse <bool>(resultDto); try { SapTratamientoContacto sapTratamientoContacto = await _unitOfWork.SapTratamientoContactoRepository.GetById(dto.Tratamiento); if (sapTratamientoContacto == null) { metadata.IsValid = false; metadata.Message = "Tratamiento no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapDepartamentoContacto sapDepartamentoContacto = await _unitOfWork.SapDepartamentoContactoRepository.GetById(dto.Departamento); if (sapDepartamentoContacto == null) { metadata.IsValid = false; metadata.Message = "Departamento no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapCargoContacto sapCargoContacto = await _unitOfWork.SapCargoContactoRepository.GetById(dto.Cargo); if (sapCargoContacto == null) { metadata.IsValid = false; metadata.Message = "Cargo no existe!!"; response.Data = false; response.Meta = metadata; return(response); } SapPoderContacto sapPoderContacto = await _unitOfWork.SapPoderContactoRepository.GetById(dto.Poder); if (sapPoderContacto == null) { metadata.IsValid = false; metadata.Message = "Poder no existe!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Rif)) { metadata.IsValid = false; metadata.Message = "Rif Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Nombre)) { metadata.IsValid = false; metadata.Message = "Nombre Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Apellido)) { metadata.IsValid = false; metadata.Message = "Apellido Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Celular)) { metadata.IsValid = false; metadata.Message = "Celular Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Telefono)) { metadata.IsValid = false; metadata.Message = "Telefono Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } if (String.IsNullOrEmpty(dto.Email)) { metadata.IsValid = false; metadata.Message = "Telefono Invalido!!"; response.Data = false; response.Meta = metadata; return(response); } var newIdContacto = await _unitOfWork.SapContactoRepository.NextId(); string FlagProcesado = ""; if (dto.IdCliente == "0") { FlagProcesado = "X"; } SapContactos newSapContactos = new SapContactos(); newSapContactos.IdContacto = newIdContacto; newSapContactos.Kunnr = dto.IdCliente; newSapContactos.Parnr = ""; newSapContactos.TitleMedi = sapTratamientoContacto.NombreTratamiento; newSapContactos.Name1 = dto.Apellido; newSapContactos.Namev = dto.Nombre; newSapContactos.Pafkt = sapCargoContacto.Codigo; newSapContactos.Abtnr = sapDepartamentoContacto.Codigo; newSapContactos.Telf1 = dto.Telefono; newSapContactos.Telf2 = dto.Celular; newSapContactos.StmpAddr = dto.Email; newSapContactos.Fax = dto.Fax; newSapContactos.Pavip = "3";//Activo if (dto.FechaNacimiento != null) { newSapContactos.Gbdat = dto.FechaNacimiento.Value.Year.ToString() + dto.FechaNacimiento.Value.Month.ToString() + dto.FechaNacimiento.Value.Day.ToString(); } newSapContactos.Parvo = sapPoderContacto.Codigo; newSapContactos.Nmail = "X"; newSapContactos.Procesado = FlagProcesado; newSapContactos.FechaCreacion = DateTime.Now; newSapContactos.UsuarioCreacion = dto.UsuarioConectado; await _unitOfWork.SapContactoRepository.Add(newSapContactos); MtrContactos newMtrContactos = new MtrContactos(); newMtrContactos.IdContacto = (long)newIdContacto; newMtrContactos.IdCliente = dto.IdCliente; newMtrContactos.Rif = dto.Rif; newMtrContactos.Nombre = dto.Nombre + " " + dto.Apellido; newMtrContactos.Cargo = sapCargoContacto.Descripcion; newMtrContactos.Area = sapDepartamentoContacto.Descripcion; newMtrContactos.Telefono1 = dto.Telefono; newMtrContactos.Celular = dto.Celular; newMtrContactos.Email = dto.Email; newMtrContactos.Fax = dto.Fax; newMtrContactos.Inactivo = false; newMtrContactos.FechaCreacion = DateTime.Now; newMtrContactos.Usuario = dto.UsuarioConectado; await _unitOfWork.MtrContactosRepository.Add(newMtrContactos); Wsmy265 newWsmy265 = new Wsmy265(); decimal decimalVal = 0; decimalVal = System.Convert.ToDecimal(dto.IdCliente); var newCorrelativoContactoCliente = await _unitOfWork.Wsmy265Repository.NextCorrelativoContactoCliente(decimalVal, dto.Rif); newWsmy265.Id = (long)newIdContacto; newWsmy265.Cliente = decimalVal; newWsmy265.Rif = dto.Rif; newWsmy265.Nombre = dto.Nombre + " " + dto.Apellido; newWsmy265.Cargo = sapCargoContacto.Descripcion; newWsmy265.Area = sapDepartamentoContacto.Descripcion; newWsmy265.TelefonoOficina1 = dto.Telefono; newWsmy265.TelefonoCelular = dto.Celular; newWsmy265.Email = dto.Email; newWsmy265.Fax = dto.Fax; newWsmy265.IdContactos = newCorrelativoContactoCliente; newWsmy265.Inactivo = ""; if (dto.FechaNacimiento != null) { newWsmy265.FechaCumpleanos = dto.FechaNacimiento.Value.Year.ToString() + dto.FechaNacimiento.Value.Month.ToString() + dto.FechaNacimiento.Value.Day.ToString(); } newWsmy265.TomaDecision = sapPoderContacto.Id; newWsmy265.AceptaEmail = "X"; newWsmy265.FechaCreacion = DateTime.Now; newWsmy265.Usuario = dto.UsuarioConectado; await _unitOfWork.Wsmy265Repository.Add(newWsmy265); await _unitOfWork.SaveChangesAsync(); response.Data = true; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = false; response.Meta = metadata; return(response); } }
public async Task Delete(long id) { MtrContactos entity = await GetById(id); _context.MtrContactos.Remove(entity); }
public void Update(MtrContactos entity) { _context.MtrContactos.Update(entity); }
public async Task Add(MtrContactos entity) { await _context.MtrContactos.AddAsync(entity); }