public ActionResult CrearEditarBodega(BodegaViewModel model)
        {
            try
            {
                var existeBodega = service.GetBodegaByNombre(model.Nombre);
                if (model.Id != 0)
                {
                    if (existeBodega != null)
                    {
                        if ((int)existeBodega.Id != model.Id)
                        {
                            return(Json(new { success = false }));
                        }
                    }

                    var bodega    = map.Update(model, model.Id);
                    var idUsuario = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                    string comentarioES = "Editó la bodega " + bodega.Nombre;

                    bitacoraMap.CrearBitacora(int.Parse(idUsuario), comentarioES, (int)bodega.Id, "Bodega");

                    return(Json(new { success = true }));
                }
                else
                {
                    if (existeBodega != null)
                    {
                        return(Json(new { success = false }));
                    }

                    var    bodega       = map.Create(model);
                    var    idUsuario    = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;
                    string comentarioES = "Creo una nueva bodega " + bodega.Nombre;
                    //string comentarioIN = "Creo una nueva bitacora";
                    bitacoraMap.CrearBitacora(int.Parse(idUsuario), comentarioES, (int)bodega.Id, "Bodega");
                    return(Json(new { success = true }));
                }
            }
            catch (Exception ex)
            {
                AltivaLog.Log.Insertar(ex.ToString(), "Error");
                return(BadRequest());
            }
        }
Beispiel #2
0
        public ActionResult EditarBodega(int id, BodegaViewModel model)
        {
            try
            {
                var dataIsValid  = false;
                var existeBodega = service.GetBodegaByNombre(model.Nombre);

                if (existeBodega != null)
                {
                    if ((int)existeBodega.Id == id)
                    {
                        dataIsValid = true;
                    }
                    else
                    {
                        return(RedirectToAction("EditarBodega", new { id = id, err = "err" }));
                    }
                }
                else
                {
                    dataIsValid = true;
                }

                if (dataIsValid)
                {
                    var    bodega       = map.Update(model, id);
                    var    idUsuario    = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;
                    string comentarioES = "Editó la bodega " + bodega.Nombre;
                    //string comentarioIN = "Creo una nueva bitacora";
                    bitacoraMap.CrearBitacora(int.Parse(idUsuario), comentarioES, (int)bodega.Id, "Bodega");
                    return(RedirectToAction(nameof(DetallesBodega), new { id = bodega.Id }));
                }
                else
                {
                    return(RedirectToAction("EditarBodega", new { id = id, err = "err" }));
                }
            }
            catch
            {
                //throw;
                return(RedirectToAction("EditarBodega", new { id = id, err = "err" }));
            }
        }