Exemplo n.º 1
0
        // GET: Voters/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var voter = db.Voters.Find(id);

            if (voter == null)
            {
                return(HttpNotFound());
            }
            var city        = db.Cities.Where(c => c.Name.Contains(voter.CityId)).FirstOrDefault();
            var comune      = db.Communes.Where(c => c.Name.Contains(voter.CommuneId)).FirstOrDefault();
            var country     = db.Countries.Where(c => c.Name.Contains(voter.CountryId)).FirstOrDefault();
            var department  = db.Departments.Where(c => c.Name.Contains(voter.DepartmentId)).FirstOrDefault();
            var votingplace = db.VotingPlaces.Where(c => c.Name.Contains(voter.VotingPlaceId)).FirstOrDefault();

            ViewBag.CityId        = new SelectList(CombosHelper.GetCities(), "CityId", "Name", city.CityId);
            ViewBag.CommuneId     = new SelectList(CombosHelper.GetCommunes(), "CommuneId", "Name", comune.CommuneId);
            ViewBag.CountryId     = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", country.CountryId);
            ViewBag.DepartmentId  = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", department.DepartmentId);
            ViewBag.VotingPlaceId = new SelectList(CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name", votingplace.VotingPlaceId);
            ViewBag.PerfilId      = new SelectList(CombosHelper.GetUser(), "userId", "name", voter.PerfilId);
            ViewBag.ReferId       = new SelectList(CombosHelper.GetRefer(), "ReferId", "FullName", voter.ReferId);

            return(View(voter));
        }
Exemplo n.º 2
0
        // GET: Emails/Create
        public ActionResult Create()
        {
            ViewBag.userId = new SelectList(
                CombosHelper.GetUserNoVoters(),
                "userId",
                "name");

            ViewBag.ReferId = new SelectList(
                CombosHelper.GetStandaloneRefer(),
                "ReferId",
                "FullName");

            ViewBag.FilterId = new SelectList(
                CombosHelper.GetVoterFilters(),
                "FiltersId",
                "name");

            ViewBag.VotingPlaceId = new SelectList(
                CombosHelper.GetVotingPlaces(),
                "VotingPlaceId",
                "Name");

            ViewBag.WorkPlaceId = new SelectList(
                CombosHelper.GetWorkPlaces(),
                "WorkPlaceId",
                "Name");

            ViewBag.Comuna = new SelectList(
                CombosHelper.GetCommunes(),
                "CommuneId",
                "Name");
            return(View());
        }
Exemplo n.º 3
0
        // GET: Voters/Create
        public ActionResult Create()
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.CityId        = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
            ViewBag.CommuneId     = new SelectList(CombosHelper.GetCommunes(), "CommuneId", "Name");
            ViewBag.CountryId     = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name");
            ViewBag.DepartmentId  = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");
            ViewBag.VotingPlaceId = new SelectList(CombosHelper.GetVotingPlaces(), "VotingPlaceId", "Name");
            ViewBag.PerfilId      = new SelectList(
                CombosHelper.GetUser(),
                "userId",
                "name");

            ViewBag.ReferId = new SelectList(
                CombosHelper.GetRefer(),
                "ReferId",
                "FullName");
            var voter = new Voter
            {
                CompanyId = user.CompanyId,
                DateBorn  = DateTime.Now,
            };

            return(View(voter));
        }
Exemplo n.º 4
0
        // GET: Bosses/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.BossId = new SelectList(
                CombosHelper.GetBosses(user.CompanyId),
                "BossId",
                "FullName");

            ViewBag.CommuneId = new SelectList(
                CombosHelper.GetCommunes(),
                "CommuneId",
                "Name");

            ViewBag.WorkPlaceId = new SelectList(
                CombosHelper.GetWorkPlaces(),
                "WorkPlaceId",
                "Name");

            ViewBag.VotingPlaceId = new SelectList(
                CombosHelper.GetVotingPlaces(),
                "VotingPlaceId",
                "Name");

            var link = new Link
            {
                CompanyId = user.CompanyId,
                Date      = DateTime.Now,
                DateBorn  = DateTime.Now,
            };

            return(View(link));
        }
