Example #1
0
        public ActionResult CreateUser([Bind(Exclude = "Photo")] User user)
        {
            try
            {
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["UserPhoto"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }

                //Here we pass the byte array to user context to store in db
                user.Photo = imageData;

                ObjectParameter statusCode    = new ObjectParameter("StatusCode", typeof(int));
                ObjectParameter statusMessage = new ObjectParameter("StatusMessage", typeof(string));

                db.AddUpdateUser(0, user.FullName, user.PhoneNumber, user.Address,
                                 user.Email, user.Username, user.Password,
                                 user.Photo, user.JobTitle,
                                 null, null, null, null, null, statusCode, statusMessage);
                TempData["AlertMessage"] = "User added Successfully";
                return(RedirectToAction("UsersList"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }