Example #1
0
    protected void Save_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            Press _press = new Press(this.ConnectionString);

            if (ViewState["pressId"] != null)
            {
                _press.LitePopulate(ViewState["pressId"], false);
            }

            _press.PressTitle = HttpUtility.HtmlEncode(txt_Title.Text);
            _press.ContentType = (Press.enumPressTypes)Enum.Parse(typeof(Press.enumPressTypes), dd_Format.SelectedValue);
            _press.Deacription = HttpUtility.HtmlEncode(txt_Desc.Text);
            _press.PressDate = txt_Date.Text;
            _press.Status = Convert.ToInt32(dd_Status.SelectedValue);

            String _pressImgType = "";
            if(fu_MThumb.HasFile)
            {
                _pressImgType = fu_MThumb.FileName.Split('.')[1];
                _press.PressThumbImgType = _pressImgType;
            }
            String _contThumb = "";
            String _contFile = "";
            switch (_press.ContentType)
            {
                case Press.enumPressTypes.Audio:
                    if (fu_AudThumb.HasFile)
                    {
                        _contThumb = fu_AudThumb.FileName.Split('.')[1];
                        _press.ContentThumbImgType = _contThumb;
                    }
                    if (fu_AudFile.HasFile)
                    {
                        _contFile = fu_AudFile.FileName.Split('.')[1];
                        _press.MusicType = _contFile;
                    }
                    break;
                case Press.enumPressTypes.Video:
                    if (fu_VidThumb.HasFile)
                    {
                        _contThumb = fu_VidThumb.FileName.Split('.')[1];
                        _press.ContentThumbImgType = _contThumb;
                    }
                    if (fu_VidFile.HasFile)
                    {
                        _contThumb = fu_VidFile.FileName.Split('.')[1];
                        _press.VideoType = _contThumb;
                    }
                    break;
                case Press.enumPressTypes.Text:
                    if (fu_TxtThumb.HasFile)
                    {
                        _contThumb = fu_TxtThumb.FileName.Split('.')[1];
                        _press.ContentThumbImgType = _contThumb;
                    }
                    _press.WebLink = txt_Link.Text;
                    break;
                default:
                    break;
            }

            if (_press.Save())
            {
                String _path;
                switch (_press.ContentType)
                {
                    case Press.enumPressTypes.Audio:
                        if (fu_AudThumb.HasFile)
                        {
                            _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressContentThumbPath"], _press.ID.ToString(), _press.ContentThumbImgType));
                            fu_AudThumb.SaveAs(_path);
                        }
                        if (fu_AudFile.HasFile)
                        {
                            _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressAudioPath"], _press.ID.ToString(), _press.MusicType));
                            fu_AudFile.SaveAs(_path);
                        }
                        break;
                    case Press.enumPressTypes.Video:
                        if (fu_VidThumb.HasFile)
                        {
                            _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressContentThumbPath"], _press.ID.ToString(), _press.ContentThumbImgType));
                            fu_VidThumb.SaveAs(_path);
                        }
                        if (fu_VidFile.HasFile)
                        {
                            _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressVideoPath"], _press.ID.ToString(), _press.VideoType));
                            fu_VidFile.SaveAs(_path);
                        }
                        break;
                    case Press.enumPressTypes.Text:
                        if (fu_TxtThumb.HasFile)
                        {
                            _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressContentThumbPath"], _press.ID.ToString(), _press.ContentThumbImgType));
                            fu_TxtThumb.SaveAs(_path);
                        }
                        break;
                    default:
                        break;
                }
                if (fu_MThumb.HasFile)
                {
                    _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["PressThumbPath"], _press.ID.ToString(), _press.PressThumbImgType));
                    fu_MThumb.SaveAs(_path);

                }

                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('Record has been updated successfully.');self.location = 'PressList.aspx';", true);
            }
            else
            {
                lbl_Error.Text = "An unexpected error has occurred. Please try again.";
                lbl_Error.Visible = true;
            }
        }
    }