Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request["id"];

        if (null != id)
        {
            IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext();
            PortfolioService    portfolioService = ctx["PortfolioService"] as PortfolioService;
            Attachment          attachment       = portfolioService.GetAttachment(Convert.ToInt32(id));
            if (null != attachment)
            {
                Response.Clear();
                string ext = Path.GetExtension(attachment.Name).Replace(".", "");
                try
                {
                    string mimeType = ApacheMimeTypes.MimeTypes[ext];
                    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", attachment.Name));
                    if (null != mimeType)
                    {
                        Response.ContentType = mimeType;
                    }
                }
                catch
                {
                    Response.ContentType = "text/plain";
                }
                Response.BinaryWrite(attachment.Data);
                Response.End();
            }
        }
    }
Exemple #2
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        FileUpload fileUpload            = modalDialog.FindControl("txtFileUpload") as FileUpload;
        Label      lblAttachmentCategory = modalDialog.FindControl("lblAttachmentCategory") as Label;
        Label      lblUploadInstructions = modalDialog.FindControl("lblUploadInstructions") as Label;
        Label      lblAttachmentName     = modalDialog.FindControl("lblAttachmentName") as Label;
        Label      lblAttachmentId       = modalDialog.FindControl("lblAttachmentId") as Label;

        AttachmentCategory category = (AttachmentCategory)Enum.Parse(typeof(AttachmentCategory), lblAttachmentCategory.Text);

        this.Validate("Upload");
        if (this.IsValid && null != fileUpload && fileUpload.HasFile && FileUtils.IsValidFile(fileUpload.FileName))
        {
            int        id         = Convert.ToInt32(lblAttachmentId.Text);
            Attachment attachment = null;
            if (id > 0)
            {
                attachment = PortfolioService.GetAttachment(id);
            }
            if (id <= 0 || null == attachment)
            {
                attachment = new Attachment();
                Portfolio portfolio = GetPortfolio();
                if (category == AttachmentCategory.Image || category == AttachmentCategory.Document || category == AttachmentCategory.Media)
                {
                    attachment.Type        = AttachmentType.Portfolio;
                    attachment.ObjectRowId = portfolio.Id;
                }
                else
                {
                    attachment.Type        = AttachmentType.Portfolio;
                    attachment.ObjectRowId = GetPortfolio().Id;
                }
                attachment.Category = category;
            }

            attachment.Description = lblAttachmentName.Text;
            attachment.Name        = fileUpload.FileName;

            using (BinaryReader reader = new BinaryReader(fileUpload.FileContent))
            {
                byte[] buf = reader.ReadBytes((int)fileUpload.FileContent.Length);
                reader.Close();
                fileUpload.FileContent.Close();
                if (FileUtils.IsImageFile(attachment.Name))
                {
                    attachment.Data = buf;// ImageUtils.NormalizeImage(buf);
                }
                else
                {
                    attachment.Data = buf;
                }
            }
            PortfolioService.SaveAttachment(attachment);
            modalDialog.HideModal();
            LoadPortfolio();
        }
    }
Exemple #3
0
 protected void btnDelAttachment_Command(Object sender, CommandEventArgs e)
 {
     if (null != e.CommandArgument)
     {
         int        id         = Convert.ToInt32(e.CommandArgument);
         Attachment attachment = PortfolioService.GetAttachment(id);
         PortfolioService.DeleteAttachment(attachment);
         LoadPortfolio();
     }
 }
