Пример #1
0
        public LessonSections(LessonTag tag, List <Label> labels, List <Label> buttons)
        {
            InitializeComponent();

            switch (tag.courseId)
            {
            case 1:
                this.lbCourse.Text = "Touch Typing Course";
                break;

            case 2:
                this.lbCourse.Text = "Most Common Words Course";
                break;

            case 3:
                this.lbCourse.Text = "Speed Building Course";
                break;

            case 4:
                this.lbCourse.Text = "Number, Special Marks and 10-Key Pad Courses";
                break;

            default:
                this.lbCourse.Text = "";
                break;
            }

            foreach (Label lb in buttons)
            {
                lb.Click += new EventHandler(ShowLessonSections);
            }
            this.pnLessonList.Controls.AddRange(buttons.ToArray());

            this.lbLessonName.Text += tag.lessonNumber + " : " + BUS_UserControls.ReadNameFromTag(tag);

            foreach (Label lb in labels)
            {
                if (lb.Tag != null)
                {
                    lb.Click += new EventHandler(ShowTypingForm);
                }

                this.pnSections.Controls.Add(lb);
            }

            this.Dock = DockStyle.Fill;
        }
Пример #2
0
        public static void ShowLessonSections(object sender, EventArgs e)
        {
            Form form = (Form)(((Control)sender).TopLevelControl);   //Tìm form ngoài cùng của sender

            BUS_UserControls.DisposeControls <LessonSections>(form); //Xoá các LessonSections không còn dùng

            LessonTag lessonTag = (LessonTag)(((Label)sender).Tag);  //Ép kiểu thuộc tính Tag sang LessonTag


            List <Label> buttons = new List <Label>();
            List <Label> labels  = BUS_UserControls.SearchLessonSections(lessonTag, sender, ref buttons);

            LessonSections lessonSections = new LessonSections(lessonTag, labels, buttons); //Tạo LessonSection mới

            form.Controls.Add(lessonSections);
            lessonSections.BringToFront();
        }
