public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Models.Program program) { if (id != program.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(program); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProgramExists(program.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(program)); }
public async Task <IActionResult> Create([Bind("ID,ProgramName,ProgramDescription,ProgramJoinCode,ProgramSupervisorID")] Models.Program program) { try { if (ModelState.IsValid) { _context.Add(program); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Programs_ProgramJoinCode")) { ModelState.AddModelError("ProgramJoinCode", "Unable to save changes. Remember, you cannot have duplicate Program Join Codes."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system admin."); } } ViewData["ProgramSupervisorID"] = new SelectList(_context.ProgramSupervisors, "ID", "Email", program.ProgramSupervisorID); return(View(program)); }
/// <summary> /// 由节目生成日历提醒 /// </summary> /// <param name="program"></param> public async Task <Messages> CreateAppoint(Models.Program program) { if (_calendar == null) { return(Messages.NotInitialized); } if (_container.Values.Keys.Contains(program.UniqueId)) { return(Messages.AlreadyExists); } var appointment = new Appointment() { Subject = program.Name, StartTime = program.StartTime, Duration = program.Duration, AllowNewTimeProposal = false, Details = $"第{program.Episode}集", Location = program.Channel.Name, Reminder = (bool)SettingService.Instance.Get("EnableCalendarNotification", true) ? (TimeSpan)SettingService.Instance.Get("ReminderSpanAhead", TimeSpan.FromMinutes(5)) as TimeSpan? : null }; await _calendar.SaveAppointmentAsync(appointment); _container.Values.Add(program.UniqueId, appointment.LocalId); LoggingService.Debug("Service", $"为节目{program}添加日历提醒成功,ID为{appointment.LocalId}"); return(Messages.Sucess); }
public void CreateCandidatura() { //arrange //act Cimob.Models.ApplicationUser applicationUser = new Models.ApplicationUser() { Id = "2", UserName = "******", Email = "*****@*****.**" }; Cimob.Models.Program program = new Models.Program() { ProgramId = 2, Name = "Erasmus Espanha", Bolsa = 120, Description = "Programas Erasmus para Espanha", StartDate = new DateTime().AddDays(12).AddMonths(10).AddYears(2016), EndDate = new DateTime().AddDays(12).AddMonths(3).AddYears(2017) }; Cimob.Models.Destination destination = new Models.Destination() { DestinationId = 2, Pais = "Espanha", Cidade = "Madrid" }; Cimob.Models.CandidaturaState candidaturaState = new Models.CandidaturaState(); Cimob.Models.Candidatura candidatura = new Cimob.Models.Candidatura() { CandidaturaId = 1, ProgramId = 2, AppliedProgram = program, UserId = "2", SubmissionUser = applicationUser, State = candidaturaState, StartDate = new DateTime().AddDays(12).AddMonths(10).AddYears(2016), LastStateDate = new DateTime().AddDays(12).AddMonths(10).AddYears(2016) }; //assert programa da candidatura Assert.Matches(candidatura.AppliedProgram.Name, program.Name); Assert.Equal(candidatura.AppliedProgram.Bolsa, program.Bolsa); Assert.Matches(candidatura.AppliedProgram.Description, program.Description); Assert.Equal(candidatura.AppliedProgram.StartDate, program.StartDate); Assert.Equal(candidatura.AppliedProgram.EndDate, program.EndDate); //assert user da candidatura Assert.Matches(candidatura.SubmissionUser.UserName, applicationUser.UserName); Assert.Matches(candidatura.SubmissionUser.Email, applicationUser.Email); }
public void UpdateModel(Models.Program program, Person currentPerson) { var programPeopleToCommit = PersonIDList != null?PersonIDList.Select(x => new ProgramPerson(program.ProgramID, x)).ToList() : new List <ProgramPerson>(); program.ProgramPeople.Merge(programPeopleToCommit, HttpRequestStorage.DatabaseEntities.ProgramPeople.Local, (x, y) => x.ProgramID == y.ProgramID && x.PersonID == y.PersonID); }
public async Task Delete(Guid id) { Models.Program program = await GetById(id); context.Remove(program); await context.SaveChangesAsync(); }
public async Task CreateProgram(Models.Program program) { var trackerAssets = await _mantleRestClient.SendRequestAsync <IEnumerable <TrackerAsset> >($"/tracker/{_trackerProductId}/assets?limit=1000", HttpMethod.Get); var multiAssetRequest = new RestRequestConfig { Body = program.ToMultiAssetRequest(trackerAssets) }; await _mantleRestClient.SendRequestAsync <string>($"/tracker/{_trackerProductId}/multiassets", HttpMethod.Post, multiAssetRequest); }
public EditViewModel(Models.Program program) { ProgramID = program.ProgramID; ProgramName = program.ProgramName; ProgramShortName = program.ProgramShortName; OrganizationID = program.OrganizationID; PrimaryContactPersonID = program.ProgramPrimaryContactPerson?.PersonID; IsActive = program.ProgramIsActive; IsDefaultForBulkImportOnly = program.IsDefaultProgramForImportOnly; }
public async Task Insert(Models.Program program, string text) { Guid blobId = await datastoreService.InsertBlob(text); program.BlobId = blobId; await context.AddAsync(program); await context.SaveChangesAsync(); }
public DetailViewData(Person currentPerson, Models.Program program ) : base(currentPerson, program) { PageTitle = program.ProgramName; BreadCrumbTitle = $"{Models.FieldDefinition.Program.GetFieldDefinitionLabel()} Detail"; Defaults = GisUploadSourceOrganization != null ? GisUploadSourceOrganization.GisDefaultMappings : new List <GisDefaultMapping>(); CrosswalkDefaults = GisUploadSourceOrganization != null ? GisUploadSourceOrganization.GisCrossWalkDefaults : new List <GisCrossWalkDefault>(); }
public DetailViewData(Person currentPerson, Models.Program program ) : base(currentPerson, program) { PageTitle = program.ProgramName; BreadCrumbTitle = $"{Models.FieldDefinition.Program.GetFieldDefinitionLabel()} Detail"; Defaults = GisUploadSourceOrganization != null ? GisUploadSourceOrganization.GisDefaultMappings : new List <GisDefaultMapping>(); CrosswalkDefaults = GisUploadSourceOrganization != null ? GisUploadSourceOrganization.GisCrossWalkDefaults : new List <GisCrossWalkDefault>(); EditProgramPeopleUrl = SitkaRoute <ProgramController> .BuildUrlFromExpression(c => c.EditProgramPeople(program)); }
public async Task <IActionResult> Create([Bind("ID,Name")] Models.Program program) { if (ModelState.IsValid) { _context.Add(program); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(program)); }
public async Task <IActionResult> PostProgram([FromBody] Models.Program program) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Programs.Add(program); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProgram", new { id = program.Id }, program)); }
protected ProgramViewData(Person currentPerson, Models.Program program) : base(currentPerson, null) { Program = program; HtmlPageTitle = program.ProgramName; EntityName = $"{Models.FieldDefinition.Program.GetFieldDefinitionLabel()}"; EditProgramUrl = program.GetEditUrl(); UserHasEditProgramPermissions = new ProgramEditFeature().HasPermissionByPerson(currentPerson); BackToProgramsText = $"Back to all {Models.FieldDefinition.Program.GetFieldDefinitionLabelPluralized()}"; ProgramsListUrl = SitkaRoute <ProgramController> .BuildUrlFromExpression(c => c.Index()); GisUploadSourceOrganization = program.GisUploadSourceOrganizations.FirstOrDefault(); }
private void PlayProgram(Models.Program program) { if (Player != null) { Player.Pause(); mplayer.URL = program.Channel; mplayer.MediaError += mplayer_MediaError; currentProgram = program; mplayer.play(); //axWindowsMediaPlayer1.Ctlcontrols.play(); return; } }
public CreateModel(SacramentMeetingPlanner.Data.SacramentMeetingPlannerContext context) { _context = context; Program = new Models.Program { DateOfMeeting = DateTime.Now, Participants = new List <Participant> { new Participant(), new Participant(), new Participant(), new Participant(), new Participant { ParticipantRole = ParticipantRoles.Speaker.ToString() } } }; }
public async Task <Models.Program> AddProgramAsync( AddProgramInput input, [ScopedService] AppDbContext context, ITopicEventSender eventSender, CancellationToken cancellationToken ) { var program = new Models.Program { ProgramName = input.ProgramName, ProgramNumber = input.ProgramNumber }; await context.Programs.AddAsync(program); await context.SaveChangesAsync(cancellationToken); await eventSender.SendAsync(nameof(Subscription.OnProgramAdd), program, cancellationToken); return(program); }
public void UpdateModel(Models.Program program, Person currentPerson, bool isNew) { program.ProgramName = IsDefaultForBulkImportOnly ? null : ProgramName; program.ProgramShortName = IsDefaultForBulkImportOnly ? null : ProgramShortName; program.OrganizationID = OrganizationID.GetValueOrDefault(); program.ProgramIsActive = IsActive; program.IsDefaultProgramForImportOnly = IsDefaultForBulkImportOnly; if (isNew) { program.ProgramCreateDate = DateTime.Now; program.ProgramCreatePersonID = currentPerson.PersonID; } else { program.ProgramLastUpdatedDate = DateTime.Now; program.ProgramLastUpdatedByPersonID = currentPerson.PersonID; } program.ProgramPrimaryContactPersonID = PrimaryContactPersonID; }
public async Task <IActionResult> OnGetAsync(int?programid) { var reqUrl = Request.HttpContext.Request; programid = int.Parse(reqUrl.Query["id"]); if (programid == 0) { return(NotFound()); } Program = await _context.Program.FirstOrDefaultAsync(m => m.ProgramID == programid); Program.Participants = await _context.Participant.Where(x => x.ProgramID == Program.ProgramID).ToListAsync(); if (Program == null) { return(NotFound()); } return(Page()); }
internal static Utilites.Objects.Program Create_Client_From_Database(Models.Program databaseProgram) { if (databaseProgram == null) { return(new Utilites.Objects.Program()); } Utilites.Objects.Program clientProgram = new Utilites.Objects.Program(); clientProgram.ID = databaseProgram.ProgramID; clientProgram.Name = string.Copy(databaseProgram.ProgramName); using (Models.TrackerContext trackerDatabase = new Models.TrackerContext()) { var workoutsForProgram = trackerDatabase.ProgramTemplates.Where(p => p.ProgramID == databaseProgram.ProgramID); foreach (Models.ProgramTemplate template in workoutsForProgram) { clientProgram.Workouts.Add(WorkoutFactory.Create_Client_From_Database(template)); } } return(clientProgram); }
private void Scrobble(DateTime time) { foreach (Models.Program program in currentPlaylist.Programs) { TimeSpan subtract = time.Subtract(program.Start); if (subtract.TotalSeconds <= 60 && subtract.TotalSeconds > 0) { PlayProgram(program); return; } // Check if program has ended, then resume the playback if (currentProgram != null) { TimeSpan minutesLeft = currentProgram.End.Subtract(time); if (minutesLeft.TotalMinutes <= 1 && minutesLeft.TotalMinutes >= -1) { // Stop and go back StopProgram(); } } } foreach (Models.Bulletin bulletin in currentPlaylist.Bulletins) { if (bulletin.Timing.Type == "hour") { if (time.Minute == bulletin.Timing.Number && time.Hour % bulletin.Timing.Range == 0) { Models.Program temporaryProgram = new Models.Program(time, bulletin.Duration, bulletin.Channel); currentProgram = temporaryProgram; PlayProgram(temporaryProgram); return; } } } }
public Task <string> GetBlob(Models.Program program) { return(datastoreService.GetBlob(program.BlobId)); }
internal static Models.Program Create_Database_From_Client(Utilites.Objects.Program clientProgram) { Models.Program databaseProgram = new Models.Program(); return(databaseProgram); }
public async Task <IActionResult> Edit(int id, Byte[] RowVersion, [Bind("ID,ProgramName,ProgramDescription,ProgramJoinCode,ProgramSupervisorID")] Models.Program program) { var programToUpdate = await _context.Programs.SingleOrDefaultAsync(p => p.ID == id); if (programToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Models.Program>(programToUpdate, "", p => p.ProgramName, p => p.ProgramDescription, p => p.ProgramJoinCode, p => p.ProgramSupervisorID)) { try { _context.Entry(programToUpdate).Property("RowVersion").OriginalValue = RowVersion; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException dex) { var exceptionEntry = dex.Entries.Single(); var clientValues = (Models.Program)exceptionEntry.Entity; var databaseEntry = exceptionEntry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError("", "Unable to save changes. The Program was deleted by another user."); } else { var databaseValues = (Models.Program)databaseEntry.ToObject(); if (databaseValues.ProgramName != clientValues.ProgramName) { ModelState.AddModelError("ProgramName", "Current value: " + databaseValues.ProgramName); } if (databaseValues.ProgramDescription != clientValues.ProgramDescription) { ModelState.AddModelError("ProgramDescription", "Current value: " + databaseValues.ProgramDescription); } if (databaseValues.ProgramJoinCode != clientValues.ProgramJoinCode) { ModelState.AddModelError("ProgramJoinCode", "Current value: " + databaseValues.ProgramJoinCode); } if (databaseValues.ProgramSupervisorID != clientValues.ProgramSupervisorID) { ProgramSupervisor databaseAssignment = await _context.ProgramSupervisors.SingleOrDefaultAsync(i => i.ID == databaseValues.ProgramSupervisorID); ModelState.AddModelError("ProgramSupervisorID", $"Current value: {databaseAssignment?.Supervisor}"); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you received your values. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to save your version of this record, click " + "the Save button again. Otherwise click the 'Back to List' hyperlink."); programToUpdate.RowVersion = (byte[])databaseValues.RowVersion; ModelState.Remove("RowVersion"); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Programs_ProgramJoinCode")) { ModelState.AddModelError("Email", "Unable to save changes. Remember, you cannot have duplicate Program Join Codes."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } } ViewData["ProgramSupervisorID"] = new SelectList(_context.ProgramSupervisors, "ID", "Supervisor", program.ProgramSupervisorID); return(View(program)); }
private void PlayProgram(Models.Program program) { if (Player != null) { Player.Pause(); mplayer.URL = program.Channel; mplayer.MediaError += mplayer_MediaError; currentProgram = program; mplayer.play(); //axWindowsMediaPlayer1.Ctlcontrols.play(); return; } }
public async Task <IActionResult> AddProgram([FromBody] Models.Program program) { await _dataService.CreateProgram(program); return(Ok()); }
private void Scrobble(DateTime time) { foreach (Models.Program program in currentPlaylist.Programs) { TimeSpan subtract = time.Subtract(program.Start); if (subtract.TotalSeconds <= 60 && subtract.TotalSeconds > 0) { PlayProgram(program); return; } // Check if program has ended, then resume the playback if (currentProgram != null) { TimeSpan minutesLeft = currentProgram.End.Subtract(time); if (minutesLeft.TotalMinutes <= 1 && minutesLeft.TotalMinutes >= -1) { // Stop and go back StopProgram(); } } } foreach (Models.Bulletin bulletin in currentPlaylist.Bulletins) { if(bulletin.Timing.Type == "hour") { if (time.Minute == bulletin.Timing.Number && time.Hour % bulletin.Timing.Range == 0) { Models.Program temporaryProgram = new Models.Program(time, bulletin.Duration, bulletin.Channel); currentProgram = temporaryProgram; PlayProgram(temporaryProgram); return; } } } }
public void AddProgram(Models.Program program) => _db.Programs.Add(program);
/// <summary> /// 根据电视猫页面链接获取节目单 /// </summary> /// <param name="href">节目单链接</param> /// <param name="daydiff">日期的偏差值</param> private async Task <ScheduleList> GetScheduleFromPage(Uri href, TimeSpan daydiff) { HttpClient client = new HttpClient(); var response = await client.GetByteArrayAsync(href); string result = Encoding.UTF8.GetString(response); HtmlDocument document = new HtmlDocument(); document.LoadHtml(result); var schedules = new ScheduleList(); HtmlNode rootNode = document.DocumentNode; HtmlNodeCollection channelNode = rootNode.SelectNodes("/body[1]/div[@class='page-content clear']/div[@class='timeline clear']/table[@class='timetable']/table[@class='timetable']"); foreach (HtmlNode channel in channelNode) { HtmlNode chNode = channel.SelectSingleNode("./tr[1]/td[@class='tdchn']"); HtmlNodeCollection proCollect = channel.SelectNodes("./tr[1]/td[@class='tdpro']"); string chName = chNode.InnerText; string chLink = chNode.FirstChild.GetAttributeValue("href", "--"); var chLinkSIdx = chLink.IndexOf('-') + 1; var key = chLink.Substring(chLinkSIdx, chLink.LastIndexOf('-') - chLinkSIdx); var uniqueKey = key.ToLower(); Channel chn = Channel.GetChannel(key, chName); chn.LogoID = key; if (schedules.ContainsKey(chn)) { #if DEBUG && DEBUG_SCHEDULE System.Diagnostics.Debugger.Break(); // 存在重复频道,需要调试 #endif continue; } List <Models.Program> proList = new List <Models.Program>(); schedules.Add(chn, proList); foreach (HtmlNode prog in proCollect) { string progName = WebUtility.HtmlDecode(prog.FirstChild.InnerText).Trim(); string startTime = WebUtility.HtmlDecode(prog.LastChild.InnerText).Trim(); Models.Program program = null; char[] space = { ' ' }; var judgeLast = startTime.Trim().Distinct(); if (judgeLast.Count() == 1 && judgeLast.First() == '.') { if (progName == startTime) { // 只有省略号的情况 var texts = prog.GetAttributeValue("title", string.Empty).Split(space, 2); program = new Models.Program() { Name = texts[1].TrimStart(space), StartTime = Convert.ToDateTime(texts[0]) }; } else { // 节目时间为省略号的情况 var timestr = prog.GetAttributeValue("title", string.Empty); DateTime time; if (!DateTime.TryParse(timestr, out time)) { // 部分情况下节目名称也会进来。。因此还是取空格前面的 time = Convert.ToDateTime(timestr.Split(space, 2)[0]); } program = new Models.Program() { Name = progName, StartTime = time }; } } else { // 节目名字靠边被省略的情况 if (prog.Attributes.Contains("title")) { progName = prog.Attributes["title"].DeEntitizeValue.Trim(); } program = new Models.Program() { Name = progName, StartTime = Convert.ToDateTime(startTime) }; } // 处理节目时间跨天的情况 if (href.AbsoluteUri.EndsWith("h0.html")) { if (program.StartTime > Convert.ToDateTime("02:00")) { program.StartTime -= TimeSpan.FromDays(1); } } program.StartTime -= daydiff; proList.Add(program); } } return(schedules); }
public CandidaturasControllerTest() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Add_Candidaturas_to_database") .Options; //#pragma warning disable CS0618 // Type or member is obsolete // //optionsBuilder.UseInMemoryDatabase().Options; //#pragma warning restore CS0618 // Type or member is obsolete _context = new ApplicationDbContext(optionsBuilder); //seed data Cimob.Models.ApplicationUser fernando = new Models.ApplicationUser() { Id = "1", UserName = "******", Email = "*****@*****.**", PasswordHash = "pass" }; Cimob.Models.Program program = new Models.Program() { ProgramId = 1, Name = "Erasmus Tota", Bolsa = 120, Description = "Programas Erasmus do Tota", StartDate = new DateTime().AddDays(12).AddMonths(10).AddYears(2016), EndDate = new DateTime().AddDays(12).AddMonths(3).AddYears(2017), DestinationId = 1 }; Cimob.Models.Destination destination = new Models.Destination() { DestinationId = 1, Pais = "Inglaterra", Cidade = "Londres" }; Cimob.Models.CandidaturaState candidaturaState = new Models.CandidaturaState(); Cimob.Models.Candidatura candidatura = new Cimob.Models.Candidatura() { CandidaturaId = 1, ProgramId = 1, AppliedProgram = program, UserId = "1", SubmissionUser = fernando, State = candidaturaState, StartDate = new DateTime().AddDays(12).AddMonths(12).AddYears(2016) }; _context.Users.Add(fernando); _context.Programs.Add(program); _context.Destinations.Add(destination); _context.Candidatura.Add(candidatura); _context.SaveChanges(); //_userManager.AddLoginAsync(fernando, new UserLoginInfo().LoginProvider()); //new IdentityResult x = await .AddPasswordAsync(fernando, fernando.PasswordHash.ToString().SignIn ) _controller = new CandidaturasController(_context, _userManager); }
public async Task Update(Models.Program program) { context.Update(program); await context.SaveChangesAsync(); }
public EditProgramPeopleViewModel(Models.Program program) { ProgramID = program.ProgramID; PersonIDList = program.ProgramPeople.Select(x => x.PersonID).ToList(); }