Exemplo n.º 5
0
        // GET: Bosses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var boss = db.Bosses.Find(id);

            if (boss == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CountryId = new SelectList(
                CombosHelper.GetCountries(),
                "CountryId",
                "Name",
                boss.CountryId);

            ViewBag.CityId = new SelectList(
                CombosHelper.GetCities(),
                "CityId",
                "Name",
                boss.CityId);

            ViewBag.CompanyId = new SelectList(
                CombosHelper.GetCompanies(),
                "CompanyId",
                "Name",
                boss.CompanyId);

            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepartments(),
                "DepartmentId",
                "Name",
                boss.DepartmentId);

            ViewBag.CommuneId = new SelectList(
                CombosHelper.GetCommunes(),
                "CommuneId",
                "Name",
                boss.CommuneId);

            ViewBag.WorkPlaceId = new SelectList(
                CombosHelper.GetWorkPlaces(),
                "WorkPlaceId",
                "Name",
                boss.WorkPlaceId);

            ViewBag.VotingPlaceId = new SelectList(
                CombosHelper.GetVotingPlaces(),
                "VotingPlaceId",
                "Name",
                boss.VotingPlaceId);
            return(View(boss));
        }
Exemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            var voter = db.Voters.Find(id);

            db.Voters.Remove(voter);
            try
            {
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                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.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));
        }
Exemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            var link = db.Links.Find(id);

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    var response = FilesHelper.DeleteDocument(link.Photo);
                    var Voter    = db.Voters.Where(V => V.Document == link.Document).FirstOrDefault();
                    if (Voter != null)
                    {
                        db.Voters.Remove(Voter);
                    }
                    var Refer = db.Refers.Where(r => r.ReferType == 2 && r.UserId == link.LinkId).FirstOrDefault();
                    if (Refer != null)
                    {
                        var coordinators = db.Coordinators.Where(c => c.ReferId == Refer.ReferId).ToList();
                        foreach (var coor in coordinators)
                        {
                            db.Coordinators.Remove(coor);
                        }

                        var leaders = db.Leaders.Where(l => l.ReferId == Refer.ReferId).ToList();
                        foreach (var leader in leaders)
                        {
                            db.Leaders.Remove(leader);
                        }

                        var voters = db.Voters.Where(v => v.ReferId == Refer.ReferId).ToList();
                        foreach (var voter in voters)
                        {
                            db.Voters.Remove(voter);
                        }

                        db.Refers.Remove(Refer);
                        db.SaveChanges();
                    }

                    //Elimino todo Coordinador y Lider Asociado a este enlace

                    //Borro cualquier anotacion que tenga en la agenda
                    var dates = db.Dates.Where(d => d.ProfessionalId == link.Document).ToList();
                    foreach (var item in dates)
                    {
                        db.Dates.Remove(item);
                    }

                    var dateItems = db.TimesDates.Where(di => di.ProfessionalId == link.Document).ToList();
                    foreach (var it in dateItems)
                    {
                        db.TimesDates.Remove(it);
                    }


                    var HV = db.HojaVidas.Where(h => h.RolId == 2 && h.UserId == link.LinkId).FirstOrDefault();
                    if (HV != null)
                    {
                        db.HojaVidas.Remove(HV);
                    }
                    db.Links.Remove(link);
                    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",
                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));
        }
Exemplo n.º 8
0
        public ActionResult Edit(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;
                    }
                }
                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();
                    }
                }

                db.Entry(link).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();

                    var referr = db.Refers.Where(r => r.ReferType == 1 && r.UserId == link.BossId).FirstOrDefault();

                    var voter      = db.Voters.Where(v => v.Document == link.Document && v.UserName == link.UserName).FirstOrDefault();
                    var country    = db.Countries.Find(link.CountryId);
                    var department = db.Departments.Find(link.DepartmentId);
                    var city       = db.Cities.Find(link.CityId);
                    var commune    = db.Communes.Find(link.CommuneId);
                    var voting     = db.VotingPlaces.Find(link.VotingPlaceId);

                    voter.Address         = link.Address;
                    voter.BossId          = link.BossId;
                    voter.CityId          = city.Name;
                    voter.CommuneId       = commune.Name;
                    voter.CompanyId       = link.CompanyId;
                    voter.CountryId       = country.Name;
                    voter.DepartmentId    = department.Name;
                    voter.Document        = link.Document;
                    voter.FirstName       = link.FirstName;
                    voter.LastName        = link.LastName;
                    voter.Phone           = link.Phone;
                    voter.UserName        = link.UserName;
                    voter.VotingPlaceId   = voting.Name;
                    voter.userId          = 2;
                    voter.ReferId         = referr.ReferId;
                    voter.PerfilId        = 1;
                    voter.Fname           = string.Format("{0} {1}", link.FirstName, link.LastName);
                    voter.Barrio          = link.Barrio;
                    voter.Profesion       = link.Profesion;
                    voter.DateBorn        = link.DateBorn;
                    db.Entry(voter).State = EntityState.Modified;

                    var refer = db.Refers.Where(r => r.ReferType == 2 && r.UserId == link.LinkId).FirstOrDefault();
                    refer.FullName        = link.FullName;
                    db.Entry(refer).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",
                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));
        }
