Пример #1
0
        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));
        }
Пример #2
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);
            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
            {
                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name", user.ProjectId);
                ViewBag.UserRolId = new SelectList(CombosHelper.GetUserRols(user.CompanyId), "UserRolId", "Name", user.UserRolId);
            }

            return(View(user));
        }
Пример #3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var quote = db.Quotes.Find(id);

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

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

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", quote.CompanyId);
                ViewBag.ProductId  = new SelectList(CombosHelper.GetProducts(), "ProductId", "Description", quote.ProductId);
                ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(), "SupplierId", "FirstName", quote.SupplierId);
            }
            else
            {
                ViewBag.ProductId  = new SelectList(CombosHelper.GetProducts(quote.CompanyId), "ProductId", "Description", quote.ProductId);
                ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(quote.CompanyId), "SupplierId", "FirstName", quote.SupplierId);
            }
            return(View(quote));
        }
Пример #4
0
        public ActionResult Create()
        {
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
                ViewBag.ProductId  = new SelectList(CombosHelper.GetProducts(), "ProductId", "Description");
                ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(), "SupplierId", "FirstName");
                var quoteNew = new Quote
                {
                    Date = DateTime.Now,
                };
                return(View(quoteNew));
            }
            //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.ProductId  = new SelectList(CombosHelper.GetProducts(user.CompanyId), "ProductId", "Description");
            ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(user.CompanyId), "SupplierId", "FirstName");
            var quote = new Quote
            {
                Date      = DateTime.Now,
                CompanyId = user.CompanyId
            };

            return(View(quote));
        }
Пример #5
0
        public ActionResult Create(Quote quote)
        {
            if (ModelState.IsValid)
            {
                db.Quotes.Add(quote);
                var responseSave = DBHelper.SaveChanges(db);
                if (responseSave.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, responseSave.Message);
            }

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

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

                ViewBag.ProductId  = new SelectList(CombosHelper.GetProducts(), "ProductCategoryId", "Description", quote.ProductId);
                ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(), "SupplierId", "FirstName", quote.SupplierId);
            }
            else
            {
                var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                ViewBag.ProductId  = new SelectList(CombosHelper.GetProducts(user.CompanyId), "ProductCategoryId", "Description", quote.ProductId);
                ViewBag.SupplierId = new SelectList(CombosHelper.GetSuppliers(user.CompanyId), "SupplierId", "FirstName", quote.SupplierId);
            }
            return(View(quote));
        }
Пример #6
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));
        }
Пример #7
0
        public ActionResult Create(NewOrderView order)
        {
            if (ModelState.IsValid)
            {
                var response = MovementsHelper.NewOrder(order, User.Identity.Name);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "UserName", order.CustomerId);
                ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(order.CompanyId), "ProjectId", "Name", order.ProjectId);
                ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", order.CompanyId);
            }
            else
            {
                var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "UserName", order.CustomerId);
                ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name", order.ProjectId);
            }
            order.Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList();
            return(View(order));
        }
Пример #8
0
        public ActionResult Create()
        {
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(0), "ProjectId", "Name");
                var overrunNew = new Overrun
                {
                    Date = DateTime.Now,
                    Type = "Adicional",
                };
                return(View(overrunNew));
            }
            //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.ProjectId = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name");
            var overrun = new Overrun
            {
                Date      = DateTime.Now,
                CompanyId = user.CompanyId,
                Type      = "Adicional",
            };

            return(View(overrun));
        }
Пример #9
0
        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));
        }
Пример #10
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));
        }
Пример #11
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));
        }
Пример #12
0
 // 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());
 }
Пример #13
0
        public ActionResult Edit(Order order)
        {
            if (ModelState.IsValid)
            {
                db.Entry(order).State = EntityState.Modified;
                var responseSave = DBHelper.SaveChanges(db);
                if (responseSave.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, responseSave.Message);
            }
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(order.CompanyId), "CustomerId", "UserName", order.CustomerId);
                ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(order.CompanyId), "ProjectId", "Name", order.ProjectId);
                ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "ProjectId", "Name", order.CompanyId);
            }
            else
            {
                var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "UserName", order.CustomerId);
                ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name", order.ProjectId);
            }
            return(View(order));
        }
Пример #14
0
        public ActionResult Create()
        {
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "FullName");
                ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(0), "ProjectId", "Name");
                ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
                var adminView = new NewOrderView
                {
                    Date    = DateTime.Now,
                    Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(),
                };
                return(View(adminView));
            }
            //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.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "FullName");
            ViewBag.ProjectId  = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name");
            var view = new NewOrderView
            {
                CompanyId = user.CompanyId,
                Date      = DateTime.Now,
                Details   = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(),
            };

            return(View(view));
        }
Пример #15
0
        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));
        }
Пример #16
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var product = db.Products.Find(id);

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

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

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId         = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", product.CompanyId);
                ViewBag.ProductCategoryId = new SelectList(CombosHelper.GetProductCategories(), "ProductCategoryId", "Description", product.ProductCategoryId);
                ViewBag.TaxId             = new SelectList(CombosHelper.GetTaxes(), "TaxId", "Description", product.TaxId);
            }
            else
            {
                ViewBag.ProductCategoryId = new SelectList(CombosHelper.GetProductCategories(product.CompanyId), "ProductCategoryId", "Description", product.ProductCategoryId);
                ViewBag.TaxId             = new SelectList(CombosHelper.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId);
            }

            return(View(product));
        }
