private void GetIDAndActivate()
    {
        try
        {
            _ID = Request.QueryString["ID"];
            if (!string.IsNullOrEmpty(_ID))
            {
                tblActivationRequest actReq = (from req in GoProGoDC.ProfileDC.tblActivationRequests
                                               where req.ActivationID.ToString() == _ID && !req.IsFulfilled
                                               select req).SingleOrDefault <tblActivationRequest>();

                if (actReq != null && actReq.IsFulfilled == false)
                {
                    MembershipUser user = Membership.GetUser(actReq.tblProfile.UserID);
                    if (!user.IsApproved)
                    {
                        //Approved user account first
                        user.IsApproved = true;
                        Membership.UpdateUser(user);

                        //Following line will submit changes in DB for creating file
                        tblFileInformation fileInfo = VirtualFS.CreateFolder(user.UserName, actReq.tblProfile.ID, null);
                        actReq.tblProfile.RootFolderID = fileInfo.ID;
                        actReq.IsFulfilled             = true;
                        //Following line will submit changes to update Profile

                        GoProGoDC.ProfileDC.SubmitChanges(ConflictMode.FailOnFirstConflict);
                        pnlSuccess.Visible = true;
                    }
                }
                else
                {
                    pnlFailure.Visible = true;
                }
            }
            else
            {
                throw new Exception("Invalid request.");
            }
        }
        catch (Exception ex)
        {
            ((PublicMaster)this.Master).ShowMessage(ex.Message, MessageType.Error);
        }
    }
Ejemplo n.º 2
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string tempFileName         = string.Empty;
        string tempFileNameAndPath  = string.Empty;
        string currentFileStorage   = ConfigurationManager.AppSettings["CurrentFileStorage"].ToString();
        string tempFileStorage      = ConfigurationManager.AppSettings["TempFileStorage"].ToString();
        string normalAspectSize     = ConfigurationManager.AppSettings["NormalPicAspect"].ToString();
        string smallAspectSize      = ConfigurationManager.AppSettings["SmallPicAspect"].ToString();
        string profilePictureFolder = ConfigurationManager.AppSettings["ProfilePictureFolder"].ToString();

        System.Drawing.Image normalImage = null;
        System.Drawing.Image smallImage  = null;

        string normalFullName = string.Empty;
        string smallFullName  = string.Empty;

        //System Folder
        tblFileInformation sysFolder;
        //Temporary System Folder
        tblFileInformation tempSysFolder;

        long normalImageLength;
        long smallImageLength;

        if (FileUpload1.HasFile)
        {
            try
            {
                using (Impersonator imp = new Impersonator())
                {
                    tempFileName        = Guid.NewGuid().ToString() + "_" + DateTime.Now.ToLongDateString();
                    tempFileNameAndPath = tempFileStorage + tempFileName;
                    FileUpload1.SaveAs(tempFileNameAndPath);

                    normalImage = Common.ResizePic(tempFileNameAndPath, ImageFormat.Jpeg, int.Parse(normalAspectSize));
                    smallImage  = Common.ResizePic(tempFileNameAndPath, ImageFormat.Jpeg, int.Parse(smallAspectSize));

                    smallFullName  = currentFileStorage + Guid.NewGuid().ToString() + "_small.jpg";
                    normalFullName = currentFileStorage + Guid.NewGuid().ToString() + "_normal.jpg";

                    normalImage.Save(normalFullName);
                    smallImage.Save(smallFullName);

                    normalImageLength = new FileInfo(normalFullName).Length;
                    smallImageLength  = new FileInfo(smallFullName).Length;

                    //Virtual File System
                    //GoProGo.FileSystem.VirtualFileSystem fileSys = new GoProGo.FileSystem.VirtualFileSystem();

                    sysFolder = VirtualFS.FindFolderByName(this.MembershipUser.UserName, ObjProfile.ID);
                    if (sysFolder == null)
                    {
                        sysFolder = VirtualFS.CreateFolder(this.MembershipUser.UserName, ObjProfile.ID, null);
                    }

                    //Check first if folder exist, if it does then don't create it
                    tempSysFolder = VirtualFS.FindFolderByName(profilePictureFolder, ObjProfile.ID);
                    if (tempSysFolder == null)
                    {
                        sysFolder = VirtualFS.CreateFolder(profilePictureFolder, ObjProfile.ID, sysFolder.ID);
                    }
                    else
                    {
                        sysFolder = tempSysFolder;
                    }

                    //To be on safe side, clean files in folder if already existing
                    List <tblFileInformation> files = VirtualFS.GetAllFilesInFolder(sysFolder, ObjProfile.ID);
                    foreach (tblFileInformation item in files)
                    {
                        File.Delete(item.FullPath);
                    }
                    //Delete files from database
                    VirtualFS.DeleteFiles(files);

                    VirtualFS.CreateFile(sysFolder.ProfileID, normalFullName, normalImageLength, GoProGo.VirtualFileSystem.AccessTypes.Public, GoProGo.VirtualFileSystem.FileTypes.File, GoProGo.VirtualFileSystem.FileExtensions.jpg, sysFolder);
                    VirtualFS.CreateFile(sysFolder.ProfileID, smallFullName, smallImageLength, GoProGo.VirtualFileSystem.AccessTypes.Public, GoProGo.VirtualFileSystem.FileTypes.File, GoProGo.VirtualFileSystem.FileExtensions.jpg, sysFolder);

                    ObjProfile.NormalProfilePicture = normalFullName;
                    ObjProfile.SmallProfilePicture  = smallFullName;
                    GoProGo.Data.GoProGoDC.ProfileDC.SubmitChanges();

                    //Finally delete temporary file
                    File.Delete(tempFileNameAndPath);

                    ShowPicture(normalFullName);

                    if (OnPictureUploaded != null)
                    {
                        OnPictureUploaded(this, null);
                    }
                }
            }
            catch (Exception ex)
            {
                Image1.Visible = false;
                ThrowError(this, new ControlErrorArgs()
                {
                    InnerException = ex, Message = ex.Message, Severity = 3
                });
            }
        }