public ActionResult Edit(SettingModel setting_m) { foreach (var secctions in setting_m.Settings) { foreach (var setting_new in secctions.Value) { settings setting = db.settings.Where(w => w.slug == setting_new.slug).SingleOrDefault(); if (setting != null) { if (setting_new.values != null) { setting.value = String.Join(",", setting_new.values);// setting_new.values.Join(","); } else { setting.value = setting_new.value; } db.Entry(setting).State = EntityState.Modified; db.SaveChanges(); } } } /* if (ModelState.IsValid) * { * db.Entry(setting).State = EntityState.Modified; * db.SaveChanges(); * return RedirectToAction("Index"); * }*/ //return View(setting); FlashData.SetFlashData("success", "Tu configuración ha sido guardada."); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, AreaModel area_m) { try { // TODO: Add update logic here if (ModelState.IsValid) { cat_areas area = new cat_areas(); area.id = area_m.id; area.id_centro = area_m.id_centro; area.nombre = area_m.nombre; db.Entry(area).State = EntityState.Modified; db.SaveChanges(); FlashData.SetFlashData("success", "Registro modificado satisfactoriamente"); return(RedirectToAction("Index")); } return(ViewBag(area_m)); } catch (Exception ex) { FlashData.SetFlashData("error", ex.Message); return(RedirectToAction("Index")); } }
public ActionResult Create(AreaModel area_m) { try { // TODO: Add insert logic here if (ModelState.IsValid) { cat_areas area = new cat_areas(); area.id_centro = area_m.id_centro; area.nombre = area_m.nombre; db.cat_areas.Add(area); db.SaveChanges(); FlashData.SetFlashData("success", "Registro agregado satisfactoriamente"); return(RedirectToAction("Index")); } return(ViewBag(area_m)); } catch { return(RedirectToAction("Index")); } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var IsAuthorized = base.AuthorizeCore(httpContext); try { if (!IsAuthorized) { return(false); } if (ModuleLevel != null) { var user = Ion_Auth.GetUser(httpContext.User.Identity.Name); var permissions = PermissionModel.GetGroup((int)user.group_id); if (user.groups.name == "admin") { return(true); } if (permissions.ContainsKey(ModuleLevel) == false) { FlashData.SetFlashData("error", "No tienes permiso para ver esta sección."); httpContext.Response.Redirect("/"); return(false); } if (RoleLevel != null && permissions[ModuleLevel].Contains(RoleLevel) == false) { FlashData.SetFlashData("error", "No tienes permiso para realizar esta acción."); httpContext.Response.Redirect("/"); return(false); } } return(true); } catch (Exception ex) { } return(false); }
public ActionResult DeleteConfirmed(int id, int id_centro) { try { // TODO: Add delete logic here cat_areas area = db.cat_areas.Find(id, id_centro); db.cat_areas.Remove(area); db.SaveChanges(); FlashData.SetFlashData("success", "Registro eliminado satisfactoriamente"); return(RedirectToAction("Index")); } catch (Exception ex) { FlashData.SetFlashData("success", ex.Message); return(RedirectToAction("Index")); } }
public ActionResult Create(users user) { try { // TODO: Add insert logic here if (ModelState.IsValid) { user.created_on = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; user.password = Sha1.SHA1HashStringForUTF8String(user.password); db.users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); } catch (Exception ex) { FlashData.SetFlashData("error", ex.Message); return(RedirectToAction("Index")); } }
public ActionResult Edit(UserModel user_m) { try { // TODO: Add update logic here if (ModelState.IsValid) { users user = db.users.Find(user_m.id); user.id = user_m.id; user.group_id = user_m.group_id; user.active = user_m.active; user.email = user_m.email; user.username = user_m.username; user.display_name = user_m.display_name; if (user_m.password != null && user_m.password != "") { user.password = Sha1.SHA1HashStringForUTF8String(user_m.password); } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); FlashData.SetFlashData("success", "La cuenta del usuario ha sido modificado satisfactoriamente"); return(RedirectToAction("Index")); } ViewBag.group_id = new SelectList(db.groups, "id", "description", user_m.group_id); return(View(user_m)); } catch (Exception ex) { FlashData.SetFlashData("error", ex.Message); return(RedirectToAction("Index")); } }
public ActionResult Save(UserModel user_m, string tab = "profile") { users update = new users(); users user = Ion_Auth.GetUser(User.Identity.Name, false); update.id = user.id; update.group_id = user.group_id; update.password = user.password; update.active = user.active; update.created_on = user.created_on; update.last_login = user.last_login; update.username = user.username; update.display_name = user.display_name; update.email = user.email; switch (tab) { case "profile": update.email = user_m.email; update.display_name = user_m.display_name; //update.password = user.password; break; case "password": if (user_m.old_password != "" && Sha1.SHA1HashStringForUTF8String(user_m.old_password) != user.password) { ModelState.AddModelError("Error", "La antigua contraseña es inválida."); } if (user_m.new_password != user_m.retype_password) { ModelState.AddModelError("Error1", "La nueva contraseña no coinciden."); } else { update.password = Sha1.SHA1HashStringForUTF8String(user_m.new_password); } break; } if (ModelState.IsValid) { //user.groups = null; db.Entry(update).State = EntityState.Modified; db.SaveChanges(); FlashData.SetFlashData("success", "Tu cuenta ha sido modificada satisfactoriamente"); } else { string errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + "\n"; } } if (errors != "") { FlashData.SetFlashData("error", errors); } } return(RedirectToAction("Details")); }
public ActionResult Upload(IEnumerable <empleados> empleados) { var all = db.empleados.Where(w => w.activo == 1).ToList(); all.ForEach(w => w.activo = 0); db.SaveChanges(); int adds = 0; int updates = 0; List <string> errors = new List <string>(); //return Json(empleados); foreach (empleados empleado in empleados) { var exists = db.empleados.Where(w => w.id_empleado == empleado.id_empleado).SingleOrDefault(); if (exists != null) { exists.activo = 1; exists.fecha_nacimiento = empleado.fecha_nacimiento; exists.nombre = empleado.nombre; exists.apellido_paterno = empleado.apellido_paterno; exists.apellido_materno = empleado.apellido_materno; exists.cargo = empleado.cargo; exists.email = empleado.email; exists.telefono = empleado.telefono; exists.tipo_mando = empleado.tipo_mando; exists.id_area = empleado.id_area == 0 ? null : empleado.id_area; exists.id_centro = empleado.id_centro == 0 ? null : empleado.id_centro; exists.rfc = empleado.rfc; exists.curp = empleado.curp; exists.direccion = empleado.direccion; if (empleado.fotografia != null) { exists.fotografia = empleado.fotografia; } try { //Response.Write(System.Web.Helpers.Json.Encode(empleado)); db.Entry(exists).State = EntityState.Modified; db.SaveChanges(); updates++; } catch (Exception ex) { errors.Add(empleado.id_empleado); } } else { empleado.activo = 1; try { empleado.id_area = empleado.id_area == 0 ? null : empleado.id_area; empleado.id_centro = empleado.id_centro == 0 ? null : empleado.id_centro; db.empleados.Add(empleado); db.SaveChanges(); adds++; } catch (Exception ex) { errors.Add(empleado.id_empleado); } } } if (errors.Count > 0) { FlashData.SetFlashData("error", "Algunos registros no se agregaron: " + String.Join(",", errors)); } //if (adds > 0) //{ FlashData.SetFlashData("success", "Se han agregado " + adds.ToString() + " registros y actualizado " + updates.ToString()); //} // return Content(""); return(RedirectToAction("Index")); }