Exemple #4
0
 protected void gvPhotos_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Download"))
     {
         int        id         = Convert.ToInt32(e.CommandArgument);
         Attachment attachment = PortfolioService.GetAttachment(id);
         Response.Clear();
         Response.ContentType = "application/octet-stream";
         Response.AddHeader("Content-Disposition", "attachment; filename=" + attachment.Name);
         Response.AddHeader("Content-Length", attachment.Data.Length.ToString());
         Response.BinaryWrite(attachment.Data);
         Response.End();
     }
 }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string       report = Request["report"];
            MemoryStream stream = null;

            if ("profile".Equals(report))
            {
                string id           = Request["id"];
                String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
                UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/"));
                Portfolio portfolio = PortfolioService.GetPortfolio(Convert.ToInt32(id));
                if (CurrentUser.Role == RoleType.Nominee)
                {
                    if (portfolio.User.Id != CurrentUser.Id)
                    {
                        portfolio = PortfolioService.GetPortfolioByUser(CurrentUser);
                    }
                }
                else if (CurrentUser.Role == RoleType.Coordinator)
                {
                    School school = RegionService.GetSchoolByUser(CurrentUser);
                    if (portfolio.School.Id != school.Id)
                    {
                        portfolio = null;
                    }
                }
                if (null != portfolio)
                {
                    IList <Attachment> list = PortfolioService.GetAttachments(AttachmentCategory.Portfolio, AttachmentType.FinalPortfolio, portfolio.Id);
                    if (list.Count > 0)
                    {
                        stream = new MemoryStream();
                        Attachment attachment = PortfolioService.GetAttachment(list[0].Id);
                        stream.Write(attachment.Data, 0, attachment.Data.Length);
                    }
                    else
                    {
                        stream = ReportService.CreatePortfolioReport(portfolio, UrlDirectory);
                    }
                }
            }
            if ("principal".Equals(report))
            {
                if (CurrentUser.Role == RoleType.Principal || CurrentUser.Role == RoleType.Coordinator)
                {
                    string    id        = Request["id"];
                    Portfolio portfolio = PortfolioService.GetPortfolio(Convert.ToInt32(id));
                    stream = ReportService.CreatePrincipalReport(portfolio);
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            if ("nominees".Equals(report))
            {
                if (CurrentUser.Role != RoleType.Nominee)
                {
                    string id     = Request["id"];
                    School school = RegionService.GetSchool(Convert.ToInt32(id));
                    stream = ReportService.NomineeReport(school);
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            Response.Clear();
            Response.ContentType = "application/pdf";

            Response.OutputStream.Write(stream.GetBuffer(), 0, (int)stream.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
        }
    }
Exemple #6
0
    private void LoadPortfolio()
    {
        Portfolio portfolio = GetPortfolio();

        MissingItems = PortfolioService.GetMissingItems(portfolio);
        lblName.Text = CurrentUser.FullName;

        IList <Attachment> attachments = PortfolioService.GetAttachments(AttachmentType.Portfolio, portfolio.Id);
        var letters = from a in attachments
                      where a.Category == AttachmentCategory.LetterOfRecomendation
                      select a;

        lnkLetter.Visible    = !letters.Any();
        lvLetters.DataSource = letters;
        lvLetters.DataBind();

        var docs = from a in attachments
                   where a.Category == AttachmentCategory.CategoryDescription
                   select a;

        lnkCatDocsUpload.Visible = docs.Count() < 2;

        lvCatDocs.DataSource = docs;
        lvCatDocs.DataBind();

        docs = from a in attachments
               where a.Category == AttachmentCategory.LeadershipDescription
               select a;

        lnkLeadership.Visible = docs.Count() < 2;

        lvLeadership.DataSource = docs;
        lvLeadership.DataBind();

        docs = from a in attachments
               where a.Category == AttachmentCategory.CitizenshipDescription
               select a;

        lnkCitizenship.Visible   = docs.Count() < 2;
        lvCitizenship.DataSource = docs;
        lvCitizenship.DataBind();

        Attachment image = attachments.FirstOrDefault(x => x.Category == AttachmentCategory.PersonalPhoto);

        if (null != image && AccordianControl.SelectedIndex == 0)
        {
            picNominee.Visible  = true;
            picNominee.ImageUrl = "~/ImageHandler.ashx?id=" + image.Id;
        }
        else
        {
            picNominee.Visible  = false;
            picNominee.ImageUrl = "";
        }

        lvTranscript.DataSource = attachments.Where(x => x.Category == AttachmentCategory.Transcript);
        lvTranscript.DataBind();

        lblSchoolEdit.Text      = portfolio.School.Name;
        lblCategoryEdit.Text    = portfolio.Category.Name;
        txtName.Text            = CurrentUser.FullName;
        txtParents.Text         = portfolio.Parents;
        txtAddress.Text         = portfolio.Address;
        txtCity.Text            = portfolio.City;
        ddlState.SelectedValue  = portfolio.State;
        txtZip.Text             = portfolio.Zip;
        txtPhone.Text           = portfolio.User.PhoneNumber;
        ddlGender.SelectedValue = portfolio.Sex.ToString();
        LoadPortfolio(portfolio);


        IEnumerable <PortfolioItem> catItems = portfolio.Items.Where(x => x.Type == ItemType.Category);

        foreach (PortfolioItem item in catItems)
        {
            TextBox tb = AccordionPane4.FindControl("txtCategory" + item.ItemIndex.ToString()) as TextBox;
            if (tb != null)
            {
                tb.Text = item.Text;
            }
        }

        PortfolioItem i = portfolio.Items.FirstOrDefault(x => x.Type == ItemType.CategoryDescription);

        if (i != null)
        {
            txtCategoryDescription.Text = i.Text;
        }

        IEnumerable <PortfolioItem> leaderItems = portfolio.Items.Where(x => x.Type == ItemType.Leadership);

        foreach (PortfolioItem item in leaderItems)
        {
            TextBox tb = AccordionPane6.FindControl("txtLeadership" + item.ItemIndex.ToString()) as TextBox;
            if (tb != null)
            {
                tb.Text = item.Text;
            }
        }
        i = portfolio.Items.FirstOrDefault(x => x.Type == ItemType.LeadershipDescription);
        if (i != null)
        {
            txtLeadershipDescription.Text = i.Text;
        }

        IEnumerable <PortfolioItem> citizenItems = portfolio.Items.Where(x => x.Type == ItemType.Citizenship);

        foreach (PortfolioItem item in citizenItems)
        {
            TextBox tb = AccordionPane8.FindControl("txtCitizenship" + item.ItemIndex.ToString()) as TextBox;
            if (tb != null)
            {
                tb.Text = item.Text;
            }
        }

        i = portfolio.Items.FirstOrDefault(x => x.Type == ItemType.CitizenshipDescription);
        if (i != null)
        {
            txtCitizenshipDescription.Text = i.Text;
        }

        i = portfolio.Items.FirstOrDefault(x => x.Type == ItemType.LifeEnrichment);
        if (i != null)
        {
            txtLifeEnrichment.Text = i.Text;
        }

        i = portfolio.Items.FirstOrDefault(x => x.Type == ItemType.UniqueQualities);
        if (i != null)
        {
            txtUniqueQualities.Text = i.Text;
        }

        if (null != portfolio)
        {
            IList <Attachment> list = PortfolioService.GetAttachments(AttachmentCategory.Document, AttachmentType.Portfolio, portfolio.Id);
            lvAttachDocs.DataSource = list;
            lvAttachDocs.DataBind();
            btnUploadDocs.Visible = (list.Count == 0);
            list               = PortfolioService.GetAttachments(AttachmentCategory.Image, AttachmentType.Portfolio, portfolio.Id);
            btnImage.Visible   = (list.Count == 0);
            lvImage.DataSource = list;
            lvImage.DataBind();
            list               = PortfolioService.GetAttachments(AttachmentCategory.Media, AttachmentType.Portfolio, portfolio.Id);
            btnMedia.Visible   = (list.Count == 0);
            lvMedia.DataSource = list;
            lvMedia.DataBind();
            list = PortfolioService.GetAttachments(AttachmentCategory.Url, AttachmentType.Portfolio, portfolio.Id);
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            var attachment = list.FirstOrDefault(x => "Document".Equals(x.Name));
            if (null != attachment)
            {
                txtDocDescription.Text = attachment.Description;
                attachment             = PortfolioService.GetAttachment(attachment.Id);
                txtDocLink.Text        = encoding.GetString(attachment.Data);
            }
            attachment = list.FirstOrDefault(x => "Image".Equals(x.Name));
            if (null != attachment)
            {
                txtImageDescription.Text = attachment.Description;
                attachment        = PortfolioService.GetAttachment(attachment.Id);
                txtImageLink.Text = encoding.GetString(attachment.Data);
            }
            attachment = list.FirstOrDefault(x => "Media".Equals(x.Name));
            if (null != attachment)
            {
                txtMediaDescription.Text = attachment.Description;
                attachment        = PortfolioService.GetAttachment(attachment.Id);
                txtMediaLink.Text = encoding.GetString(attachment.Data);
            }
        }
        else
        {
            PortfolioService.SavePortfolio(portfolio);
        }
        if (portfolio.Status != Status.Incomplete)
        {
            DisableButtons(Page.Controls);
        }
    }