Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            var department = db.Departments.Find(id);

            db.Departments.Remove(department);
            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.CountryId = new SelectList(
                CombosHelper.GetCountries(),
                "CountryId",
                "Name",
                department.CountryId);
            return(View(department));
        }
Exemplo n.º 2
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.º 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: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name");
     return(View());
 }
Exemplo n.º 5
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                UserHelper.CreateUserASP(user.UserName, "User");

                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}.jpg", folder, user.UserId);
                        user.Photo           = pic;
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", user.CountryId);
            return(View(user));
        }
Exemplo n.º 6
0
        // GET: Cities/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var city = db.Cities.Find(id);

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

            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepartments(),
                "DepartmentId",
                "Name",
                city.DepartmentId);
            return(View(city));
        }
Exemplo n.º 7
0
 public ActionResult Create(Department department)
 {
     if (ModelState.IsValid)
     {
         db.Departments.Add(department);
         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",
         department.CountryId);
     return(View(department));
 }
Exemplo n.º 8
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                if (company.LogoFile != null)
                {
                    var folder   = "~/Content/Logos";
                    var file     = string.Format("{0}.jpg", company.CompanyId);
                    var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}.jpg", folder, company.CompanyId);
                        company.Logo            = pic;
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", company.CountryId);
            return(View(company));
        }
Exemplo n.º 9
0
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                if (company.LogoFile != null)
                {
                    var pic      = string.Empty;
                    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)
                    {
                        pic          = string.Format("{0}/{1}", folder, file);
                        company.Logo = pic;
                    }
                }

                db.Entry(company).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",
                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));
        }
Exemplo n.º 10
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.º 11
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.º 12
0
        // GET: Users/Create
        public ActionResult Create()
        {
            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");

            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());
        }
Exemplo n.º 13
0
        // GET: Cities/Create
        public ActionResult Create()
        {
            ViewBag.CountryId = new SelectList(
                CombosHelper.GetCountries(),
                "CountryId",
                "Name");

            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepartments(),
                "DepartmentId",
                "Name");
            return(View());
        }
Exemplo n.º 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            var user = db.Users.Find(id);

            db.Users.Remove(user);
            try
            {
                var response = FilesHelper.DeleteDocument(user.Photo);
                db.SaveChanges();
                UsersHelper.DeleteUser(user.UserName);
                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.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);
            return(View(user));
        }
Exemplo n.º 15
0
        public ActionResult Edit(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                var response = DBHelper.SaveChanges(db);
                if (response.Succedeed)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }

            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name", customer.CityId);
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", customer.CountryId);
            return(View(customer));
        }
        public ActionResult Edit(VotingPlace votingPlace)
        {
            if (ModelState.IsValid)
            {
                db.Entry(votingPlace).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",
                votingPlace.CountryId);

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

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

            return(View(votingPlace));
        }
Exemplo n.º 17
0
        // GET: Customers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Customer customer = db.Customers.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name", customer.CityId);
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", customer.CountryId);
            return(View(customer));
        }
Exemplo n.º 18
0
        public ActionResult Create(Customer customer)
        {
            if (ModelState.IsValid)
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Customers.Add(customer);
                        var response = DBHelper.SaveChanges(db);
                        if (!response.Succedeed)
                        {
                            ModelState.AddModelError(string.Empty, response.Message);
                            transaction.Rollback();
                            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(), "CityId", "Name", customer.CityId);
                            ViewBag.DepartmentId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", customer.CountryId);
                        }
                        UserHelper.CreateUserASP(customer.UserName, "Customer");

                        var user            = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
                        var companyCustomer = new CompanyCustomer
                        {
                            CompanyId  = user.CompanyId,
                            CustomerId = customer.CustomerId,
                        };

                        db.CompanyCustomers.Add(companyCustomer);
                        db.SaveChanges();

                        transaction.Commit();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name", customer.CityId);
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", customer.CountryId);
            return(View(customer));
        }
Exemplo n.º 19
0
        // GET: Departments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var department = db.Departments.Find(id);

            if (department == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CountryId = new SelectList(
                CombosHelper.GetCountries(),
                "CountryId",
                "Name",
                department.CountryId);
            return(View(department));
        }
Exemplo n.º 20
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.º 21
0
        // 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));
        }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
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.º 24
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.º 25
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.º 26
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.º 27
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.º 28
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));
        }
Exemplo n.º 29
0
        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));
        }