Beispiel #1
0
        public ActionResult Update(ResponseUpdateView model)
        {
            model.ToCourseTC = model.ToCourseTC.ToUpperInvariant();
            if (!Repository.GetAll().Any(x => x.Course_TC == model.ToCourseTC))
            {
                ShowMessage("Курс с кодом {0} не существует".FormatWith(model.ToCourseTC));
                return(RedirectBack());
            }
            var responses     = ResponseService.GetAll(x => x.Course_TC == model.FromCourseTC).ToList();
            var responseCount = responses.Count;

            foreach (var response in responses)
            {
                response.Course_TC = model.ToCourseTC;
            }
            ResponseService.SubmitChanges();
            Func <string, string> comma = x => "," + x + ",";

            var workCount    = UpdateUserWorks(model, comma);
            var sectionCount = UpdateSections(model, comma);

            UpdateEntityStudySets(model, comma);
            var tagCount       = UpdateRelations(model);
            var courseTagCount = UpdateCourseRelations(model);

            SORelationService.SubmitChanges();

            var message = (
                "Обновлено. Отзывов {0}, работ слушателей {1}, не анонс {4}, привязки {2} и курса {3}, ")
                          .FormatWith(responseCount, workCount, tagCount, courseTagCount, sectionCount);

            ShowMessage(message);
            return(RedirectBack());
        }
Beispiel #2
0
        private int UpdateCourseRelations(ResponseUpdateView model)
        {
            var courseTableName = LinqToSqlUtils.GetTableName(typeof(Course));
            var relations       = SORelationService.GetAll(x =>
                                                           x.Object_ID.Equals(model.FromCourseTC) &&
                                                           x.ObjectType == courseTableName).ToList();

            foreach (var relation in relations)
            {
                relation.Object_ID = model.ToCourseTC;
            }

            var count = relations.Count;

            return(count);
        }
Beispiel #3
0
        private void UpdateEntityStudySets(ResponseUpdateView model, Func <string, string> comma)
        {
            var entitySets = EntityStudySetService.GetAll().Select(uw => new {
                courseTCs = "," + uw.CourseTCList.Replace(" ", "") + ",",
                uw
            })
                             .Where(x => x.courseTCs.Contains(comma(model.FromCourseTC))).ToList();

            foreach (var entitySet in entitySets)
            {
                var newCourseTCs = entitySet.courseTCs.Replace(comma(model.FromCourseTC),
                                                               comma(model.ToCourseTC));
                entitySet.uw.CourseTCList = newCourseTCs.Trim(',');
            }
            UserWorkService.SubmitChanges();
        }
Beispiel #4
0
        private int UpdateUserWorks(ResponseUpdateView model, Func <string, string> comma)
        {
            var userWorks = UserWorkService.GetAll().Select(uw => new {
                courseTCs = "," + uw.Course_TC.Replace(" ", "") + ",",
                uw
            })
                            .Where(x => x.courseTCs.Contains(comma(model.FromCourseTC))).ToList();

            foreach (var userWork in userWorks)
            {
                var newCourseTCs = userWork.courseTCs.Replace(comma(model.FromCourseTC),
                                                              comma(model.ToCourseTC));
                userWork.uw.Course_TC = newCourseTCs.Trim(',');
            }
            UserWorkService.SubmitChanges();
            return(userWorks.Count);
        }
Beispiel #5
0
        private int UpdateSections(ResponseUpdateView model, Func <string, string> comma)
        {
            var sections = SectionService.GetAll().Select(uw => new {
                courseTCs = "," + uw.NotAnnounce.Replace(" ", "") + ",",
                uw
            })
                           .Where(x => x.courseTCs.Contains(comma(model.FromCourseTC))).ToList();

            foreach (var section in sections)
            {
                var newCourseTCs = section.courseTCs.Replace(comma(model.FromCourseTC),
                                                             comma(model.ToCourseTC));
                section.uw.NotAnnounce = newCourseTCs.Trim(',');
            }
            SectionService.SubmitChanges();
            return(sections.Count);
        }