Ejemplo n.º 1
0
        public ActionResult Register(bool Thumbnail, [Bind(Prefix = "RegisterModel")]RegisterModel registermodel, 
            HttpPostedFileBase imageLoad2)
        {
            var AccountImage = new ImageModel();

            if (imageLoad2 != null)
            {
                using (Image img = Image.FromStream(imageLoad2.InputStream))
                {

                    //--Initalise the size of the array
                    byte[] file = new byte[imageLoad2.InputStream.Length];

                    //--Create a new BinaryReader and set the InputStream for the Images InputStream to the
                    //--beginning, as we create the img using a stream.
                    BinaryReader reader = new BinaryReader(imageLoad2.InputStream);
                    imageLoad2.InputStream.Seek(0, SeekOrigin.Begin);

                    //--Load the image binary.
                    file = reader.ReadBytes((int)imageLoad2.InputStream.Length);

                    //--Create a new image to be added to the database
                    AccountImage.RecordCreatedDate = DateTime.Now;
                    AccountImage.RecordAmendedDate = DateTime.Now;
                    AccountImage.Source = file;
                    AccountImage.FileSize = imageLoad2.ContentLength;
                    AccountImage.FileName = imageLoad2.FileName;
                    AccountImage.ContentType = imageLoad2.ContentType;
                    AccountImage.Height = img.Height;
                    AccountImage.Width = img.Width;

            #if DEBUG
                   AccountImage.RecordStatus = "T";            //--Testing.
            #else
                   AccountImage.RecordStatus = " ";            //--Live.
            #endif
                   //-- Now we create the thumbnail and save it.
                   if (Thumbnail == true)
                   {
                       byte[] thumbnail = Images.CreateThumbnailToByte(imageLoad2.InputStream, 100, 100);
                       AccountImage.ThumbnailSource = thumbnail;
                       AccountImage.ThumbnailFileSize = thumbnail.Length;
                       AccountImage.ThumbnailContentType = Files.GetContentType(imageLoad2.FileName);
                       AccountImage.ThumbnailHeight = Images.FromByteHeight(thumbnail);
                       AccountImage.ThumbnailWidth = Images.FromByteWidth(thumbnail);
                   }

                }

            }

            if (ModelState.IsValid)
            {
                registermodel.UserId = Guid.NewGuid();
                // Attempt to register the user
                // MembershipCreateStatus createStatus;
                MembershipCreateStatus createStatus = MembershipService.CreateUser(registermodel.UserName, registermodel.Password, registermodel.Email, registermodel.UserId);
                // Membership.CreateUser(registermodel.UserName, registermodel.Password, registermodel.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(registermodel.UserName, false /* createPersistentCookie */);
                    //--If the registeration is an success then
                    //--save the Image away.
                    AccountImage.UniqueId = registermodel.UserId;
                    AccountImage.TableLink = registermodel.UserId;
                    db.Images.Add(AccountImage);
                    db.SaveChanges();

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            var viewModel = new RegisterViewModel
            {
                RegisterModel = registermodel,
                Thumbnail = Thumbnail,
                UniqueKey = registermodel.UserId.ToString()

            };
            // If we got this far, something failed, redisplay form
            return View(viewModel);
        }
Ejemplo n.º 2
0
        //
        // GET: /Account/Register
        public ActionResult Register()
        {
            var viewModel = new RegisterViewModel
            {
                Thumbnail = true
            };

            return View(viewModel);
        }