public ActionResult Create([Bind(Include = "ActorId,ActorFirstName,ActorLastName,Address,City,State,ZipCode,PhoneNumber,AgencyID,ActorPhoto,SpecialNotes,DateAdded,IsActive")] Actor actor, HttpPostedFileBase actorheadshot)
        {
            ViewBag.AgencyID = new SelectList(db.UserDetails, "UserID", "FirstName", actor.AgencyID);
            if (ModelState.IsValid)
            {
                #region Image Upload
                string imgName = "~/Content/actorheadshots/nouserimg.png";

                if (actorheadshot != null)
                {
                    /**/
                    imgName = actorheadshot.FileName;

                    /*1*/
                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

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

                    /*3*/
                    if (goodExts.Contains(ext.ToLower()) && (actorheadshot.ContentLength <= 4193404))
                    {
                        /*4*/
                        imgName = Guid.NewGuid() + ext.ToLower();

                        //actorheadshot.SaveAs(Server.MapPath("~/Content/actorheadshots/" + imgName));

                        #region Resize Image
                        /*5*/
                        string savePath = Server.MapPath("~/Content/actorheadshots/");
                        //taking the contents of this file and creating a stream of bytes, http file base type is becoming a stream of bytes into a type of image. this conversion has to take place for us to be able to resize the image
                        /*6*/
                        Image convertedImage = Image.FromStream(actorheadshot.InputStream);
                        int   maxImageSize   = 500;
                        int   maxThumbSize   = 100;
                        //if you allowed image uploads for magazine and books - you would need to repeat that code - that's why the image service code is in an imageservice area
                        /*7*/
                        UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize);
                        //saves image onto server - but doesn't update db need to make sure to update what is stored in the db
                        #endregion
                    }
                    else
                    {
                        imgName = "nouserimg.png";
                    }
                }
                actor.ActorPhoto = imgName;
                #endregion

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

            return(View(userDetail));
        }
        public ActionResult Create([Bind(Include = "AuditionID,ActorId,LocationId,AuditionDate")] Reservation reservation)
        {
            if (User.IsInRole("Agency"))
            {
                string currentUserID = User.Identity.GetUserId();
                ViewBag.ActorId    = new SelectList(db.Actors.Where(a => a.AgencyID == currentUserID), "ActorId", "ActorFullName", reservation.ActorId);
                ViewBag.LocationId = new SelectList(db.AuditionLocations, "LocationID", "FullAuditionLocation", reservation.LocationId);
            }
            if (User.IsInRole("Admin"))
            {
                ViewBag.ActorId    = new SelectList(db.Actors, "ActorId", "ActorFullName", reservation.ActorId);
                ViewBag.LocationId = new SelectList(db.AuditionLocations, "LocationID", "FullAuditionLocation", reservation.LocationId);
            }
            if (ModelState.IsValid)
            {
                var auditionlimit = db.AuditionLocations.Where(x => x.LocationID == reservation.LocationId).Select(x => x.AuditionLimit).FirstOrDefault();

                var nbrOfReservations = db.Reservations.Where(x => x.LocationId == reservation.LocationId).Count();

                var nbrOfOpenSpots = auditionlimit - nbrOfReservations;

                if (nbrOfReservations < auditionlimit || User.IsInRole("Admin"))
                {
                    db.Reservations.Add(reservation);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                if (nbrOfReservations > auditionlimit && User.IsInRole("Agency"))
                {
                    ViewBag.Message = $"Sorry, there are no more auditions available at that location.";
                    return(View("Create"));
                }
                //assign reservation date
            }

            //ViewBag.ActorId = new SelectList(db.Actors, "ActorId", "ActorFirstName", reservation.ActorId);
            //ViewBag.LocationId = new SelectList(db.AuditionLocations, "LocationID", "LocationName", reservation.LocationId);
            return(View(reservation));
        }
Esempio n. 4
0
        public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase agencyphoto)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    string imgName = "~/Content/actorheadshots/nouserimg.png";

                    if (agencyphoto != null)
                    {
                        imgName = agencyphoto.FileName;
                        string   ext      = imgName.Substring(imgName.LastIndexOf('.'));
                        string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" };
                        if (goodExts.Contains(ext.ToLower()) && (agencyphoto.ContentLength <= 4193404))

                        {
                            imgName = Guid.NewGuid() + ext.ToLower();
                            string savePath       = Server.MapPath("~/Content/agencylogo/");
                            Image  convertedImage = Image.FromStream(agencyphoto.InputStream);
                            int    maxImageSize   = 500;
                            int    maxThumbSize   = 100;
                            UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize);
                        }
                        else
                        {
                            imgName = "nouserimg.png";
                        }
                    }

                    // Added Custom User Details
                    #region Custom User Details

                    UserDetail newUserDetails = new UserDetail();
                    newUserDetails.UserID      = user.Id;
                    newUserDetails.FirstName   = model.FirstName;
                    newUserDetails.LastName    = model.LastName;
                    newUserDetails.AgencyName  = model.AgencyName;
                    newUserDetails.UserPhoto   = model.UserPhoto;
                    newUserDetails.UserNotes   = model.UserNotes;
                    newUserDetails.DateFounded = model.DateFounded;
                    newUserDetails.UserPhoto   = imgName;

                    AuditionsEntities db = new AuditionsEntities();
                    db.UserDetails.Add(newUserDetails);
                    db.SaveChanges();
                    UserManager.AddToRole(user.Id, "Agency");

                    #endregion

                    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;
                    return(View("RegisterSuccess"));
                }
                AddErrors(result);
            }

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