Ejemplo n.º 1
0
        public ActionResult UserForm(User user)
        {
            string webpath = null;

            if (Request.Files.Count > 0 && !string.IsNullOrEmpty(Request.Files[0].FileName))
            {
                HttpPostedFileBase file  = Request.Files[0];
                string             fname = file.FileName.Substring(file.FileName.LastIndexOf('.'));
                webpath = SharedSupport.SharedImagesPath + user.Username + fname;
                string fileSystemPath = SharedSupport.GetImageFolderPath() + user.Username + fname;
                file.SaveAs(fileSystemPath);
            }
            else if (!string.IsNullOrEmpty(user.SocialProfilePicture))
            {
                webpath = user.SocialProfilePicture;
            }

            TempData["user"] = SharedSupport.FilterUser(user, webpath);
            return(RedirectToAction("Chat"));
        }
Ejemplo n.º 2
0
        //Depreciated Method
        private string UserForm(User data)
        {
            string webpath = string.Empty;

            if (!string.IsNullOrEmpty(data.SocialProfilePicture))
            {
                byte[] binaryData = Convert.FromBase64String(data.SocialProfilePicture
                                                             .Replace("data:image/jpg;base64,", "")
                                                             .Replace("data:image/jpeg;base64,", "")
                                                             .Replace("data:image/gif;base64,", "")
                                                             .Replace("data:image/png;base64,", "")
                                                             .Replace("data:image/bmp;base64,", "")
                                                             );

                string slashSubStr   = data.SocialProfilePicture.Substring(data.SocialProfilePicture.IndexOf('/') + 1);
                string fileExtension = slashSubStr.Substring(0, slashSubStr.IndexOf(';'));
                webpath = SharedSupport.SharedImagesPath + data.Username + "." + fileExtension;
                string fileSystemPath = SharedSupport.GetImageFolderPath() + data.Username + "." + fileExtension;
                Stream sampleStream   = new MemoryStream(binaryData);
                using (FileStream writerStream = File.Open(fileSystemPath, FileMode.Append))
                {
                    Byte[] byteData = new Byte[binaryData.Count()];
                    for (byte i = 0; i < 100; i++)
                    {
                        Int32 readeDataLength = sampleStream.Read(byteData, 0, byteData.Count());
                        writerStream.Write(byteData, 0, readeDataLength);
                    }
                }
            }

            ChatUser filteredUser = SharedSupport.FilterUser(data, webpath);

            if (DBSupport.GetUser(filteredUser) != null)
            {
                return(usernameExists.Replace("username", data.Username));
            }

            return(JsonConvert.SerializeObject(filteredUser));
        }