Beispiel #1
0
 public ActionResult Edit([Bind(Include = "Id,Name,IsActive")] CountryTbl countryTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(countryTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(countryTbl));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,StateId,IsActive")] CityTbl cityTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cityTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StateId = new SelectList(db.StateTbls, "Id", "Name", cityTbl.StateId);
     return(View(cityTbl));
 }
        public ActionResult Save(Item item, HttpPostedFileBase imageUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View("ProductForm", item));
            }

            if (item.Id == 0)
            {
                if (imageUrl != null)
                {
                    string ImageName    = System.IO.Path.GetFileName(imageUrl.FileName);
                    string physicalPath = Server.MapPath("~/UploadedImages/" + ImageName);

                    // save image in folder
                    imageUrl.SaveAs(physicalPath);

                    //save new record in database
                    item.ImageUrl = ImageName;
                    db.Item.Add(item);
                }
            }
            else
            {
                var updateItem = db.Item.Find(item.Id);
                if (updateItem == null)
                {
                    return(HttpNotFound());
                }
                if (imageUrl != null)
                {
                    string ImageName    = System.IO.Path.GetFileName(imageUrl.FileName);
                    string physicalPath = Server.MapPath("~/UploadedImages/" + ImageName);

                    // save image in folder
                    imageUrl.SaveAs(physicalPath);

                    //save new record in database
                    item.ImageUrl = ImageName;
                    db.Entry(updateItem).CurrentValues.SetValues(item);
                }
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(User user)
        {
            bool IsUNExist = false;
            var  userExist = db.User.FirstOrDefault(m => m.Username == user.Username);

            if (userExist != null)
            {
                IsUNExist = (userExist.Id == user.Id) ? false : true;
            }

            bool IsEMExist = false;

            userExist = db.User.FirstOrDefault(m => m.Email == user.Email);
            if (userExist != null)
            {
                IsEMExist = (userExist.Id == user.Id) ? false : true;
            }

            userExist = db.User.FirstOrDefault(m => m.Id == user.Id);

            if (ModelState.IsValid && !IsUNExist && !IsEMExist)
            {
                db.Entry(userExist).CurrentValues.SetValues(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            if (IsUNExist)
            {
                ModelState.AddModelError("", "Username is already exist.");
            }
            else if (IsEMExist)
            {
                ModelState.AddModelError("", "Email is already exist.");
            }
            else
            {
                ModelState.AddModelError("", "Fill the blanks correctly.");
            }
            return(View(user));
        }