Beispiel #1
0
        public ActionResult Create(User user, HttpPostedFileBase uploadImage)
        {
            try
            {
                //if the user selected an image
                if (uploadImage != null)
                {
                    user.ImageType = uploadImage.ContentType;
                    user.Image     = new byte[uploadImage.ContentLength];
                    uploadImage.InputStream.Read(user.Image, 0, uploadImage.ContentLength);
                }
                else
                {
                    DefultImage.GetDefultImage(user);
                }

                db.Users.Add(user);
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #2
0
        public ActionResult Create(Award award, HttpPostedFileBase uploadImage)
        {
            try
            {
                //if the user selected an image
                if (uploadImage != null)
                {
                    award.ImageType = uploadImage.ContentType;
                    award.Image     = new byte[uploadImage.ContentLength];
                    uploadImage.InputStream.Read(award.Image, 0, uploadImage.ContentLength);
                }
                else
                {
                    //Sets the defult image
                    DefultImage.GetDefultImage(award);
                }

                db.Awards.Add(award);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the image
        /// </summary>
        /// <param name="id">Award id</param>
        /// <returns></returns>
        public FileContentResult GetImage(int id)
        {
            Award award = db.Awards.Find(id);

            //if no image sets default image
            if (award.Image == null)
            {
                DefultImage.GetDefultImage(award);
                db.Entry(award).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return(File(award.Image, award.ImageType));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the image
        /// </summary>
        /// <param name="id">User id</param>
        /// <returns></returns>
        public FileContentResult GetImage(int id)
        {
            User user = db.Users.Find(id);

            //if no image sets default image
            if (user.Image == null)
            {
                DefultImage.GetDefultImage(user);
                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }


            return(File(user.Image, user.ImageType));
        }