// GET: Companies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(
                           HttpStatusCode.BadRequest));
            }

            var company = db.Companies.Find(id);

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

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(company.StateId),
                    "CityId",
                    "NameCity",
                    company.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    company.StateId);

            return(View(company));
        }
Exemplo n.º 2
0
        // GET: WareHouses/Create
        public ActionResult Create()
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity");

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState");

            var warehouse =
                new WareHouse
            {
                CompanyId = user.CompanyId,
            };

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

            var wareHouse = db.WareHouses.Find(id);

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

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    wareHouse.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    wareHouse.StateId);

            return(View(wareHouse));
        }
Exemplo n.º 4
0
        // GET: Users/Create
        public ActionResult Create()
        {
            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(0),
                    "CityId",
                    "NameCity");

            ViewBag.CompanyId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany");

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState");

            return(View());
        }
Exemplo n.º 5
0
        public ActionResult Edit(WareHouse wareHouse)
        {
            if (ModelState.IsValid)
            {
                db.Entry(wareHouse).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,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }
            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    wareHouse.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    wareHouse.StateId);

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

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

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

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

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(customer.StateId),
                    "CityId",
                    "NameCity",
                    customer.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    customer.StateId);

            return(View(customer));
        }
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (company.LogoFile != null)
                    {
                        var folder = "~/Content/Logos";

                        var file = string.Format("{0}.jpg",
                                                 company.CompanyId);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                company.LogoFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            company.Logo = pic;

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

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(company.StateId),
                    "CityId",
                    "NameCity",
                    company.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    company.StateId);

            return(View(company));
        }
Exemplo n.º 8
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    UsersHelpers.
                    CreateUserASP(user.UserName, "User");

                    if (user.PhotoFile != null)
                    {
                        var folder = "~/Content/Photos";

                        var file = string.Format("{0}.jpg",
                                                 user.UserID);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                user.PhotoFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            user.Photo = pic;

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

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(user.StateId),
                    "CityId",
                    "NameCity",
                    user.CityId);

            ViewBag.CompanyId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    user.CompanyId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    user.StateId);

            return(View(user));
        }
Exemplo n.º 9
0
        public ActionResult Create(Customer customer)
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (customer.LogoCFile != null)
                    {
                        var folder = "~/Content/Customers";

                        var file = string.Format("{0}.jpg",
                                                 customer.CustomerID);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                customer.LogoCFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            customer.LogoC = pic;

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

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(customer.StateId),
                    "CityId",
                    "NameCity",
                    customer.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    customer.StateId);

            return(View(customer));
        }