Example #1
0
        public ActionResult Create()
        {
            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
            ViewBag.DepartmentId   = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");
            ViewBag.ProjectStateId = new SelectList(CombosHelper.GetProjectStates(), "ProjectStateId", "Name");

            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
                return(View());
            }
            //verifica el usuario logeado y envia su compania a la vista
            var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

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

            var project = new Project {
                CompanyId = user.CompanyId
            };

            return(View(project));
        }
Example #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var project = db.Projects.Find(id);

            if (project == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(project.DepartmentId), "CityId", "Name", project.CityId);
            ViewBag.DepartmentId   = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", project.DepartmentId);
            ViewBag.ProjectStateId = new SelectList(CombosHelper.GetProjectStates(), "ProjectStateId", "Name", project.ProjectStateId);

            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", project.CompanyId);
            }

            return(View(project));
        }
Example #3
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));
        }
        public ActionResult Edit( Company company)
        {
            if (ModelState.IsValid)
            {
                var pic = company.Logo;
                var folder = "~/Content/Logos";

                if (company.LogoFile != null)
                {
                    pic = pic.Substring(16);
                    pic = FilesHelper.UploadPhoto(company.LogoFile,pic, folder);
                    pic = string.Format("{0}/{1}", folder, pic);
                    company.Logo = pic;
                }
                db.Entry(company).State = EntityState.Modified;
                var respon = DBHelper.SaveChanges(db);
                if (!respon.Succeded)
                {
                 ModelState.AddModelError(string.Empty, respon.Message);
                  return View(company);
                }
                 return RedirectToAction("Index");
                
                
            }
            ViewBag.CityId = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", company.DepartmentId);
            return View(company);
        }
Example #5
0
        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.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);

            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(), "UserRolId", "Name", user.UserRolId);
            }
            else
            {
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(), "UserRolId", "Name", user.UserRolId);
            }

            return(View(user));
        }
Example #6
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));
        }
        public ActionResult Edit(User user)
        {
            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);
                    user.Photo = string.Format("{0}/{1}", folder, file);
                }

                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId); //Find look ID

                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();


                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.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
 public ActionResult Edit(Customer customer)
 {
     if (ModelState.IsValid)
     {
         var db2         = new KissiContext();
         var currentUser = db2.Customers.Find(customer.CustomerId);
         if (currentUser.UserName != customer.UserName)
         {
             UsersHelper.UpdateUserName(currentUser.UserName, customer.UserName);
         }
         db2.Dispose();
         db.Entry(customer).State = EntityState.Modified;
         var response = DBHelper.SaveChanges(db);
         if (response.Succeeded)
         {
             //UsersHelper.CreateUserASP(customer.UserName, "Customer");
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, response.Message);
         //return RedirectToAction("Index");
     }
     ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId);
     //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", customer.CompanyId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId);
     return(View(customer));
 }
Example #9
0
        public ActionResult Create([Bind(Include = "UserId,UserName,FirstName,LastName,Phone,Address,Photo,DepartmentId,CityId,CompanyId")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                if (user.PhotoFile != null)
                {
                    var folder   = "~/Content/Users";
                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, string.Format("{0}", user.UserId));

                    var pic = string.Format("{0}/{1}", folder, response);
                    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.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
 // GET: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");
     return(View());
 }
        // GET: VotingPlaces/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var votingPlace = db.VotingPlaces.Find(id);

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

            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));
        }
Example #12
0
        public ActionResult Create(Warehouse warehouse)
        {
            if (ModelState.IsValid)
            {
                db.Warehouses.Add(warehouse);
                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, "There are a record with the same value.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId);
            return(View(warehouse));
        }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                UsersHelper.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}", folder, file);
                        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.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();                                 //meterlo en un try con un mensaje diciendo que no puede haber dos correo iguales
                UsersHelper.CreateUserASP(user.UserName, "User"); // con esta linea validamos que debe crear un usuario


                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"));
                }
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
Example #15
0
        // GET: Customers/Create
        public ActionResult Create()
        {
            ViewBag.CityId    = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
            ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name");

            return(View());
        }
Example #16
0
        // GET: Companies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Company company = db.Companies.Find(id);

            if (company == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId = new SelectList(
                CombosHelper.GetCities(),
                "CityId",
                "Name",
                company.CityId);

            ViewBag.StateId = new SelectList(
                CombosHelper.GetStates(),
                "StateId",
                "Name",
                company.StateId);

            return(View(company));
        }
Example #17
0
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                if (company.LogoFile != null)
                {
                    var folder    = "~/Content/Logos";
                    var file      = string.Format("{0}.jpg", company.CompanyId);
                    var response2 = FilesHelper.UploadPhoto(company.LogoFile, folder, file);
                    if (response2)
                    {
                        company.Logo = string.Format("{0}/{1}", folder, file);;
                    }
                }

                db.Entry(company).State = EntityState.Modified;
                var response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, response.Message);
                }
            }
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
Example #18
0
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");

            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(), "UserRolId", "Name");
                var adminUserModel = new User
                {
                    State     = true,
                    BirthDate = DateTime.Now,
                };
                return(View(adminUserModel));
            }
            //verifica el usuario logeado y envia su compania a la vista
            var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

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

            ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(), "UserRolId", "Name");
            var userModel = new User
            {
                BirthDate = DateTime.Now,
                State     = true,
            };

            return(View(userModel));
        }
