This class represents the table for Images and it necessary columns
Inheritance: IImageModel
Beispiel #1
0
        public ActionResult Create(ImageModel imagemodel)
        {
            if (ModelState.IsValid)
            {
                imagemodel.UniqueId = Guid.NewGuid();
                db.Images.Add(imagemodel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(imagemodel);
        }
Beispiel #2
0
 public ActionResult Edit(ImageModel imagemodel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imagemodel).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(imagemodel);
 }
Beispiel #3
0
        public ActionResult GetThumbnailImage(Guid id, bool tableLink)
        {
            ImageModel image = new ImageModel();
            byte[] imageSource = null;
            int count = 0;

            if (tableLink == true)
            {
                //--We either need to lookup the Image in the Database via the Secondary Key.....
                count = db.Images.Count(c => c.TableLink == id);

                //--Found a record.

                //--TODO: ADD THIS AS A CLASS TO Bradaz.OpenSource.MVC
                if (count > 0)
                {
                    image = db.Images.SingleOrDefault(i => i.TableLink == id);

                    //--Convert the Image data into Memory, and return it to the client.
                    imageSource = image.ThumbnailSource;
                    return File(imageSource, image.ThumbnailContentType, image.FileName);

                }

            }
            else
            {
                //--....or we can lookup using the id of the image
                count = db.Images.Count(c => c.UniqueId == id);

                //--Found a record
                if (count > 0)
                {
                    image = db.Images.SingleOrDefault(i => i.UniqueId == id);

                    //--Convert the Image data into Memory, and return it to the client.
                    imageSource = image.ThumbnailSource;
                    return File(imageSource, image.ThumbnailContentType, image.FileName);

                }
            }

            return File(new byte[0], null);
        }
        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);
        }