Пример #17
0
        public ActionResult Create(int?id)
        {
            //var details = db.Orders.Where(odt => odt.UserName == userName).ToList;
            Order orders = db.Orders.Find(id);

            DisbursedLoan views = new DisbursedLoan()
            {
                //UserName = User.Identity.Name,
                CompanyId         = orders.CompanyId,
                CustomerId        = orders.CustomerId,
                WarehouseId       = orders.WarehouseId,
                OrderId           = orders.OrderId,
                StateId           = DBHelper.GetState("Disbursed", db),
                TypeLoanId        = DBHelper.GetTypeLoan("Renewed", db),
                LoanStateId       = DBHelper.GetLoanState("Common", db),
                StartDate         = orders.StartDate,
                EndDate           = orders.EndDate,
                Period            = orders.Period,
                UserName          = User.Identity.Name,
                Remarks           = orders.Remarks,
                BorrowedCapital   = orders.BorrowedCapital,
                Interest          = orders.Interest,
                Total             = orders.Total,
                Balance           = orders.Balance,
                DailyPayment      = orders.DailyPayment,
                OperatingExpenses = orders.OperatingExpenses,
            };
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();


            ViewBag.CompanyId  = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", orders.CompanyId);
            ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "FullName", orders.CustomerId);

            return(View(views));
        }
Пример #18
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var overrun = db.Overruns.Find(id);

            if (overrun == null)
            {
                return(HttpNotFound());
            }
            var adminUser = WebConfigurationManager.AppSettings["AdminUser"];

            if (adminUser == User.Identity.Name)
            {
                ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", overrun.CompanyId);
                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(0), "ProjectId", "Name", overrun.ProjectId);
            }
            else
            {
                ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(overrun.CompanyId), "ProjectId", "Description", overrun.ProjectId);
            }
            return(View(overrun));
        }
Пример #19
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

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

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

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

            return(View(user));
        }
Пример #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));
        }
Пример #21
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));
        }
Пример #22
0
        // GET: MainWarehouses/Create
        public ActionResult Create()
        {
            var users = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", users.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name");
            ViewBag.DistrictId   = new SelectList(db.Districts, "DistrictId", "Name");
            return(View());
        }
Пример #23
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));
        }
Пример #24
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());
        }
Пример #25
0
        // GET: Users1/Create
        public ActionResult Create()
        {
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name");
            ViewBag.DistrictId   = new SelectList(db.Districts, "DistrictId", "Name");
            //ViewBag.MainWarehouseId = new SelectList(CombosHelper.GetMainWarehouses(), "MainWarehouseId", "Name");
            var user = new User
            {
                MainWarehouseId = 1,
            };

            return(View(user));
        }
Пример #26
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                try
                {
                    db.SaveChanges();

                    UserHelper.CreateUserASP(user.UserName, "User");

                    if (user.PhotoFile != null)
                    {
                        var picture = string.Empty;
                        var folder  = "~/Content/Users";

                        var response = FileHelper.UploadPhoto(user.PhotoFile, folder, $"{user.UserId}.jpg");

                        if (response)
                        {
                            picture = $"{folder}/{user.UserId}.jpg";

                            user.Photo = picture;

                            //actualizo la db:
                            db.Entry(user).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, "There are a record with the same Value.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name");
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name");
            return(View(user));
        }
Пример #27
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                var pic    = user.Photo;
                var folder = "~/Content/Users";

                if (user.PhotoFile != null)
                {
                    if (pic == null || pic == string.Empty)
                    {
                        pic = FilesHelper.GetNamePhoto(user.UserId);
                    }
                    else
                    {
                        pic = pic.Substring(16);
                    }


                    if (pic != null)
                    {
                        pic = FilesHelper.UploadPhoto(user.PhotoFile, pic, folder);
                        pic = string.Format("{0}/{1}", folder, pic);
                    }
                }
                user.Photo = pic;
                var db2         = new EcomerceDataContext();
                var currenrUser = db2.Users.Find(user.UserId);
                if (currenrUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currenrUser.UserName, user.UserName);
                }
                db2.Dispose();
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                var respons = DBHelper.SaveChanges(db);

                if (!respons.Succeded)
                {
                    ModelState.AddModelError(string.Empty, respons.Message);
                    return(View(user));
                }
                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.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
Пример #28
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));
        }
Пример #29
0
        public ActionResult Edit([Bind(Include = "UserId,UserName,FirstName,LastName,Phone,Address,Photo,DepartmentId,CompanyId,CityId")] User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var picture = string.Empty;
                    var folder  = "~/Content/Users";

                    var response = FileHelper.UploadPhoto(user.PhotoFile, folder, $"{user.UserId}.jpg");

                    if (response)
                    {
                        picture = $"{folder}/{user.UserId}.jpg";

                        user.Photo = picture;
                    }
                }

                //Busco el userName viejo a actualizar:
                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UserHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                //close de DB:
                db2.Dispose();

                db.Entry(user).State = EntityState.Modified;

                try
                {
                    //actualizo la db:
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            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.GetDepartment(), "DepartmentId", "Name", user.DepartmentId);

            return(View(user));
        }
Пример #30
0
 public ActionResult Edit(ProductCategory productCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productCategory).State = EntityState.Modified;
         var responseSave = DBHelper.SaveChanges(db);
         if (responseSave.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, responseSave.Message);
     }
     ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", productCategory.CompanyId);
     return(View(productCategory));
 }