Пример #3
0
        public void Handle(LessonMementoPropagatedEvent @event)
        {
            using (var db = new DisciturContext())
            {
                int itemId = _identityMapper.GetModelId <Lesson>(@event.Memento.Id);
                if (itemId.Equals(0))
                {
                    int  userId = _identityMapper.GetModelId <User>(@event.Memento.AuthorId);
                    User _user  = db.Users.Find(userId);

                    Lesson lesson = new Lesson();
                    lesson.Title        = @event.Memento.Title;
                    lesson.Discipline   = @event.Memento.Discipline;
                    lesson.School       = @event.Memento.School;
                    lesson.Classroom    = @event.Memento.Classroom;
                    lesson.Author       = _user;
                    lesson.UserId       = _user.UserId;
                    lesson.Content      = @event.Memento.Content;
                    lesson.Conclusion   = @event.Memento.Conclusion;
                    lesson.PublishDate  = @event.Memento.CreationDate;
                    lesson.CreationDate = @event.Memento.CreationDate;
                    UpdateLessonArchFields(lesson, _user.UserName, @event.Memento.CreationDate, @event.Memento.Version);
                    //lesson.LastModifDate = @event.CreationDate;
                    //lesson.LastModifUser = _user.UserName;
                    //lesson.Vers = 1;
                    lesson.RecordState = Constants.RECORD_STATE_ACTIVE;

                    // Create FeedBacks Collection
                    @event.Memento.FeedBacks.ToList()
                    .ForEach(feedback => {
                        LessonFeedback fb = new LessonFeedback()
                        {
                            Feedback           = feedback.Feedback,
                            Nature             = feedback.Nature,
                            LessonFeedbackGuid = feedback.Id
                        };
                        lesson.FeedBacks.Add(fb);
                    });

                    // Create Tags Collection
                    @event.Memento.Tags.ToList()
                    .ForEach(tag =>
                    {
                        LessonTag t = new LessonTag()
                        {
                            LessonTagName = tag.LessonTagName
                        };
                        lesson.Tags.Add(t);
                    });

                    db.Lessons.Add(lesson);
                    db.SaveChanges();
                    //Ids mapping
                    _identityMapper.Map <Lesson>(lesson.LessonId, @event.Memento.Id);
                    if (lesson.FeedBacks.Count > 0)
                    {
                        lesson.FeedBacks.ToList()
                        .ForEach(feedback => _identityMapper.Map <LessonFeedback>(feedback.LessonFeedbackId, feedback.LessonFeedbackGuid));
                    }

                    // Create Ratings Collection
                    List <int> ratingsList = new List <int>();
                    @event.Memento.Ratings.ToList()
                    .ForEach(r =>
                    {
                        int authorId = _identityMapper.GetModelId <User>(r.UserId);
                        User author  = db.Users.Find(userId);
                        ratingsList.Add(r.Rating);
                        LessonRating rating = new LessonRating()
                        {
                            LessonId      = lesson.LessonId,
                            UserId        = authorId,
                            Author        = author,
                            Rating        = r.Rating,
                            Content       = r.Content ?? string.Empty,
                            CreationDate  = r.CreationDate,
                            LastModifDate = r.LastModifDate,
                            LastModifUser = r.LastModifUser,
                            Vers          = r.Vers,
                            RecordState   = Constants.RECORD_STATE_ACTIVE
                        };
                        // Add new Lesson's Rating
                        db.LessonRatings.Add(rating);
                        db.SaveChanges();
                        _identityMapper.Map <LessonRating>(rating.Id, r.Id);
                    });

                    lesson.Rate = ratingsList.Count > 0 ? Math.Max((int)Math.Round(ratingsList.Average()), 1) : 0;

                    // Create Comments Collection
                    @event.Memento.Comments.ToList()
                    .ForEach(c =>
                    {
                        // get read-model Ids (ID-maps)
                        int _userId  = _identityMapper.GetModelId <User>(c.AuthorId);
                        int?parentId = c.ParentId == null ? null : (int?)_identityMapper.GetModelId <LessonComment>(c.ParentId.Value);
                        // get involved read-model entities
                        User author = db.Users.Find(userId);

                        // Create new Read-Model Lesson's Comment
                        LessonComment comment = new LessonComment()
                        {
                            LessonId      = lesson.LessonId,
                            Content       = c.Content,
                            CreationDate  = c.CreationDate,
                            Date          = c.Date,
                            LastModifDate = c.Date,
                            Level         = c.Level,
                            ParentId      = parentId,
                            Vers          = c.Vers,
                            RecordState   = Constants.RECORD_STATE_ACTIVE,
                            UserId        = _userId,
                            Author        = author,
                            LastModifUser = author.UserName
                        };
                        db.LessonComments.Add(comment);
                        db.SaveChanges();
                        // Map new IDs
                        // NOTE: Comment is NOT and AR, but it's mapped with it's own Id-map for compatibility with existant read-model
                        _identityMapper.Map <LessonComment>(comment.Id, c.Id);
                    });

                    // Persist changes
                    db.Entry(lesson).State = EntityState.Modified;
                    db.SaveChanges();
                }
                // otherwise it could be used for maintenance purposes
            }
        }
