Ejemplo n.º 1
0
        public void addCoursesToProject(List <Course> inCourses, Project p)
        {
            List <CourseProject> projectCourses = getProjectCourses(p);
            //List<Course> coursesFromProjectCourses = projectCourses.stream().map(cp -> cp.getCourse());
            List <Course> coursesFromProjectCourses = projectCourses.Select(cp => cp.Course).ToList();

            foreach (Course c in inCourses)
            {
                if (!coursesFromProjectCourses.Contains(c))
                {
                    CourseProject cp = new CourseProject();
                    cp.Course  = c;
                    cp.Project = p;
                    session.CourseProjects.Add(cp);
                    session.SaveChanges();
                }
            }
            foreach (CourseProject cp in projectCourses)
            {
                if (!inCourses.Contains(cp.Course))
                {
                    session.CourseProjects.Remove(cp);
                    session.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        private static void FillDoc(Document document, CourseProject work)
        {
            var adp     = work.AssignedCourseProjects.Count == 1 ? work.AssignedCourseProjects.First() : null;
            var cinfo   = CultureInfo.CreateSpecificCulture("ru-ru");
            var xmlData = adp == null?CourseProjectToXml(work, cinfo) : CourseProjectToXml(adp, cinfo);

            var nodes = xmlData.SelectNodes("//YearlyWorks/@year");

            foreach (XmlNode node in nodes)
            {
                const string Bookn = "year";
                var          value = node.InnerText;
                ReplaceBookmarkText(document, Bookn, value);
                break;
            }

            nodes = xmlData.SelectNodes("//YearlyWorks/item[@name]");
            foreach (XmlNode node in nodes)
            {
                var name  = node.Attributes["name"];
                var line  = node.Attributes["line"];
                var bookn = line != null?string.Format("{0}_{1}", name.Value, line.Value) : name.Value;

                var value = node.InnerText;
                ReplaceBookmarkText(document, bookn, value);
            }
        }
        public void SaveProject(CourseProjectData projectData)
        {
            if (!projectData.LecturerId.HasValue)
            {
                throw new ApplicationException("LecturerId cant be empty!");
            }

            AuthorizationHelper.ValidateLecturerAccess(Context, projectData.LecturerId.Value);

            CourseProject project;

            if (projectData.Id.HasValue)
            {
                project = Context.CourseProjects
                          .Include(x => x.CourseProjectGroups)
                          .Single(x => x.CourseProjectId == projectData.Id);
                if (Context.CourseProjects.Any(x =>
                                               x.Theme == projectData.Theme && x.SubjectId == projectData.SubjectId &&
                                               x.CourseProjectId != projectData.Id))
                {
                    throw new ApplicationException("Тема с таким названием уже есть!");
                }
            }
            else
            {
                if (Context.CourseProjects.Any(
                        x => x.Theme == projectData.Theme && x.SubjectId == projectData.SubjectId))
                {
                    throw new ApplicationException("Тема с таким названием уже есть!");
                }
                project = new CourseProject();
                Context.CourseProjects.Add(project);
            }

            var currentGroups = project.CourseProjectGroups.ToList();
            var newGroups     = projectData.SelectedGroupsIds.Select(x => new CourseProjectGroup
            {
                GroupId = x, CourseProjectId = project.CourseProjectId
            }).ToList();

            var groupsToAdd    = newGroups.Except(currentGroups, grp => grp.GroupId);
            var groupsToDelete = currentGroups.Except(newGroups, grp => grp.GroupId);

            foreach (var projectGroup in groupsToAdd)
            {
                project.CourseProjectGroups.Add(projectGroup);
            }

            foreach (var projectGroup in groupsToDelete)
            {
                Context.CourseProjectGroups.Remove(projectGroup);
            }

            project.LecturerId = projectData.LecturerId.Value;
            project.Theme      = projectData.Theme;
            project.SubjectId  = projectData.SubjectId.Value;
            Context.SaveChanges();
        }
Ejemplo n.º 4
0
 public static void CourseProjectToWord(string fileName, CourseProject work, HttpResponseBase response)
 {
     response.Clear();
     response.Charset         = "ru-ru";
     response.HeaderEncoding  = Encoding.UTF8;
     response.ContentEncoding = Encoding.UTF8;
     response.ContentType     = "application/vnd.ms-word";
     response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".doc");
     CreateDoc(work, response);
     response.Flush();
     response.End();
 }
Ejemplo n.º 5
0
        private static void CreateDoc(CourseProject work, HttpResponseBase response)
        {
            Microsoft.Office.Interop.Word.Application app = null;
            string tempfileName = null;
            object falseValue   = false;
            var    missing      = Type.Missing;
            object save         = WdSaveOptions.wdSaveChanges;
            object original     = WdOriginalFormat.wdOriginalDocumentFormat;

            try
            {
                var url = string.Format("{0}.Export.cptasklist.doc", Assembly.GetExecutingAssembly().GetName().Name);
                using (var templateStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(url))
                {
                    object tempdot = tempfileName = SaveToTemp(templateStream);

                    app = new Microsoft.Office.Interop.Word.Application();
                    var doc = app.Documents.Open(ref tempdot, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                    if (doc == null)
                    {
                        throw new ApplicationException("Unable to open the word template! Try to add Launch and Activation permissions for Word DCOM component for current IIS user (IIS_IUSRS for example). Or set Identity to Interactive User.");
                    }

                    FillDoc(doc, work);
                    doc.Save();
                    doc.Close(ref save, ref original, ref falseValue);

                    SaveToResponse(tempfileName, response);
                }
            }
            finally
            {
                if (app != null)
                {
                    object dontSave = WdSaveOptions.wdDoNotSaveChanges;
                    app.Quit(ref dontSave, ref original, ref falseValue);
                }

                if (tempfileName != null)
                {
                    try
                    {
                        File.Delete(tempfileName);
                    }
                    catch (Exception)
                    {
                        //todo: log
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static XmlDocument CourseProjectToXml(CourseProject work, CultureInfo cultureInfo)
        {
            var doc  = new XmlDocument();
            var root = doc.CreateElement("YearlyWorks");

            root.SetAttribute("DiplomProjectId", work.CourseProjectId.ToString());
            root.SetAttribute("year", string.Empty);

            var children = new List <XmlElement>();

            children.AddRange(CreateStringNodes(doc, "Theme", work.Theme, 523, 638, 5));

            var univer = doc.CreateElement("item");

            univer.SetAttribute("name", "Univer");
            univer.InnerText = "Белорусский Национальный Технический университет";
            children.Add(univer);

            var faculty = doc.CreateElement("item");

            faculty.SetAttribute("name", "Faculty");
            faculty.InnerText = "Информационных технологий и робототехники";
            children.Add(faculty);

            children.AddRange(CreateStringNodes(doc, "InputData", work.InputData, 439, 638, 13));

            children.AddRange(CreateStringNodes(doc, "RPZContent", work.RpzContent, 331, 638, 15));

            children.AddRange(CreateStringNodes(doc, "DrawMaterials", work.DrawMaterials, 403, 638, 5));

            children.AddRange(CreateStringNodes(doc, "Consultants", work.Consultants, 271, 638, 6));

            var pd = doc.CreateElement("item");

            pd.SetAttribute("name", "PublishData");
            pd.InnerText = string.Empty;
            children.Add(pd);
            children.AddRange(CreateStringNodes(doc, "Workflow", string.Empty, 638, 638, 14));

            foreach (var item in children)
            {
                root.AppendChild(item);
            }

            doc.AppendChild(root);
            return(doc);
        }
Ejemplo n.º 7
0
        public void InsertCourseProject(string courseId, string projectUuid)
        {
            CourseProject cp = new CourseProject();

            cp.CourseId    = Hasher.Base64Encode(courseId);
            cp.ProjectUuid = projectUuid;

            lock (DbContext.locker)
            {
                var rowsAffected =
                    Db.Query <CourseProject>("Select * FROM CourseProject WHERE CourseProject.CourseId = ?" +
                                             " AND CourseProject.ProjectUuid = ?", cp.CourseId, cp.ProjectUuid).Count;
                System.Diagnostics.Debug.WriteLine("Deserialize: CourseProject rowsAffected: " +
                                                   rowsAffected);
                if (rowsAffected == 0)
                {
                    // The item does not exists in the database so safe to insert
                    Db.Insert(cp);
                }
            }
        }
Ejemplo n.º 8
0
        public static string CourseProjectToDocView(CourseProject work)
        {
            var sb       = new StringBuilder();
            var cinfo    = CultureInfo.CreateSpecificCulture("ru-ru");
            var doc      = CourseProjectToXml(work, cinfo);
            var xslt     = new XslTransform();
            var url      = string.Format("{0}.Export.cptasklist.xslt", Assembly.GetExecutingAssembly().GetName().Name);
            var xsltFile = Assembly.GetExecutingAssembly().GetManifestResourceStream(url);

            xsltFile.Seek(0, SeekOrigin.Begin);
            using (var xmlr = XmlReader.Create(xsltFile))
            {
                xslt.Load(xmlr);
                using (TextWriter tw = new StringWriter(sb))
                {
                    var result = new XsltArgumentList();
                    xslt.Transform(doc, result, tw);
                }
            }

            return(sb.ToString());
        }
        private void CreateBtsProject(CourseProject courseProject, int developerId)
        {
            var lecturerId = (int)courseProject.LecturerId;
            var project    = new Project
            {
                CreatorId = lecturerId, Title = courseProject.Theme, DateOfChange = DateTime.Now
            };

            ProjectManagementService.SaveProject(project);

            ProjectManagementService.AssingRole(new ProjectUser
            {
                UserId        = lecturerId,
                ProjectId     = project.Id,
                ProjectRoleId = ProjectRole.Leader
            });

            ProjectManagementService.AssingRole(new ProjectUser
            {
                UserId        = developerId,
                ProjectId     = project.Id,
                ProjectRoleId = ProjectRole.Developer
            });
        }
Ejemplo n.º 10
0
        private async void TestInsertProject(object sender, EventArgs e)
        {
            DbContext        DbContext = DbContext.GetDbContext;
            SQLiteConnection Db        = DbContext.Db;

            System.Diagnostics.Debug.WriteLine("Before insert Project.Count: " +
                                               Db.Query <Project>("Select * from Project").Count());

            ProjectsController jc = new ProjectsController();


            string  testUuid = "colemak";
            Project project  = new Project()
            {
                uuid = testUuid,
            };

            string  companyId = "Ikea";
            Company comp      = new Company()
            {
                id = companyId
            };

            string courseId = "sverige";
            Course course   = new Course()
            {
                id = courseId
            };

            string     sgId = "dykking";
            StudyGroup sg   = new StudyGroup()
            {
                id = sgId
            };

            StudyGroupProject sgj = new StudyGroupProject()
            {
                StudyGroupId = sgId,
                ProjectUuid  = testUuid
            };

            CourseProject lj = new CourseProject()
            {
                CourseId    = courseId,
                ProjectUuid = testUuid
            };

            CompanyProject cp = new CompanyProject()
            {
                CompanyId   = companyId,
                ProjectUuid = testUuid
            };

            string  jtId = "10aarErfaringEcma6";
            JobType jt   = new JobType()
            {
                id = jtId
            };

            JobTypeProject jtp = new JobTypeProject()
            {
                ProjectUuid = testUuid,
                JobTypeId   = jtId
            };

            // try catch on tables that will not be affected by a job delete
            try
            {
                Db.Insert(comp);
            }
            catch
            {
            }
            Db.Insert(project);
            try
            {
                Db.Insert(course);
            }
            catch
            {
            }
            try
            {
                Db.Insert(sg);
            }
            catch
            {
            }
            Db.Insert(sgj);
            Db.Insert(lj);
            Db.Insert(cp);
            try
            {
                Db.Insert(jt);
            }
            catch
            {
            }
            Db.Insert(jtp);

            System.Diagnostics.Debug.WriteLine("After insert: Project.Count: " +
                                               Db.Query <Project>("Select * from Project").Count());
        }