public UBICACION GetUbicacionByID(int id)
        {
            UBICACION oUbicacion = null;

            try
            {
                using (MyContext ctx = new MyContext())
                {
                    ctx.Configuration.LazyLoadingEnabled = false;
                    oUbicacion = ctx.UBICACION.Find(id);
                }

                return(oUbicacion);
            }
            catch (DbUpdateException dbEx)
            {
                string mensaje = "";
                Log.Error(dbEx, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw new Exception(mensaje);
            }
            catch (Exception ex)
            {
                string mensaje = "";
                Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw;
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutUBICACION(int id, UBICACION uBICACION)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != uBICACION.ID)
            {
                return(BadRequest());
            }

            db.Entry(uBICACION).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UBICACIONExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void DeleteUbicacion(int id)
        {
            int returno;

            try
            {
                using (MyContext ctx = new MyContext())
                {
                    /* La carga diferida retrasa la carga de datos relacionados,
                     * hasta que lo solicite específicamente.*/
                    ctx.Configuration.LazyLoadingEnabled = false;
                    UBICACION oUbicacion = new UBICACION()
                    {
                        Estado = false
                    };
                    ctx.Entry(oUbicacion).State = EntityState.Modified;
                    returno = ctx.SaveChanges();
                }
            }
            catch (DbUpdateException dbEx)
            {
                string mensaje = "";
                Log.Error(dbEx, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw new Exception(mensaje);
            }
            catch (Exception ex)
            {
                string mensaje = "";
                Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw;
            }
        }
        public async Task <UBICACION> Update(UBICACION element)
        {
            var aux = _solutionDBContext.UBICACION.Update(element);
            await _solutionDBContext.SaveChangesAsync();

            return(aux.Entity);
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            ServiceUbicacion _serviceUbic = new ServiceUbicacion();
            UBICACION        oUbicacion   = null;

            try
            {
                // Si va null
                if (id == null)
                {
                    return(RedirectToAction("Ubicaciones"));
                }

                oUbicacion = _serviceUbic.GetUbicacionByID(id);
                if (oUbicacion == null)
                {
                    TempData["Message"]         = "No existe la ubicación solicitada";
                    TempData["Redirect"]        = "Ubicacion";
                    TempData["Redirect-Action"] = "Ubicaciones";

                    return(RedirectToAction("Default", "Error"));
                }

                return(View(oUbicacion));
            }
            catch (Exception ex)
            {
                Log.Error(ex, MethodBase.GetCurrentMethod());
                TempData["Message"]         = "Error al procesar los datos" + ex.Message;
                TempData["Redirect"]        = "Ubicacion";
                TempData["Redirect-Action"] = "Ubicaciones";

                return(RedirectToAction("Default", "Error"));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Save(UBICACION ubic)
        {
            ServiceUbicacion _serviceUbicacion = new ServiceUbicacion();

            try
            {
                if (ModelState.IsValid)
                {
                    UBICACION oUbicacion = _serviceUbicacion.Save(ubic);
                }
                else
                {
                    Util.Util.ValidateErrors(this);

                    return(View("Create", ubic));
                }

                return(RedirectToAction("Ubicaciones"));
            }
            catch (Exception ex)
            {
                Log.Error(ex, MethodBase.GetCurrentMethod());
                TempData["Message"]         = "Error al procesar los datos" + ex.Message;
                TempData["Redirect"]        = "Ubicacion";
                TempData["Redirect-Action"] = "Ubicaciones";

                return(RedirectToAction("Default", "Error"));
            }
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            UBICACION uBICACION = db.UBICACION.Find(id);

            db.UBICACION.Remove(uBICACION);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <UBICACION> Add(UBICACION Elemnet)
        {
            await _solutionDBContext.UBICACION.AddAsync(Elemnet);

            await _solutionDBContext.SaveChangesAsync();

            return(Elemnet);
        }
Ejemplo n.º 9
0
        public IHttpActionResult GetUBICACION(int id)
        {
            UBICACION uBICACION = db.UBICACION.Find(id);

            if (uBICACION == null)
            {
                return(NotFound());
            }

            return(Ok(uBICACION));
        }
 public static UbicacionModel Map(UBICACION dto)
 {
     return(new UbicacionModel()
     {
         id = dto.PersonaID,
         latitud = dto.UbicacionLatitud,
         longitud = dto.UbicacionLongitud,
         idemp = dto.EmpresaID,
         obs = dto.UbicacionObservaciones
     });
 }
        public async Task <UBICACION> Update(int id, UBICACION element)
        {
            var entity = await Get(id);

            entity.UbicacionLatitud = element.UbicacionLatitud;

            _solutionDBContext.UBICACION.Update(entity);
            await _solutionDBContext.SaveChangesAsync();

            return(entity);
        }
Ejemplo n.º 12
0
        public IHttpActionResult PostUBICACION(UBICACION uBICACION)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.UBICACION.Add(uBICACION);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = uBICACION.ID }, uBICACION));
        }
Ejemplo n.º 13
0
 public ActionResult Edit([Bind(Include = "Id,Continente,Pais,Ciudad")] UBICACION uBICACION)
 {
     if (ModelState.IsValid)
     {
         db.Entry(uBICACION).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Ciudad     = new SelectList(db.CIUDAD, "Id", "Descripcion", uBICACION.Ciudad);
     ViewBag.Continente = new SelectList(db.CONTINENTE, "Id", "Descripcion", uBICACION.Continente);
     ViewBag.Pais       = new SelectList(db.PAIS, "Id", "Descripcion", uBICACION.Pais);
     return(View(uBICACION));
 }
Ejemplo n.º 14
0
        // GET: UBICACION/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UBICACION uBICACION = db.UBICACION.Find(id);

            if (uBICACION == null)
            {
                return(HttpNotFound());
            }
            return(View(uBICACION));
        }
Ejemplo n.º 15
0
        public IHttpActionResult DeleteUBICACION(int id)
        {
            UBICACION uBICACION = db.UBICACION.Find(id);

            if (uBICACION == null)
            {
                return(NotFound());
            }

            db.UBICACION.Remove(uBICACION);
            db.SaveChanges();

            return(Ok(uBICACION));
        }
Ejemplo n.º 16
0
        // GET: UBICACION/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UBICACION uBICACION = db.UBICACION.Find(id);

            if (uBICACION == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Ciudad     = new SelectList(db.CIUDAD, "Id", "Descripcion", uBICACION.Ciudad);
            ViewBag.Continente = new SelectList(db.CONTINENTE, "Id", "Descripcion", uBICACION.Continente);
            ViewBag.Pais       = new SelectList(db.PAIS, "Id", "Descripcion", uBICACION.Pais);
            return(View(uBICACION));
        }
Ejemplo n.º 17
0
        public void EliminarUbicacion(int idUbicacion)
        {
            //instancia de objeto de clase SalaBLL para borrar las salas de la ubicacion
            SalaBLL sbll = new SalaBLL();
            //obtiene la ubicacion de acuerdo a la id entregada en el parametro idUbicacion
            UBICACION u = ((from e in entidades.UBICACION where e.ID_UBICACION == idUbicacion select e).First());

            //recorre el conjunto de salas obtenidas en el metodo EliminarSalasPorUbicacion y las deshabilita
            foreach (SALA sala in sbll.EliminarSalasPorUbicacion(idUbicacion))
            {
                sbll.DeshabilitarSala(sala.IDSALA);
            }

            //finalmente deshabilita la ubicacion y se guardan los cambios
            u.ACTIVO = false;
            entidades.SaveChanges();
        }
        public UBICACION Save(UBICACION ubic)
        {
            int       retorno    = 0;
            UBICACION oUbicacion = null;

            try
            {
                using (MyContext ctx = new MyContext())
                {
                    ctx.Configuration.LazyLoadingEnabled = false;
                    oUbicacion = GetUbicacionByID(ubic.Id);

                    if (oUbicacion == null)
                    {
                        ctx.UBICACION.Add(ubic);
                        retorno = ctx.SaveChanges();
                    }
                    else
                    {
                        ctx.UBICACION.Add(ubic);
                        ctx.Entry(ubic).State = EntityState.Modified;
                        retorno = ctx.SaveChanges();
                    }
                }

                if (retorno >= 0)
                {
                    oUbicacion = GetUbicacionByID(ubic.Id);
                }

                return(oUbicacion);
            }
            catch (DbUpdateException dbEx)
            {
                string mensaje = "";
                Log.Error(dbEx, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw new Exception(mensaje);
            }
            catch (Exception ex)
            {
                string mensaje = "";
                Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw;
            }
        }
Ejemplo n.º 19
0
        public UBICACION Save(UBICACION ubic)
        {
            IRepositoryUbicacion repository = new RepositoryUbicacion();

            return(repository.Save(ubic));
        }