Exemplo n.º 9
0
        public ActionResult Index(string Document, string CustomerId, int?FilterId, int?Comuna, int?VotingPlaceId, int?WorkPlaceId, int?page = null)
        {
            ViewBag.uno    = FilterId;
            ViewBag.dos    = Comuna;
            ViewBag.tres   = VotingPlaceId;
            ViewBag.cuatro = WorkPlaceId;
            page           = (page ?? 1);
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!string.IsNullOrEmpty(Document))
            {
                if (Utilidades.isNumeric(Document))
                {
                    ViewBag.FilterId = new SelectList(
                        CombosHelper.GetFilters(),
                        "FiltersId",
                        "name");

                    ViewBag.VotingPlaceId = new SelectList(
                        CombosHelper.GetVotingPlaces(),
                        "VotingPlaceId",
                        "Name");

                    ViewBag.WorkPlaceId = new SelectList(
                        CombosHelper.GetWorkPlaces(),
                        "WorkPlaceId",
                        "Name");

                    ViewBag.Comuna = new SelectList(
                        CombosHelper.GetCommunes(),
                        "CommuneId",
                        "Name");
                    double doc  = Convert.ToDouble(Document);
                    var    link = db.Links.Where(v => v.Document == doc);
                    return(View(link.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 5)));
                }
            }

            if (!string.IsNullOrEmpty(CustomerId))
            {
                if (Utilidades.isNumeric(CustomerId))
                {
                    ViewBag.FilterId = new SelectList(
                        CombosHelper.GetFilters(),
                        "FiltersId",
                        "name");

                    ViewBag.VotingPlaceId = new SelectList(
                        CombosHelper.GetVotingPlaces(),
                        "VotingPlaceId",
                        "Name");

                    ViewBag.WorkPlaceId = new SelectList(
                        CombosHelper.GetWorkPlaces(),
                        "WorkPlaceId",
                        "Name");

                    ViewBag.Comuna = new SelectList(
                        CombosHelper.GetCommunes(),
                        "CommuneId",
                        "Name");
                    int doc  = Convert.ToInt32(CustomerId);
                    var link = db.Links.Where(b => b.LinkId == doc);
                    return(View(link.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 5)));
                }
            }
            if (FilterId > 0)
            {
                if (FilterId == 1)//GENERAL
                {
                    ViewBag.FilterId = new SelectList(
                        CombosHelper.GetFilters(),
                        "FiltersId",
                        "name",
                        FilterId);

                    ViewBag.VotingPlaceId = new SelectList(
                        CombosHelper.GetVotingPlaces(),
                        "VotingPlaceId",
                        "Name");

                    ViewBag.Comuna = new SelectList(
                        CombosHelper.GetCommunes(),
                        "CommuneId",
                        "Name");
                    ViewBag.WorkPlaceId = new SelectList(
                        CombosHelper.GetWorkPlaces(),
                        "WorkPlaceId",
                        "Name");

                    var linkGeneral = db.Links.Where(b => b.CompanyId == user.CompanyId);
                    return(View(linkGeneral.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 5)));
                }
                if (FilterId == 2)//COMUNA
                {
                    if (Comuna > 0)
                    {
                        ViewBag.FilterId = new SelectList(
                            CombosHelper.GetFilters(),
                            "FiltersId",
                            "name",
                            FilterId);

                        ViewBag.Comuna = new SelectList(
                            CombosHelper.GetCommunes(),
                            "CommuneId",
                            "Name",
                            Comuna);

                        ViewBag.VotingPlaceId = new SelectList(
                            CombosHelper.GetVotingPlaces(),
                            "VotingPlaceId",
                            "Name");
                        ViewBag.WorkPlaceId = new SelectList(
                            CombosHelper.GetWorkPlaces(),
                            "WorkPlaceId",
                            "Name");

                        var linkComuna = db.Links.Where(b => b.CompanyId == user.CompanyId && b.CommuneId == Comuna);
                        return(View(linkComuna.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 10)));
                    }
                }
                if (FilterId == 3)//LUGAR DE VOTACION
                {
                    if (VotingPlaceId > 0)
                    {
                        ViewBag.FilterId = new SelectList(
                            CombosHelper.GetFilters(),
                            "FiltersId",
                            "name",
                            FilterId);

                        ViewBag.Comuna = new SelectList(
                            CombosHelper.GetCommunes(),
                            "CommuneId",
                            "Name");

                        ViewBag.WorkPlaceId = new SelectList(
                            CombosHelper.GetWorkPlaces(),
                            "WorkPlaceId",
                            "Name");

                        ViewBag.VotingPlaceId = new SelectList(
                            CombosHelper.GetVotingPlaces(),
                            "VotingPlaceId",
                            "Name",
                            VotingPlaceId);

                        var linkVotacion = db.Links.Where(b => b.CompanyId == user.CompanyId && b.VotingPlaceId == VotingPlaceId);
                        return(View(linkVotacion.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 10)));
                    }
                }

                if (FilterId == 4)
                {
                    if (WorkPlaceId > 0)
                    {
                        ViewBag.FilterId = new SelectList(
                            CombosHelper.GetFilters(),
                            "FiltersId",
                            "name",
                            FilterId);

                        ViewBag.Comuna = new SelectList(
                            CombosHelper.GetCommunes(),
                            "CommuneId",
                            "Name");

                        ViewBag.VotingPlaceId = new SelectList(
                            CombosHelper.GetVotingPlaces(),
                            "VotingPlaceId",
                            "Name");

                        ViewBag.WorkPlaceId = new SelectList(
                            CombosHelper.GetWorkPlaces(),
                            "WorkPlaceId",
                            "Name",
                            WorkPlaceId);

                        var linkWork = db.Links.Where(b => b.CompanyId == user.CompanyId && b.WorkPlaceId == WorkPlaceId);
                        return(View(linkWork.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 10)));
                    }
                }
            }
            ViewBag.FilterId = new SelectList(
                CombosHelper.GetFilters(),
                "FiltersId",
                "name");

            ViewBag.VotingPlaceId = new SelectList(
                CombosHelper.GetVotingPlaces(),
                "VotingPlaceId",
                "Name");

            ViewBag.WorkPlaceId = new SelectList(
                CombosHelper.GetWorkPlaces(),
                "WorkPlaceId",
                "Name");

            ViewBag.Comuna = new SelectList(
                CombosHelper.GetCommunes(),
                "CommuneId",
                "Name");
            var links = db.Links.Where(b => b.CompanyId == user.CompanyId);

            return(View(links.OrderBy(b => b.CompanyId).ThenBy(b => b.FirstName).ToPagedList((int)page, 10)));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        // 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));
        }
