public async Task <IActionResult> Edit(int id, [Bind("TipoLocald,Nombre,EstaHabilitado,EstaPublicado")] TipoLocal tipoLocal) { if (id != tipoLocal.TipoLocald) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tipoLocal); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoLocalExists(tipoLocal.TipoLocald)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tipoLocal)); }
public ActionResult Details(int?_id) { if (User.Identity.IsAuthenticated) { if (!User.IsInRole("ROLLTRA")) { RedirectToAction("AccesoDenegado", "Acceso"); } } else { RedirectToAction("~/Account/Login"); } if (_id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TipoLocal tipolocal = db.TiposLocal.Find(_id); if (tipolocal == null) { return(HttpNotFound()); } return(View(tipolocal)); }
public JsonResult DeleteTipoLocal(int?id) { string result = string.Empty; try { TipoLocal tipolocal = db.TiposLocal.Find(id); db.Set <TipoLocal>().Remove(tipolocal); db.SaveChanges(); result = "success"; } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { result = "El Tipo Local no puede ser eliminado ya que está asociado a otros registros"; } else { if (ex.InnerException != null) { result = ex.InnerException.Message; } else { result = ex.Message; } } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Create([Bind("TipoLocald,Nombre,EstaHabilitado,EstaPublicado")] TipoLocal tipoLocal) { if (ModelState.IsValid) { _context.Add(tipoLocal); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tipoLocal)); }
public ActionResult Edit([Bind(Include = "Id,DescripcionTipoLocal")] TipoLocal tipolocal) { if (db.TiposLocal.Where(tl => tl.Id != tipolocal.Id && tl.DescripcionTipoLocal == tipolocal.DescripcionTipoLocal).Any()) { ModelState.AddModelError("DescripcionTipoLocal", "La descripcion del tipo local ya existe"); } if (ModelState.IsValid) { db.Entry(tipolocal).State = EntityState.Modified; db.SaveChanges(); return(Json(new { HayError = false }, JsonRequestBehavior.AllowGet)); } var Errores = ModelState.ToDictionary ( e => e.Key, e => e.Value.Errors.Select(x => x.ErrorMessage).ToArray() ); return(Json(new { HayError = true, Errores = Errores }, JsonRequestBehavior.AllowGet)); }
public ActionConfirmation SaveOrUpdateTipo(TipoLocal item) { if (!item.IsValid()) { return(ActionConfirmation.CreateFailure("objeto no es válida")); } try { _tipoLocalRepository.SaveOrUpdate(item); _tipoLocalRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccess("saved ok")); } catch (Exception exception) { _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, item.ActualizadoPor, EventSource.Sistema); return(ActionConfirmation.CreateFailure(exception.ToString())); } }
public JsonResult SaveTipo(TipoLocalFormModel tipo) { TipoLocal tipoLocal = null; tipoLocal = tipo.Id == Guid.Empty ? new TipoLocal() : _localService.GetTipo(tipo.Id); tipoLocal.Detalle = tipo.Detalle; tipoLocal.Estado = _statusService.Get(tipo.EstadoId); if (tipoLocal.Id == Guid.Empty) { tipoLocal.CreadoEn = DateTime.Now; tipoLocal.CreadoPor = User.Identity.Name; } tipoLocal.ActualizadoEn = DateTime.Now; tipoLocal.ActualizadoPor = User.Identity.Name; var confirmation = _localService.SaveOrUpdateTipo(tipoLocal); return(Json(confirmation.WasSuccessful)); }