public ActionResult Edit([Bind(Include = "LocationID,LocationName,Address,City,State,Zip,ReservationLimit")] Location location)
 {
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(location));
 }
 public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName")] UserDetail userDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userDetail));
 }
Пример #3
0
 public ActionResult Edit([Bind(Include = "ReservationID,OwnerAssetID,LocationID,ReservationDate")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LocationID   = new SelectList(db.Locations, "LocationID", "LocationName", reservation.LocationID);
     ViewBag.OwnerAssetID = new SelectList(db.OwnerAssets, "OwnerAssetID", "AssetName", reservation.OwnerAssetID);
     return(View(reservation));
 }
        public ActionResult Edit([Bind(Include = "OwnerAssetID,AssetName,OwnerID,AssetPhoto,SpecialNotes,IsActive,DateAdded")] OwnerAsset ownerAsset, HttpPostedFileBase assetImage)
        {
            if (ModelState.IsValid)
            {
                if (assetImage != null)
                {
                    string imageName = assetImage.FileName;

                    string ext = imageName.Substring(imageName.LastIndexOf('.'));

                    string[] goodExts = { ".jpg", ".jpeg", ".png", ".gif" };

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imageName = Guid.NewGuid() + ext;
                        assetImage.SaveAs(Server.MapPath("~/Content/images/Photos/" + imageName));

                        ownerAsset.AssetPhoto = imageName;
                    }
                }

                //Dynamically grabs current logged in user and sets it as the OwnerID if the user is not an Admin
                if (User.IsInRole("Client"))
                {
                    string currentUser = User.Identity.GetUserId();

                    ownerAsset.OwnerID = currentUser;
                }

                if (!User.IsInRole("Admin"))
                {
                    //Automatically sets the IsActive property to true
                    ownerAsset.IsActive = true;
                }

                db.Entry(ownerAsset).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.OwnerID = new SelectList(db.UserDetails, "UserID", "FirstName", ownerAsset.OwnerID);
            return(View(ownerAsset));
        }