Ejemplo n.º 1
0
        public ActionResult AddProduct(AddProductView view)
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            if (ModelState.IsValid)
            {
                var orderDetailTmp =
                    db.OrderDetailTmps.
                    Where(odt => odt.UserName ==
                          User.Identity.Name &&
                          odt.ProductID == view.ProductId).
                    FirstOrDefault();

                if (orderDetailTmp == null)
                {
                    var product =
                        db.Products.Find(view.ProductId);

                    orderDetailTmp = new OrderDetailTmp
                    {
                        Description = product.Description,
                        Price       = product.Price,
                        ProductID   = product.ProductID,
                        Quantity    = view.Quantity,
                        TaxRate     = product.Tax.Rate,
                        UserName    = User.Identity.Name,
                    };

                    db.OrderDetailTmps.
                    Add(orderDetailTmp);
                }
                else
                {
                    orderDetailTmp.Quantity += view.Quantity;

                    db.Entry(orderDetailTmp).State =
                        EntityState.Modified;
                }

                db.SaveChanges();

                return(RedirectToAction("Create"));
            }

            ViewBag.ProductId =
                new SelectList(
                    ComboBoxHelpers.
                    GetProducts(
                        user.CompanyId),
                    "ProductID",
                    "Description");

            return(PartialView(view));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Tax tax)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tax).State =
                    EntityState.Modified;

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

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

            return(View(tax));
        }
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Entry(category).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);
                    }
                }
            }

            return(View(category));
        }
Ejemplo n.º 5
0
        public ActionResult Create(City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);

                try
                {
                    db.SaveChanges();

                    if (city.FlagFile != null)
                    {
                        var folder = "~/Content/Cities/FlagsCities";

                        var file = string.Format("{0}.jpg",
                                                 city.CityId);

                        var response =
                            FilesHelpers.
                            UploadPhoto(
                                city.FlagFile,
                                folder, file);

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

                            city.Flag = pic;

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

                            db.SaveChanges();
                        }
                    }
                    if (city.ShieldFile != null)
                    {
                        var folder1 = "~/Content/Cities/ShieldsCities";

                        var file1 = string.Format("{0}.jpg",
                                                  city.CityId);

                        var response1 =
                            FilesHelpers.
                            UploadPhoto(
                                city.ShieldFile,
                                folder1, file1);

                        if (response1)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder1,
                                              file1);

                            city.Shield = pic;

                            db.Entry(city).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,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

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

            return(View(city));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public ActionResult Create(Product product)
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Products.Add(product);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (product.ImageFile != null)
                    {
                        var folder = "~/Content/Products";

                        var file = string.Format("{0}.jpg",
                                                 product.ProductID);

                        var response =
                            FilesHelpers.
                            UploadPhoto(
                                product.ImageFile,
                                folder, file);

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

                            product.Image = pic;

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

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

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

            ViewBag.CategoryId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCategories(
                        user.CompanyId),
                    "CategoryId",
                    "Description",
                    product.CategoryId);

            ViewBag.TaxId =
                new SelectList(
                    ComboBoxHelpers.
                    GetTaxes(
                        user.CompanyId),
                    "TaxId",
                    "Description",
                    product.TaxId);

            return(View(product));
        }
Ejemplo n.º 10
0
        public ActionResult Create(State state)
        {
            if (ModelState.IsValid)
            {
                db.States.Add(state);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (state.FlagFile != null)
                    {
                        var folder = "~/Content/Flags";

                        var file = string.Format("{0}.jpg",
                                                 state.StateId);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                state.FlagFile,
                                folder, file);

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

                            state.Flag = pic;

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

                            db.SaveChanges();
                        }
                    }

                    if (state.ShieldFile != null)
                    {
                        var folder1 = "~/Content/Shields";

                        var file1 = string.Format("{0}.jpg",
                                                  state.StateId);

                        var response1 =
                            FilesHelpers.
                            UploadPhoto(
                                state.ShieldFile,
                                folder1, file1);

                        if (response1)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder1,
                                              file1);

                            state.Shield = pic;

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

                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }

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

            return(View(state));
        }