コード例 #1
0
        public async Task <ActionResult> Add([Bind(Include = "FacultyId, Name")] Programme programme)
        {
            if (ModelState.IsValid)
            {
                _programmeRepository.Add(programme);
                await _programmeRepository.Commit();

                return(RedirectToAction("Index", new { facultyId = programme.FacultyId }));
            }

            return(View(programme));
        }
コード例 #2
0
        public IHttpActionResult Post([FromBody] List <CreateProgramme> programs)
        {
            if (programs == null || !programs.Any() || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ValidatePrograms(programs);

            var programmeList = _mapper.Map <IEnumerable <Programme> >(programs)
                                .OrderBy(x => x.StartDateTime)
                                .SequentiallyCount <Programme>(new ProgrammePrgtNoSequenceCounter())
                                .ToList();

            _programmeRepository.Add(programmeList);

            // group by date and channels
            programmeList.GroupBy(s => new { s.StartDateTime.Date, s.SalesArea }).ForEach(grp =>
            {
                using (MachineLock.Create(string.Format("xggameplan.scheduleday.{0}.{1}", grp.Key.SalesArea, grp.Key.Date), new TimeSpan(0, 10, 0)))
                {
                    using (var scope = _repositoryFactory.BeginRepositoryScope())
                    {
                        var scheduleRepository = scope.CreateRepository <IScheduleRepository>();
                        var schedule           = scheduleRepository.GetOrCreateSchedule(grp.Key.SalesArea, grp.Key.Date);

                        if (schedule.Programmes is null)
                        {
                            schedule.Programmes = new List <Programme>();
                        }

                        schedule.Programmes.AddRange(grp);
                        scheduleRepository.Add(schedule);
                        scheduleRepository.SaveChanges();
                    }
                }
            });

            return(Ok());
        }
コード例 #3
0
 public override Programme Add(Programme model)
 {
     _repository.Add(model);
     return(model);
 }