Example #19
0
        public ActionResult Create(Company company)
        {
            db.Companies.Add(company);

            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();


                if (company.LogoFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Logos";
                    var file   = string.Format("{0}.jpg", company.CompanyId);

                    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;
                        db.SaveChanges();
                    }
                }


                return(RedirectToAction("Index"));
            }

            ViewBag.CityId        = new SelectList(CombosHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentsId = new SelectList(CombosHelper.GetDepartments(), "DepartmentsId", "Name", company.DepartmentsId);
            return(View(company));
        }
Example #20
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.ProjectId == 0)
                {
                    user.ProjectId = null;
                }

                if (user.PhotoFile != null)
                {
                    var          pic      = string.Empty;
                    const string folder   = "~/Content/Users";
                    var          file     = string.Format("{0}.jpg", user.UserId);
                    var          response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);
                    if (response)
                    {
                        pic        = string.Format("{0}/{1}.", folder, file);
                        user.Photo = pic;
                    }
                }

                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();

                db.Entry(user).State = EntityState.Modified;
                var responseSave = DBHelper.SaveChanges(db);
                if (responseSave.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, responseSave.Message);
            }
            ViewBag.CityId          = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.DepartmentId    = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            ViewBag.PensionSystemId = new SelectList(CombosHelper.GetPensionSystems(), "PensionSystemId", "Name", user.PensionSystemId);

            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);

                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name", user.ProjectId);
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(), "UserRolId", "Name", user.UserRolId);
            }
            else
            {
                var userIdentity = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(userIdentity.CompanyId), "ProjectId", "Name", user.ProjectId);
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(userIdentity.CompanyId), "UserRolId", "Name", user.UserRolId);
            }
            return(View(user));
        }
Example #21
0
 // GET: Users/Create
 public ActionResult Create()
 {
     //precisa trocar o db.Cities pelo metodo criado no CombosHelper pra chamar a lista oredenada
     ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name");
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name");
     return(View());
 }
Example #22
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));
        }
Example #23
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));
        }
Example #24
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.Succeeded)
                        {
                            ModelState.AddModelError(string.Empty, response.Message);
                            transaction.Rollback();
                            ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId);

                            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId);

                            return(View(customer));
                        }

                        UserHelper.CreateUserASP(customer.UserName, "Customer");

                        var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

                        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(customer.DepartmentId), "CityId", "Name", customer.CityId);

            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId);


            return(View(customer));
        }
Example #25
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));
        }
Example #26
0
        // GET: Warehouses/Create
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
            var user      = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
            var warahouse = new Warehouse {
                CompanyId = user.CompanyId,
            };

            return(View(warahouse));
        }
Example #27
0
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");
            var companyModel = new Company
            {
                State = true,
            };

            return(View(companyModel));
        }
 public ActionResult Edit([Bind(Include = "CityId,DepartamentsId,Name")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetCities(), "DepartamentsId", "Name", city.DepartamentsId);
     return(View(city));
 }
Example #29
0
 public ActionResult Create(Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Suppliers.Add(supplier);
                 var response = DBHelper.SaveChanges(db);
                 if (!response.Succeeded)
                 {
                     ModelState.AddModelError(string.Empty, response.Message);
                     transaction.Rollback();
                     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(supplier.DepartmentId), "CityId", "Name", supplier.CityId);
                     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", supplier.DepartmentId);
                     return(View(supplier));
                 }
                 if (supplier.PhotoFile != null)
                 {
                     var folder    = "~/Content/Suppliers";
                     var file      = string.Format("{0}.jpg", supplier.SupplierId);
                     var response2 = FilesHelper.UploadPhoto(supplier.PhotoFile, folder, file);
                     if (response2)
                     {
                         supplier.Photo           = string.Format("{0}/{1}", folder, file);
                         db.Entry(supplier).State = EntityState.Modified;
                         db.SaveChanges();
                     }
                 }
                 UsersHelper.CreateUserASP(supplier.UserName, "Supplier");
                 var user            = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
                 var CompanySupplier = new CompanySupplier
                 {
                     CompanyId  = user.CompanyId,
                     SupplierId = supplier.SupplierId,
                 };
                 db.CompanySuppliers.Add(CompanySupplier);
                 db.SaveChanges();
                 transaction.Commit();
                 return(RedirectToAction("Index"));
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 ModelState.AddModelError(string.Empty, ex.Message);
             }
         }
     }
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(supplier.DepartmentId), "CityId", "Name", supplier.CityId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", supplier.DepartmentId);
     return(View(supplier));
 }
Example #30
0
 public ActionResult Edit(Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         db.Entry(warehouse).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", warehouse.DepartmentId);
     return(View(warehouse));
 }