示例#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}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                        //actalizamos la dv
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
示例#2
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                byte[] imagenActual = null;

                HttpPostedFileBase FileBase = Request.Files[0];
                if (FileBase == null)
                {
                    imagenActual = db.Users.SingleOrDefault(t => t.UserID == user.UserID).Foto;
                }
                else
                {
                    WebImage image = new WebImage(FileBase.InputStream);
                    user.Foto = image.GetBytes();
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID);
            ViewBag.CompanyID    = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID);
            return(View(user));
        }
示例#3
0
 public ActionResult Create()
 {
     ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name");
     ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name");
     return(View());
 }
示例#4
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}-{1}.jpg", company.CompanyId, company.Name);
                    var respose = FilesHelpers.UploadPhoto(company.LogoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        company.Logo = pic;
                        //actalizamos la dv
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
        // GET: Companies/Create
        public ActionResult Create()
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(0), "CityID", "Name");
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name");
            return(View());
        }
 public ActionResult Edit(Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         db.Entry(warehouse).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", warehouse.CityId);
     ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId);
     return(View(warehouse));
 }
示例#7
0
        public ActionResult Create(Warehouse warehouse)
        {
            if (ModelState.IsValid)
            {
                db.Warehouses.Add(warehouse);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(warehouse.DepartmentID), "CityID", "Name", warehouse.CityID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", warehouse.DepartmentID);
            return(View(warehouse));
        }
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name");

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

            var customer = new Customer {
                CompanyId = user.CompanyId
            };

            return(View(customer));
        }
        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(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId);
                            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId);
                            return(View(customer));
                        }

                        UsersHelper.CreateUserASP(customer.UserName, "Customer");
                        var user            = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
                        var companyCustomer = new CompanyCustomers
                        {
                            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(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId);
            return(View(customer));
        }
        // 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(CombosHelpers.GetCities(company.DepartmentID), "CityID", "Name", company.CityID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", company.DepartmentID);
            return(View(company));
        }
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase FileBase = Request.Files[0];
                WebImage           image    = new WebImage(FileBase.InputStream);
                company.Logo = image.GetBytes();
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(company.DepartmentID), "CityID", "Name", company.CityID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", company.DepartmentID);
            return(View(company));
        }
        // 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(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId);
            return(View(customer));
        }
示例#13
0
        // GET: Warehouses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Warehouse warehouse = db.Warehouses.Find(id);

            if (warehouse == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(warehouse.DepartmentID), "CityID", "Name", warehouse.CityID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", warehouse.DepartmentID);
            return(View(warehouse));
        }
        public ActionResult Edit(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                var response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId);
            return(View(customer));
        }
示例#15
0
        public ActionResult Create(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();

                //El customer tiene rol de Customer
                UsersHelper.CreateUserASP(customer.UserName, "Customer");

                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", customer.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId);
            return(View(customer));
        }
示例#16
0
        public ActionResult Edit(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();

                // TODO: validar cuando el email cambia

                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", customer.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId);

            return(View(customer));
        }
示例#17
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase FileBase = Request.Files[0];
                WebImage           image    = new WebImage(FileBase.InputStream);
                user.Foto = image.GetBytes();
                db.Users.Add(user);
                db.SaveChanges();
                UsersHelper.CreateUserASP(user.UserName, "User");
                return(RedirectToAction("Index"));
            }

            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID);
            ViewBag.CompanyID    = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID);
            return(View(user));
        }
示例#18
0
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name");

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

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

            var warehouse = new Warehouse {
                CompanyId = user.CompanyId
            };

            return(View(warehouse));
        }
示例#19
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        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();

                //actalizamos la dv
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }