public ActionResult Edit([Bind(Include = "Category_ID,Category_Name,Category_ImageName")] tbl_Categories tbl_Categories, HttpPostedFileBase CategoryEdit)
        {
            if (ModelState.IsValid)
            {
                if (CategoryEdit != null)
                {
                    string pathToSave = Server.MapPath(@"~/Content/Uploads/Categories/");

                    //tbl_Categories.Category_ImageName = file.FileName;

                    var replaceCategoryPhoto = new tbl_Categories()
                    {
                        Category_Name      = tbl_Categories.Category_Name,
                        Category_ImagePath = pathToSave
                    };

                    string NewFileName = String.Format("{0}.png", replaceCategoryPhoto.Category_Name);
                    replaceCategoryPhoto.Category_ImageName = NewFileName;
                    CategoryEdit.SaveAs(Path.Combine(pathToSave, NewFileName));
                }

                db.Entry(tbl_Categories).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tbl_Categories));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "City_ID,City_Name,AccountID")] tbl_Cities tbl_Cities)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Cities.Add(tbl_Cities);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AccountID = new SelectList(db.tbl_Accounts, "Account_ID", "Account_FirstName", tbl_Cities.AccountID);
            return(View(tbl_Cities));
        }
        public ActionResult Create([Bind(Include = "Category_ID,Category_Name,Category_ImageName")] tbl_Categories tbl_Categories, HttpPostedFileBase file)
        {
            using (Store_DB db = new Store_DB())
            {
                if (file != null)
                {
                    string pathToSave = Server.MapPath(@"~/Content/Uploads/Categories/");

                    //tbl_Categories.Category_ImageName = file.FileName;

                    var createCategory = new tbl_Categories()
                    {
                        Category_Name      = tbl_Categories.Category_Name,
                        Category_ImagePath = pathToSave
                    };
                    string NewFileName = String.Format("{0}.png", createCategory.Category_Name);
                    createCategory.Category_ImageName = NewFileName;
                    file.SaveAs(Path.Combine(pathToSave, NewFileName));

                    db.tbl_Categories.Add(createCategory);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(View(tbl_Categories));
        }
        public ActionResult Register(AccountsModel user, int Cityid)
        {
            using (Store_DB db = new Store_DB())
            {
                List <tbl_Cities> cityList = (from data in db.tbl_Cities
                                              select data).ToList();
                tbl_Cities objCities = new tbl_Cities();
                objCities.City_Name = "Select City";
                objCities.City_ID   = 0;
                cityList.Insert(0, objCities);
                SelectList objCityModel = new SelectList(cityList, "City_ID", "City_Name", 0);

                AccountsModel objModelForCity = new AccountsModel();
                objModelForCity.AccountCityList = objCityModel;

                var accountCitySelected = ViewBag.City_Name = cityList.Where(c => c.City_ID == Cityid).FirstOrDefault().City_Name;

                if (ModelState.IsValid)
                {
                    var createAccount = new tbl_Accounts()
                    {
                        Account_FirstName    = user.AccountFirstName,
                        Account_LastName     = user.AccountLastName,
                        Account_BirthDate    = user.AccountBirthDate,
                        Account_City         = accountCitySelected,
                        Account_EmailAddress = user.AccountEmailAddress,
                        Account_UserName     = user.AccountUserName,
                        Account_Password     = user.AccountPassword,
                        Account_Mobile       = user.AccountMobile,
                        Account_Phone        = user.AccountPhone,
                        Account_CreatedDate  = user.AccountCreateDate
                    };

                    db.tbl_Accounts.Add(createAccount);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }

                return(View(objModelForCity));
            }
        }