// GET: Bosses/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var link = db.Links.Find(id); if (link == null) { return(HttpNotFound()); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", link.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", link.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", link.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", link.DepartmentId); ViewBag.BossId = new SelectList( CombosHelper.GetBosses(link.CompanyId), "BossId", "FullName", link.BossId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", link.CommuneId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", link.WorkPlaceId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", link.VotingPlaceId); return(View(link)); }
// GET: Companies/Create public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); return(View()); }
public ActionResult Create(Link link, string newWorkPlace) { if (ModelState.IsValid) { if (link.WorkPlaceId == 9999) { if (!string.IsNullOrEmpty(newWorkPlace)) { var workPlace = new WorkPlace { Name = newWorkPlace, }; db.WorkPlaces.Add(workPlace); try { db.SaveChanges(); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un lugar de trabajo con ese nombre"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", link.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", link.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", link.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", link.DepartmentId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", link.CommuneId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", link.WorkPlaceId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", link.VotingPlaceId); return(View(link)); } db.SaveChanges(); link.WorkPlaceId = workPlace.WorkPlaceId; } } db.Links.Add(link); try { db.SaveChanges(); //UsersHelper.CreateUserASP(link.UserName, "Link"); if (link.PhotoFile != null) { var folder = "~/Content/Links"; var file = string.Format("{0}.jpg", link.LinkId); var response = FilesHelper.UploadPhoto(link.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); link.Photo = pic; db.Entry(link).State = EntityState.Modified; db.SaveChanges(); } } var city = db.Cities.Find(link.CityId); var department = db.Departments.Find(link.DepartmentId); var country = db.Countries.Find(link.CountryId); var comune = db.Communes.Find(link.CommuneId); var votingPlace = db.VotingPlaces.Find(link.VotingPlaceId); var refer = db.Refers.Where(r => r.ReferType == 1 && r.UserId == link.BossId).FirstOrDefault(); var Voter = new Voter { Address = link.Address, BossId = link.BossId, CityId = city.Name, CommuneId = comune.Name, CompanyId = link.CompanyId, CountryId = country.Name, DepartmentId = department.Name, Document = link.Document, FirstName = link.FirstName, LastName = link.LastName, Phone = link.Phone, UserName = link.UserName, VotingPlaceId = votingPlace.Name, userId = 2, ReferId = refer.ReferId, PerfilId = 1, Fname = string.Format("{0} {1}", link.FirstName, link.LastName), Barrio = link.Barrio, DateBorn = link.DateBorn, Profesion = link.Profesion, }; db.Voters.Add(Voter); db.SaveChanges(); var Refer = new Refer { ReferType = 2, UserId = link.LinkId, FullName = link.FullName, Active = 1 }; db.Refers.Add(Refer); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", link.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", link.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", link.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", link.DepartmentId); ViewBag.BossId = new SelectList( CombosHelper.GetBosses(link.CompanyId), "BossId", "FullName", link.BossId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", link.CommuneId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", link.WorkPlaceId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", link.VotingPlaceId); return(View(link)); }
public ActionResult Edit(Leader leader, string newWorkPlace) { if (ModelState.IsValid) { if (leader.WorkPlaceId == 9999) { if (!string.IsNullOrEmpty(newWorkPlace)) { var workPlace = new WorkPlace { Name = newWorkPlace, }; db.WorkPlaces.Add(workPlace); try { db.SaveChanges(); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un lugar de trabajo con ese nombre"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", leader.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", leader.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", leader.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", leader.DepartmentId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", leader.CommuneId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", leader.WorkPlaceId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", leader.VotingPlaceId); return(View(leader)); } db.SaveChanges(); leader.WorkPlaceId = workPlace.WorkPlaceId; } } if (leader.PhotoFile != null) { var folder = "~/Content/Leader"; var file = string.Format("{0}.jpg", leader.LeaderId); var response = FilesHelper.UploadPhoto(leader.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); leader.Photo = pic; db.Entry(leader).State = EntityState.Modified; db.SaveChanges(); } } var refer = db.Refers.Find(leader.ReferId); if (leader.userId == 1) { leader.BossId = refer.UserId; } if (leader.userId == 2) { leader.LinkId = refer.UserId; } if (leader.userId == 3) { leader.CoordinatorId = refer.UserId; } db.Entry(leader).State = EntityState.Modified; try { db.SaveChanges(); var voter = db.Voters.Where(v => v.Document == leader.Document).FirstOrDefault(); var country = db.Countries.Find(leader.CountryId); var department = db.Departments.Find(leader.DepartmentId); var city = db.Cities.Find(leader.CityId); var commune = db.Communes.Find(leader.CommuneId); var voting = db.VotingPlaces.Find(leader.VotingPlaceId); if (voter != null) { voter.Address = leader.Address; voter.BossId = leader.BossId; voter.LinkId = leader.LinkId; voter.CoordinatorId = leader.CoordinatorId; voter.CityId = city.Name; voter.CommuneId = commune.Name; voter.CompanyId = leader.CompanyId; voter.CountryId = country.Name; voter.DepartmentId = department.Name; voter.Document = leader.Document; voter.FirstName = leader.FirstName; voter.LastName = leader.LastName; voter.Phone = leader.Phone; voter.UserName = leader.UserName; voter.VotingPlaceId = voting.Name; voter.userId = 4; voter.ReferId = refer.ReferId; voter.PerfilId = leader.userId; voter.Fname = string.Format("{0} {1}", leader.FirstName, leader.LastName); voter.Profesion = leader.Profesion; voter.Barrio = leader.Barrio; voter.DateBorn = leader.DateBorn; db.Entry(voter).State = EntityState.Modified; } var refer2 = db.Refers.Where(r => r.ReferType == 4 && r.UserId == leader.LeaderId).FirstOrDefault(); refer2.FullName = leader.FullName; db.Entry(refer2).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", leader.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", leader.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", leader.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", leader.DepartmentId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", leader.CommuneId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", leader.VotingPlaceId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", leader.WorkPlaceId); ViewBag.userId = new SelectList( CombosHelper.GetTypeUserCoordinator(), "userId", "name", leader.userId); ViewBag.ReferId = new SelectList( CombosHelper.GetRefer(), "ReferId", "FullName", leader.ReferId); return(View(leader)); }
public ActionResult Edit(Voter voter) { if (ModelState.IsValid) { var refer = db.Refers.Find(voter.ReferId); var city = db.Cities.Find(Convert.ToInt32(voter.CityId)); var department = db.Departments.Find(Convert.ToInt32(voter.DepartmentId)); var country = db.Countries.Find(Convert.ToInt32(voter.CountryId)); var comune = db.Communes.Find(Convert.ToInt32(voter.CommuneId)); var votingPlace = db.VotingPlaces.Find(Convert.ToInt32(voter.VotingPlaceId)); if (voter.PerfilId == 1) { voter.BossId = refer.UserId; } if (voter.PerfilId == 2) { voter.LinkId = refer.UserId; } if (voter.PerfilId == 3) { voter.CoordinatorId = refer.UserId; } if (voter.PerfilId == 4) { voter.LeaderId = refer.UserId; } voter.ReferId = refer.ReferId; voter.Fname = string.Format("{0} {1}", voter.FirstName, voter.LastName); voter.CityId = city.Name; voter.DepartmentId = department.Name; voter.CountryId = country.Name; voter.CommuneId = comune.Name; voter.VotingPlaceId = votingPlace.Name; db.Entry(voter).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", voter.CityId); ViewBag.CommuneId = new SelectList(CombosHelper.GetCommunes(), "CommuneId", "Name", voter.CommuneId); ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", voter.CountryId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", voter.DepartmentId); ViewBag.VotingPlaceId = new SelectList(CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", voter.VotingPlaceId); ViewBag.PerfilId = new SelectList( CombosHelper.GetUser(), "userId", "name", voter.PerfilId); ViewBag.ReferId = new SelectList( CombosHelper.GetRefer(), "ReferId", "FullName", voter.ReferId); return(View(voter)); }
// GET: Leaders/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name"); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name"); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name"); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name"); ViewBag.AssociationId = new SelectList( CombosHelper.GetAssociations(), "AssociationId", "Name"); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name"); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name"); ViewBag.userId = new SelectList( CombosHelper.GetTypeUserCoordinator(), "userId", "name"); ViewBag.ReferId = new SelectList( CombosHelper.GetRefer(), "ReferId", "FullName"); var leader = new Leader { CompanyId = user.CompanyId, Date = DateTime.Now, DateBorn = DateTime.Now, }; return(View(leader)); }
// GET: Leaders/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var leader = db.Leaders.Find(id); if (leader == null) { return(HttpNotFound()); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", leader.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", leader.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", leader.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", leader.DepartmentId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", leader.CommuneId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", leader.VotingPlaceId); ViewBag.userId = new SelectList( CombosHelper.GetTypeUserCoordinator(), "userId", "name", leader.userId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", leader.WorkPlaceId); ViewBag.ReferId = new SelectList( CombosHelper.GetRefer(), "ReferId", "FullName", leader.ReferId); return(View(leader)); }
public ActionResult DeleteConfirmed(int id) { var leader = db.Leaders.Find(id); using (var transaction = db.Database.BeginTransaction()) { try { var response = FilesHelper.DeleteDocument(leader.Photo); var Voter = db.Voters.Where(V => V.Document == leader.Document).FirstOrDefault(); if (Voter != null) { db.Voters.Remove(Voter); } var Refer = db.Refers.Where(r => r.ReferType == 4 && r.UserId == leader.LeaderId).FirstOrDefault(); if (Refer != null) { var voters = db.Voters.Where(v => v.ReferId == Refer.ReferId); foreach (var voter in voters) { db.Voters.Remove(voter); } db.Refers.Remove(Refer); db.SaveChanges(); } //Borro cualquier anotacion que tenga en la agenda var dates = db.Dates.Where(d => d.ProfessionalId == leader.Document).ToList(); foreach (var item in dates) { db.Dates.Remove(item); } var dateItems = db.TimesDates.Where(di => di.ProfessionalId == leader.Document).ToList(); foreach (var it in dateItems) { db.TimesDates.Remove(it); } var HV = db.HojaVidas.Where(h => h.RolId == 4 && h.UserId == leader.LeaderId).FirstOrDefault(); if (HV != null) { db.HojaVidas.Remove(HV); } db.Leaders.Remove(leader); db.SaveChanges(); transaction.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { ModelState.AddModelError(string.Empty, "El registro no se puede borrar porque tiene registros relacionados"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", leader.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", leader.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", leader.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", leader.DepartmentId); ViewBag.CommuneId = new SelectList( CombosHelper.GetCommunes(), "CommuneId", "Name", leader.CommuneId); ViewBag.WorkPlaceId = new SelectList( CombosHelper.GetWorkPlaces(), "WorkPlaceId", "Name", leader.WorkPlaceId); ViewBag.VotingPlaceId = new SelectList( CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", leader.VotingPlaceId); ViewBag.userId = new SelectList( CombosHelper.GetTypeUserCoordinator(), "userId", "name", leader.userId); ViewBag.ReferId = new SelectList( CombosHelper.GetRefer(), "ReferId", "FullName", leader.ReferId); return(View(leader)); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); try { db.SaveChanges(); if (company.LogoFile != null) { var folder = "~/Content/Logos"; var file = string.Format("{0}_{1}.jpg", company.CompanyId, company.Name); var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); company.Logo = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", company.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", company.CityId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", company.DepartmentId); return(View(company)); }
public ActionResult Edit(User user, string rol) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } var db2 = new WebApiPruebaContext(); var currentUser = db2.Users.Find(user.UserId); UsersHelper.DeleteUser(currentUser.UserName); if (rol == "1") { UsersHelper.CreateUserASP(user.UserName, "User"); } if (rol == "2") { UsersHelper.CreateUserASP(user.UserName, "Digitador"); } if (rol == "3") { UsersHelper.CreateUserASP(user.UserName, "Reunion"); } if (rol == "4") { UsersHelper.CreateUserASP(user.UserName, "Secretario"); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", user.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); List <SelectListItem> muser = new List <SelectListItem>(); muser.Add(new SelectListItem { Text = "Seleccione un rol", Value = "0" }); muser.Add(new SelectListItem { Text = "Administrador", Value = "1" }); muser.Add(new SelectListItem { Text = "Digitador", Value = "2" }); muser.Add(new SelectListItem { Text = "Reuniones", Value = "3" }); muser.Add(new SelectListItem { Text = "Secretario", Value = "4" }); ViewData["rol"] = muser; return(View(user)); }
// GET: Users/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = db.Users.Find(id); if (user == null) { return(HttpNotFound()); } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", user.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); List <SelectListItem> mn = new List <SelectListItem>(); mn.Add(new SelectListItem { Text = "Hombre", Value = "1" }); mn.Add(new SelectListItem { Text = "Mujer", Value = "2" }); ViewData["genero"] = mn; List <SelectListItem> muser = new List <SelectListItem>(); muser.Add(new SelectListItem { Text = "Seleccione un rol", Value = "0" }); muser.Add(new SelectListItem { Text = "Administrador", Value = "1" }); muser.Add(new SelectListItem { Text = "Digitador", Value = "2" }); muser.Add(new SelectListItem { Text = "Reuniones", Value = "3" }); muser.Add(new SelectListItem { Text = "Secretario", Value = "4" }); ViewData["rol"] = muser; return(View(user)); }
public ActionResult Create(User user, string rol) { if (ModelState.IsValid) { db.Users.Add(user); try { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(userContext)); var UserASP = userManager.FindByEmail(user.UserName); if (UserASP == null) { db.SaveChanges(); if (rol == "1") { UsersHelper.CreateUserASP(user.UserName, "User"); } if (rol == "2") { UsersHelper.CreateUserASP(user.UserName, "Digitador"); } if (rol == "3") { UsersHelper.CreateUserASP(user.UserName, "Reunion"); } if (rol == "4") { UsersHelper.CreateUserASP(user.UserName, "Secretario"); } if (user.PhotoFile != null) { var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Ya existe un usuario con ese correo electrónico"); List <SelectListItem> mn2 = new List <SelectListItem>(); mn2.Add(new SelectListItem { Text = "Hombre", Value = "1" }); mn2.Add(new SelectListItem { Text = "Mujer", Value = "2" }); ViewData["genero"] = mn2; ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", user.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); List <SelectListItem> muser2 = new List <SelectListItem>(); muser2.Add(new SelectListItem { Text = "Seleccione un rol", Value = "0" }); muser2.Add(new SelectListItem { Text = "Administrador", Value = "1" }); muser2.Add(new SelectListItem { Text = "Digitador", Value = "2" }); muser2.Add(new SelectListItem { Text = "Reuniones", Value = "3" }); muser2.Add(new SelectListItem { Text = "Secretario", Value = "4" }); ViewData["rol"] = muser2; return(View(user)); } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Ya existe un Registro con esa descripción"); } else { ModelState.AddModelError(string.Empty, ex.ToString()); } } } ViewBag.CountryId = new SelectList( CombosHelper.GetCountries(), "CountryId", "Name", user.CountryId); ViewBag.CityId = new SelectList( CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList( CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList( CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); List <SelectListItem> muser = new List <SelectListItem>(); muser.Add(new SelectListItem { Text = "Seleccione un rol", Value = "0" }); muser.Add(new SelectListItem { Text = "Administrador", Value = "1" }); muser.Add(new SelectListItem { Text = "Digitador", Value = "2" }); muser.Add(new SelectListItem { Text = "Reuniones", Value = "3" }); muser.Add(new SelectListItem { Text = "Secretario", Value = "4" }); ViewData["rol"] = muser; List <SelectListItem> mn = new List <SelectListItem>(); mn.Add(new SelectListItem { Text = "Hombre", Value = "1" }); mn.Add(new SelectListItem { Text = "Mujer", Value = "2" }); ViewData["genero"] = mn; return(View(user)); }