Exemplo n.º 12
0
        public ActionResult Create(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;
                    }
                }
                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.Leaders.Add(leader);
                try
                {
                    db.SaveChanges();
                    //UsersHelper.CreateUserASP(leader.UserName, "Leader");
                    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 = new Refer
                    {
                        ReferType = 4,
                        UserId    = leader.LeaderId,
                        FullName  = leader.FullName,
                        Active    = 1
                    };
                    db.Refers.Add(Refer);
                    db.SaveChanges();


                    var city        = db.Cities.Find(leader.CityId);
                    var department  = db.Departments.Find(leader.DepartmentId);
                    var country     = db.Countries.Find(leader.CountryId);
                    var comune      = db.Communes.Find(leader.CommuneId);
                    var votingPlace = db.VotingPlaces.Find(leader.VotingPlaceId);
                    var Voter       = new Voter
                    {
                        Address       = leader.Address,
                        BossId        = leader.BossId,
                        LinkId        = leader.LinkId,
                        CoordinatorId = leader.CoordinatorId,
                        CityId        = city.Name,
                        CommuneId     = comune.Name,
                        CompanyId     = leader.CompanyId,
                        CountryId     = leader.Country.Name,
                        DepartmentId  = department.Name,
                        Document      = leader.Document,
                        FirstName     = leader.FirstName,
                        LastName      = leader.LastName,
                        Phone         = leader.Phone,
                        UserName      = leader.UserName,
                        VotingPlaceId = votingPlace.Name,
                        userId        = 4,
                        ReferId       = refer.ReferId,
                        PerfilId      = leader.userId,
                        Fname         = string.Format("{0} {1}", leader.FirstName, leader.LastName),
                        Barrio        = leader.Barrio,
                        Profesion     = leader.Profesion,
                        DateBorn      = leader.DateBorn,
                    };
                    db.Voters.Add(Voter);

                    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.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));
        }
Exemplo n.º 13
0
        // 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));
        }