Beispiel #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var user = Page.User as CustomPrincipal;

            if (user != null)
            {
                var file = new Academic.DbEntities.ActivityAndResource.FileResource()
                {
                    Id   = FileResourceId,
                    Name = txtName.Text
                    ,
                    Description = CKEditor1.Text
                    ,
                    //Display = (byte)ddlDisplay.SelectedIndex
                    //,
                    ShowSize = chkShowSize.Checked
                    ,
                    ShowType = chkShowType.Checked
                    ,
                    ShowUploadModifiedDate = chkShowUploadModifiedDate.Checked
                    ,
                    ShowDescriptionOnCoursePage = chkDisplayDescription.Checked
                    ,
                };
                if (ddlDisplay.SelectedIndex == 0)
                {
                    file.Display = 2;
                }
                else
                {
                    file.Display = 4;
                }
                //files
                var list  = new List <Academic.DbEntities.Subjects.SubjectFile>();
                var files = FilesDisplay1.GetFiles();
                if (files != null)
                {
                    foreach (var f in files)
                    {
                        var fileName = Path.GetFileName(f.FilePath);
                        var fi       = new Academic.DbEntities.Subjects.SubjectFile()
                        {
                            Id        = f.Id,
                            CreatedBy = user.Id
                            ,
                            CreatedDate = DateTime.Now
                            ,
                            DisplayName = f.FileDisplayName                           //Path.GetFileName(imageFile.FileName)
                            ,
                            FileDirectory = DbHelper.StaticValues.CourseFilesLocation //StaticValue.UserImageDirectory
                            ,
                            FileName = fileName
                                       //Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                            ,
                            FileSizeInBytes = f.FileSizeInBytes //imageFile.ContentLength
                            ,
                            FileType = f.FileType               //imageFile.ContentType
                            ,
                            IconPath = f.IconPath
                            ,
                            SubjectId = SubjectId
                            ,
                            Void = !f.Visible
                        };
                        list.Add(fi);
                    }
                }
                var restriction = RestrictionUC.GetRestriction();

                if (!RestrictionUC.IsValid)
                {
                    return;
                }
                using (var helper = new DbHelper.ActAndRes())
                {
                    var saved = helper.AddOrUpdateFileResource(file, list, SectionId, restriction);
                    if (saved != null)
                    {
                        Response.Redirect(DbHelper.StaticValues.WebPagePath.CourseDetailPage(SubjectId, SectionId));
                        //Response.Redirect("~/Views/Course/Section/Master/CourseSectionListing.aspx?SubId=" + SubjectId + "&edit=1#section_" + SectionId);
                    }
                }
            }
        }