Пример #4
0
        public void Handle(SavedNewDraftLessonEvent @event)
        {
            using (var db = new DisciturContext())
            {
                int  userId = _identityMapper.GetModelId <User>(@event.AuthorId);
                User _user  = db.Users.Find(userId);

                Lesson lesson = new Lesson();
                lesson.Title        = @event.Title;
                lesson.Discipline   = @event.Discipline;
                lesson.School       = @event.School;
                lesson.Classroom    = @event.Classroom;
                lesson.Author       = _user;
                lesson.UserId       = _user.UserId;
                lesson.Content      = @event.Content;
                lesson.Conclusion   = @event.Conclusion;
                lesson.PublishDate  = @event.CreationDate;
                lesson.CreationDate = @event.CreationDate;
                UpdateLessonArchFields(lesson, _user.UserName, @event.CreationDate, @event.Version);
                //lesson.LastModifDate = @event.CreationDate;
                //lesson.LastModifUser = _user.UserName;
                //lesson.Vers = 1;
                lesson.RecordState = Constants.RECORD_STATE_ACTIVE;

                // Create FeedBacks Collection
                if (@event.FeedBacks.ContainsKey(EntityStatus.A))
                {
                    @event.FeedBacks[EntityStatus.A].ToList()
                    .ForEach(feedback => {
                        LessonFeedback fb = new LessonFeedback()
                        {
                            Feedback           = feedback.Feedback,
                            Nature             = feedback.Nature,
                            LessonFeedbackGuid = feedback.Id
                        };
                        lesson.FeedBacks.Add(fb);
                    });
                }
                // Create Tags Collection
                if (@event.Tags.ContainsKey(EntityStatus.A))
                {
                    @event.Tags[EntityStatus.A].ToList()
                    .ForEach(tag =>
                    {
                        LessonTag t = new LessonTag()
                        {
                            LessonTagName = tag.LessonTagName
                        };
                        lesson.Tags.Add(t);
                    });
                }

                db.Lessons.Add(lesson);
                db.SaveChanges();
                //Ids mapping
                _identityMapper.Map <Lesson>(lesson.LessonId, @event.Id);
                if (lesson.FeedBacks.Count > 0)
                {
                    lesson.FeedBacks.ToList()
                    .ForEach(feedback => _identityMapper.Map <LessonFeedback>(feedback.LessonFeedbackId, feedback.LessonFeedbackGuid));
                }
            }
        }
Пример #5
0
        public void Handle(SavedDraftLessonEvent @event)
        {
            using (var db = new DisciturContext())
            {
                int    lessonId = _identityMapper.GetModelId <Lesson>(@event.Id);
                Lesson lesson   = db.Lessons.Where(l => l.LessonId.Equals(lessonId) &&
                                                   //l.Vers.Equals(@event.Version) &&
                                                   l.RecordState.Equals(Constants.RECORD_STATE_ACTIVE))
                                  .First();

                if (lesson.Title != @event.Title)
                {
                    lesson.Title = @event.Title;
                }
                if (lesson.Discipline != @event.Discipline)
                {
                    lesson.Discipline = @event.Discipline;
                }

                lesson.School      = @event.School;
                lesson.Classroom   = @event.Classroom;
                lesson.Discipline  = @event.Discipline;
                lesson.Content     = @event.Content;
                lesson.Conclusion  = @event.Conclusion;
                lesson.PublishDate = @event.ModificationDate;

                // Update FeedBacks Collection
                if (@event.FeedBacks.ContainsKey(EntityStatus.A))
                {
                    @event.FeedBacks[EntityStatus.A].ToList()
                    .ForEach(feedback => {
                        LessonFeedback fb = new LessonFeedback()
                        {
                            Feedback           = feedback.Feedback,
                            Nature             = feedback.Nature,
                            LessonFeedbackGuid = feedback.Id
                        };
                        lesson.FeedBacks.Add(fb);
                    });
                }
                if (@event.FeedBacks.ContainsKey(EntityStatus.M))
                {
                    @event.FeedBacks[EntityStatus.M].ToList()
                    .ForEach(feedback =>
                    {
                        var item      = lesson.FeedBacks.Single(f => f.LessonFeedbackId.Equals(_identityMapper.GetModelId <LessonFeedback>(feedback.Id)));
                        item.Feedback = feedback.Feedback;
                    });
                }
                if (@event.FeedBacks.ContainsKey(EntityStatus.C))
                {
                    @event.FeedBacks[EntityStatus.C].ToList()
                    .ForEach(feedback =>
                    {
                        var item = lesson.FeedBacks.Single(f => f.LessonFeedbackId.Equals(_identityMapper.GetModelId <LessonFeedback>(feedback.Id)));
                        lesson.FeedBacks.Remove(item);
                        db.LessonFeedbacks.Remove(item);
                    });
                }
                // Update Tags Collection
                if (@event.Tags.ContainsKey(EntityStatus.A))
                {
                    @event.Tags[EntityStatus.A].ToList()
                    .ForEach(tag => {
                        LessonTag t = new LessonTag()
                        {
                            LessonTagName = tag.LessonTagName
                        };
                        lesson.Tags.Add(t);
                    });
                }
                if (@event.Tags.ContainsKey(EntityStatus.C))
                {
                    @event.Tags[EntityStatus.C].ToList()
                    .ForEach(tag =>
                    {
                        var item = lesson.Tags.Single(t => t.LessonTagName.Equals(tag.LessonTagName));
                        lesson.Tags.Remove(item);
                        db.LessonTags.Remove(item);
                    });
                }
                UpdateLessonArchFields(lesson, lesson.LastModifUser, @event.ModificationDate, @event.Version);

                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();

                if (lesson.FeedBacks.Count > 0)
                {
                    lesson.FeedBacks.ToList()
                    .ForEach(feedback => {
                        if (@event.FeedBacks.ContainsKey(EntityStatus.A) && @event.FeedBacks[EntityStatus.A].Any(f => f.Id.Equals(feedback.LessonFeedbackGuid)))
                        {
                            _identityMapper.Map <LessonFeedback>(feedback.LessonFeedbackId, feedback.LessonFeedbackGuid);
                        }
                    });
                }
            }
        }
