public ActionResult Create([Bind(Include = "LocationID,LocationName,Address,City,State,Zip,ReservationLimit")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
        public ActionResult Create([Bind(Include = "UserID,FirstName,LastName")] UserDetail userDetail)
        {
            if (ModelState.IsValid)
            {
                db.UserDetails.Add(userDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userDetail));
        }
        public ActionResult Create([Bind(Include = "OwnerAssetID,AssetName,OwnerID,AssetPhoto,SpecialNotes,IsActive,DateAdded")] OwnerAsset ownerAsset, HttpPostedFileBase assetImage)
        {
            if (ModelState.IsValid)
            {
                //default image
                string imageName = "noImage.png";

                //if file was sent
                if (assetImage != null)
                {
                    imageName = assetImage.FileName;

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

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

                    //if extension is valid
                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imageName = Guid.NewGuid() + ext;
                        assetImage.SaveAs(Server.
                                          MapPath("~/Content/images/Photos/" + imageName));
                    }
                    else
                    {
                        imageName = "noImage.png";
                    }
                }

                ownerAsset.AssetPhoto = imageName;

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

                    ownerAsset.OwnerID = currentUser;
                }

                //Automatically sets the IsActive property to true
                ownerAsset.IsActive = true;

                //Dynamically adds the current date
                ownerAsset.DateAdded = DateTime.Now;

                db.OwnerAssets.Add(ownerAsset);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OwnerID = new SelectList(db.UserDetails, "UserID", "FirstName", ownerAsset.OwnerID);
            return(View(ownerAsset));
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "ReservationID,OwnerAssetID,LocationID,ReservationDate")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                var place     = db.Locations.Where(x => x.LocationID == reservation.LocationID).FirstOrDefault();
                var dateCount = db.Reservations.Where(x => x.ReservationDate == reservation.ReservationDate && x.LocationID == reservation.LocationID).Count();

                int reserveLimit = place.ReservationLimit;
                if (reserveLimit > dateCount)
                {
                    db.Reservations.Add(reservation);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("LimitExceeded"));
                }
            }

            ViewBag.LocationID   = new SelectList(db.Locations, "LocationID", "LocationName", reservation.LocationID);
            ViewBag.OwnerAssetID = new SelectList(db.OwnerAssets, "OwnerAssetID", "AssetName", reservation.OwnerAssetID);
            return(View(reservation));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;

                    #region Dealing with custom user details
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID    = user.Id;
                    newUserDeets.FirstName = model.FirstName;
                    newUserDeets.LastName  = model.LastName;

                    ReservationProjectEntities db = new ReservationProjectEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion

                    UserManager.AddToRole(user.Id, "Client");

                    return(RedirectToAction("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }