//Registrar Negocio Ubicacion public int Registrar(RequestNegocioUbicacionRegistrarDto modelo, ref long idNuevo) { int resultado = 0; try { const string query = "Maestro.usp_NegocioUbicacion_Registrar"; var p = new DynamicParameters(); p.Add("IdNegocioUbicacion", 0, DbType.Int64, ParameterDirection.Output); p.Add("IdNegocio", modelo.IdNegocio); p.Add("Latitud", modelo.Latitud); p.Add("Longitud", modelo.Longitud); p.Add("Titulo", modelo.Titulo); p.Add("Descripcion", modelo.Descripcion); p.Add("Predeterminado", modelo.Predeterminado); using (var cn = HelperClass.ObtenerConeccion()) { if (cn.State == ConnectionState.Closed) { cn.Open(); } resultado = cn.Execute(query, commandType: CommandType.StoredProcedure, param: p); idNuevo = p.Get <long>("IdNegocioUbicacion"); } } catch (Exception ex) { Log(Level.Error, (ex.InnerException == null ? ex.Message : ex.InnerException.Message)); } return(resultado); }
public async Task <ActionResult <ResponseNegocioUbicacionRegistrarDto> > Registrar([FromBody] RequestNegocioUbicacionRegistrarDto modelo) { if (!ModelState.IsValid) { return(BadRequest()); } ResponseNegocioUbicacionRegistrarDto respuesta = new ResponseNegocioUbicacionRegistrarDto(); long nuevoId = 0; var result = await Task.FromResult(_lnNegocioUbicacion.Registrar(modelo, ref nuevoId)); if (result == 0) { respuesta.ListaError.Add(new ErrorDto { Mensaje = "Error al intentar registrar" }); return(BadRequest(respuesta)); } respuesta.ProcesadoOk = 1; respuesta.IdGenerado = nuevoId; return(Ok(respuesta)); }
//Registrar Negocio public int Registrar(RequestNegocioRegistrarDto modelo, ref long idNuevo) { int respuesta = 0; try { if (modelo.ListaUbicacion != null) { if (modelo.ListaUbicacion.Any()) { modelo.ListaUbicacion = modelo.ListaUbicacion.Where(x => x.Latitud != 0 && x.Longitud != 0).ToList(); if (modelo.ListaUbicacion.Any()) { int cantidadPredeterminados = modelo.ListaUbicacion.Where(x => x.Predeterminado == 1).Count(); if (cantidadPredeterminados > 1) { //Desmarcar todos menos uno bool seEncontroMarcado = false; foreach (var ubicacion in modelo.ListaUbicacion) { if (!seEncontroMarcado) { if (ubicacion.Predeterminado == 1) { seEncontroMarcado = true; } } else { ubicacion.Predeterminado = 0; } } } else { modelo.ListaUbicacion.First().Predeterminado = 1; } } } } using (var scope = new TransactionScope()) { respuesta = _adNegocio.Registrar(modelo, ref idNuevo); LnNegocioUbicacion lnNegocioUbicacion = new LnNegocioUbicacion(); if (modelo.ListaUbicacion == null) { modelo.ListaUbicacion = new List <RequestNegocioRegistrarUbicacionRegistrarDto>(); } if (modelo.ListaUbicacion.Any()) { int cantidadOkEsperadas = modelo.ListaUbicacion.Count; int cantidadUbicacionesOk = 0; foreach (var negUbi in modelo.ListaUbicacion) { var entUbi = new RequestNegocioUbicacionRegistrarDto { IdNegocio = idNuevo, Descripcion = negUbi.Descripcion, Titulo = negUbi.Titulo, Latitud = negUbi.Latitud, Longitud = negUbi.Longitud, Predeterminado = false }; if (negUbi.Predeterminado == 1) { entUbi.Predeterminado = true; } long idNuevoUbicacion = 0; int resultadoUbicacion = lnNegocioUbicacion.Registrar(entUbi, ref idNuevoUbicacion); if (resultadoUbicacion > 0 && idNuevoUbicacion > 0) { cantidadUbicacionesOk++; } } if (cantidadOkEsperadas == cantidadUbicacionesOk) { scope.Complete(); } } else { scope.Complete(); } } } catch (Exception ex) { Log(Level.Error, ex.InnerException == null ? ex.Message : ex.InnerException.Message); } return(respuesta); }
//Registar Ubicacion de Negocio public int Registrar(RequestNegocioUbicacionRegistrarDto modelo, ref long idNuevo) { return _adNegocioUbicacion.Registrar(modelo, ref idNuevo); }