Пример #6
0
        protected override void Seed(MyHobby.Models.MyHobbyContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            DataImporter importer = new DataImporter();

            importer.ImportSuburbs(context);

            Suburb mk  = context.Suburbs.SingleOrDefault(s => s.EnglishName == "Mong Kok");
            Suburb cwb = context.Suburbs.SingleOrDefault(s => s.EnglishName == "Causeway Bay");
            Suburb tst = context.Suburbs.SingleOrDefault(s => s.EnglishName == "Tsim Sha Tsui");

            context.HobbyCategories.AddOrUpdate(
                c => c.Id,
                new HobbyCategory {
                Id = 100, Name = "Arts & Craft"
            },
                new HobbyCategory {
                Id = 200, Name = "Career & Business"
            },
                new HobbyCategory {
                Id = 300, Name = "Dance"
            },
                new HobbyCategory {
                Id = 400, Name = "Fashion & Beauty"
            },
                new HobbyCategory {
                Id = 500, Name = "Food & Drink"
            },
                new HobbyCategory {
                Id = 600, Name = "Music"
            },
                new HobbyCategory {
                Id = 700, Name = "Photography"
            },
                new HobbyCategory {
                Id = 800, Name = "Sports"
            },
                new HobbyCategory {
                Id = 900, Name = "Technology"
            }
                );

            HobbyCategory sports = context.HobbyCategories.Find(800);
            HobbyCategory food   = context.HobbyCategories.Find(500);

            Business tennisAcademy = new Business {
                Name = "HK Tennis Academy", Description = "all about tennis", Suburb = mk, Address = "723 Evergreen Terrace", HobbyCategories = new List <HobbyCategory> {
                    sports
                }
            };
            Business cakeFactory = new Business {
                Name = "Cake Factory", Description = "chocolate banana cake", Suburb = cwb, Address = "723 Evergreen Terrace", HobbyCategories = new List <HobbyCategory> {
                    food
                }
            };

            context.Businesses.AddOrUpdate(
                i => i.Name,
                tennisAcademy,
                cakeFactory
                );

            User anthony = new User {
                Name = "Anthony", Username = "******", Password = "******", CreatedDate = DateTime.UtcNow
            };

            context.Users.AddOrUpdate(
                i => i.Username,
                anthony,
                new User {
                Name = "mario", Username = "******", Password = "******", CreatedDate = DateTime.UtcNow
            }
                );

            BusinessUser staff1 = new BusinessUser {
                Business = tennisAcademy, User = anthony, Role = UserRole.Admin, Title = "專業教練"
            };

            context.BusinessUsers.AddOrUpdate(
                bu => new { bu.BusinessId, bu.UserId },
                staff1
                );

            BusinessReview goodCakeReview = new BusinessReview {
                Title = "老師很用心", Comment = "非常推介,會再來", Rating = 5, CreatedTime = DateTime.UtcNow, Business = cakeFactory, CreatedBy = anthony
            };
            BusinessReview badCakeReview = new BusinessReview {
                Title = "老師無料到", Comment = "不會再來", Rating = 1, CreatedTime = DateTime.UtcNow, Business = cakeFactory, CreatedBy = anthony
            };

            context.BusinessReviews.AddOrUpdate(
                i => i.Title,
                goodCakeReview,
                badCakeReview
                );

            BusinessReviewComment cakeReviewComment = new BusinessReviewComment {
                Comment = "thank you for your feedback", CreatedTime = DateTime.UtcNow, BusinessReview = badCakeReview, CreatedBy = anthony
            };

            context.BusinessReviewComments.AddOrUpdate(
                i => i.Id,
                cakeReviewComment
                );

            Course tennisDummy = new Course {
                Name = "Tennis for Dummies", Description = "Teach you everything to prepare yourself for wimbledon"
            };

            if (context.Courses.SingleOrDefault(c => c.Name == tennisDummy.Name) == null)
            {
                tennisDummy.Business = tennisAcademy;
            }

            context.Courses.AddOrUpdate(
                i => i.Name,
                tennisDummy
                );

            LessonTag tennisTag = new LessonTag()
            {
                Id = 1, Tag = "Tennis"
            };
            LessonTag cupcakeTag = new LessonTag()
            {
                Id = 2, Tag = "cupcake"
            };
            LessonTag cakeTag = new LessonTag()
            {
                Id = 3, Tag = "cake"
            };

            context.LessonTags.AddOrUpdate(
                i => i.Tag,
                tennisTag,
                cupcakeTag,
                cakeTag
                );

            context.Lessons.AddOrUpdate(
                i => i.Name,
                new Lesson {
                Id = 1, Business = tennisAcademy, Suburb = mk, Name = "Cupcakes", Description = "first class in the series", CostNotes = "4 classes, 1hr/class", Instructors = new List <User> {
                    anthony
                }, Course = tennisDummy, Tags = new List <LessonTag> {
                    cakeTag, cupcakeTag
                }
            },
                new Lesson {
                Id = 2, Business = tennisAcademy, Suburb = cwb, Name = "Baking 101", Description = "first class in the series", CostNotes = "4 classes, 1hr/class", Instructors = new List <User> {
                    anthony
                }, Course = tennisDummy, Tags = new List <LessonTag> {
                    cakeTag
                }
            }
                );

            int ii = 1;

            for (int i = 0; i < 20; i++)
            {
                Lesson lesson1 = new Lesson {
                    Business = tennisAcademy, Suburb = tst, Name = "Tennis " + ii, Address = "Victoria park, Causewaybay", Description = "first class in the series", Instructors = new List <User> {
                        anthony
                    }, Course = null, Tags = new List <LessonTag> {
                        tennisTag
                    }
                };
                context.Lessons.Add(lesson1);

                Session s1 = new Session {
                    Lesson = lesson1, Cost = 200, CostNotes = "4 classes, 1hr/class", MaxStudents = 15, StartDate = DateTime.Today, EndDate = DateTime.Today.AddHours(2), Deadline = DateTime.Today
                };
                context.Sessions.Add(s1);

                Session s2 = new Session {
                    Lesson = lesson1, Cost = 200, CostNotes = "4 classes, 1hr/class", MaxStudents = 15, StartDate = DateTime.Today.AddMonths(1), EndDate = DateTime.Today.AddMonths(1).AddHours(2), Deadline = DateTime.Today, Registrations = new List <Registration> {
                        new Registration()
                        {
                            Student = anthony, RegistrationDate = DateTime.UtcNow
                        }
                    }
                };
                context.Sessions.Add(s2);

                ii++;
            }
        }