public void Add(Daf item) { var now = DateTime.Now; item.CreatedAt = DateTime.Now; item.CreatedBy = Permissions.User.Id; db.Dafs.AddObject(item); db.SaveChanges(); }
private History getHistoryBase(Daf item, string FieldName, object oldValue, object newValue) { return(new History { ReferenceId = item.Id, TableName = "DAF", FieldName = FieldName, OldValue = string.Format("{0}", oldValue), NewValue = string.Format("{0}", newValue), UpdateDate = item.UpdateAt.Value, UpdatedBy = item.UpdatedBy.Value, }); }
private IEnumerable <History> GetQuestionsHistory(Daf item, object oldValue, object newValue) { var questions = DAF_v2(null).Questions; var oldAnswers = ccEntities.Deserialize <List <CC.Data.Models.DafQuestion> >((string)oldValue) ?? new List <CC.Data.Models.DafQuestion>(); var newAnswers = ccEntities.Deserialize <List <CC.Data.Models.DafQuestion> >((string)newValue) ?? new List <CC.Data.Models.DafQuestion>(); var a = from q in questions let oldAnswerId = oldAnswers.Where(f => f.Id == q.Id).Select(f => f.SelectedAnswerId).FirstOrDefault() let newAnswerId = newAnswers.Where(f => f.Id == q.Id).Select(f => f.SelectedAnswerId).FirstOrDefault() where oldAnswerId != newAnswerId let oldAnserText = q.Options.Where(f => f.Id == oldAnswerId).Select(f => f.Text).FirstOrDefault() let newAnserText = q.Options.Where(f => f.Id == newAnswerId).Select(f => f.Text).FirstOrDefault() select getHistoryBase(item, q.Text, oldAnserText, newAnserText); return(a); }
public void RemoveObject(Daf entity) { var d = sdf(DateTime.Now, this.Permissions.User.Id)(entity); if (entity.FunctionalityScoreId.HasValue) { var fs = new FunctionalityScore { Id = entity.FunctionalityScoreId.Value }; db.FunctionalityScores.Attach(fs); db.FunctionalityScores.DeleteObject(fs); } db.DafDeleteds.AddObject(d); db.Dafs.DeleteObject(entity); }
public void ChangeStatus(Daf item, Daf.Statuses newStatus) { var now = DateTime.Now; item.UpdateAt = now; item.UpdatedBy = Permissions.User.Id; switch (newStatus) { case Daf.Statuses.Completed: item.EffectiveDate = now; item.ReviewedAt = now; item.ReviewedBy = this.Permissions.User.Id; item.FunctionalityScore = new FunctionalityScore { ClientId = item.ClientId, DiagnosticScore = item.TotlaScore.Value, StartDate = item.EffectiveDate, UpdatedAt = now, UpdatedBy = item.UpdatedBy.Value, FunctionalityLevelId = db.FunctionalityLevels .Where(f => item.TotlaScore >= f.MinScore && item.TotlaScore <= f.MaxScore) .Select(f => f.Id) .FirstOrDefault() }; break; case Daf.Statuses.EvaluatorSigned: item.SignedAt = now; item.SignedBy = this.Permissions.User.Id; break; } item.Status = newStatus; var entry = db.ObjectStateManager.GetObjectStateEntry(item); foreach (var h in Changeset(entry)) { db.Histories.AddObject(h); } db.SaveChanges(); }
public static async Task ProcessFile(ExecutionContext context, DateTime?dayToProcess = null) { dayToProcess ??= DateTime.Now; var(Masechta, Daf) = StaticData.CalculateDafForDate(dayToProcess.Value); var shiurName = $"{Masechta} {(Daf < 10 ? "0" + Daf : Daf.ToString())}"; var tempFilePath = Path.GetTempPath(); var client = new HttpClient(); /* * FIND SHIUR PAGE HREF */ var baseUrl = "https://www.outorah.org"; var seriesUrl = $"{baseUrl}/series/4033"; var response = client.GetAsync(seriesUrl).ConfigureAwait(false).GetAwaiter().GetResult(); var stringContent = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); var html = new HtmlAgilityPack.HtmlDocument(); html.LoadHtml(stringContent); var elements = html.DocumentNode.SelectNodes("//*[@class='shiur__name']"); var element = elements.First(e => e.InnerText.Contains(shiurName)); var attribute = element.Attributes.First(a => a.Name == "href").Value; /* * FIND VIDEO URL */ response = client.GetAsync($"{baseUrl}{attribute}").ConfigureAwait(false).GetAwaiter().GetResult(); stringContent = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); html.LoadHtml(stringContent); elements = html.DocumentNode.SelectNodes("//script"); var shiur = elements.Where(e => e.Attributes.Any(a => a.Name == "type" && a.Value == "application/ld+json")) .Select(e => System.Text.Json.JsonSerializer.Deserialize <Shiur>(e.InnerHtml)) .FirstOrDefault(e => !string.IsNullOrWhiteSpace(e.contentUrl)); /* * DOWNLOAD VIDEO FILE */ var fileName = $"Daf {Daf} ({dayToProcess.Value.ToString("MMM d yyyy")})"; var videoFilePath = Path.Combine(tempFilePath, $"{fileName}.mp4"); response = client.GetAsync(shiur.contentUrl).ConfigureAwait(false).GetAwaiter().GetResult(); using var content = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult(); using var file = File.Create(videoFilePath); content.CopyToAsync(file).ConfigureAwait(false).GetAwaiter().GetResult(); file.Close(); /* * CONVERT VIDEO FILE TO AUDIO FILE */ var mp3FilePath = Path.Combine(tempFilePath, $"{fileName}.mp3"); var workingDirectory = Path.Combine(context.FunctionAppDirectory, "ffmpeg"); var pathToExecutable = Path.Combine(workingDirectory, "ffmpeg.exe"); var info = new ProcessStartInfo { FileName = pathToExecutable, WorkingDirectory = workingDirectory, Arguments = $"-y -i \"{videoFilePath}\" -codec:a libmp3lame -b:a 32k -vn -ac 1 \"{mp3FilePath}\"", RedirectStandardInput = false, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; using var proc = new Process { StartInfo = info }; proc.Start(); proc.WaitForExit(); /* * UPLOAD FILE TO CLOUD */ var blockBlob = StorageAccount.NewFromConnectionString(Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process)) .CreateCloudBlobClient() .GetContainerReference(StaticData.ShiurimContainerName) .GetBlockBlobReference(Path.Combine("dist/rabbielistefansky/eightminutedaf", Masechta.ToLowerInvariant().Replace(" ", string.Empty), Path.GetFileName(mp3FilePath))); blockBlob.Properties.ContentType = "audio/mpeg"; await blockBlob.UploadFromFileAsync(mp3FilePath).ConfigureAwait(false); File.Delete(videoFilePath); File.Delete(mp3FilePath); }
public void Update(Daf item) { item.CreatedAt = DateTime.Now; item.CreatedBy = Permissions.User.Id; db.SaveChanges(); }
public ActionResult Create(DafCreateModel model, HttpPostedFileBase file) { ViewBag.CurrentUserId = Permissions.User.Id; ModelState.Clear(); var Client = db.Clients.Where(Permissions.ClientsFilter).Select(f => new { f.Id, f.AgencyId, f.FirstName, f.LastName, Culture = f.Agency.AgencyGroup.Culture ?? f.Agency.AgencyGroup.Country.Culture, AgencyName = f.Agency.Name }).FirstOrDefault(f => f.Id == model.ClientId); if (Client == null) { ModelState.AddModelError(string.Empty, Resources.Resource.ClientNotFound); } else { model.AgencyName = Client.AgencyName; model.ClientFirstName = Client.FirstName; model.ClientLastName = Client.LastName; if (User.IsInRole(FixedRoles.DafEvaluator) && Permissions.User.AgencyId != Client.AgencyId) { ModelState.AddModelError(string.Empty, Resources.Resource.NotAllowed); } CC.Web.Attributes.LocalizationAttributeBase.SetCulture(Client.Culture); } var evaluator = Evaluators(Client.AgencyId).FirstOrDefault(f => f.Id == model.EvaluatorId); if (evaluator == null) { ModelState.AddModelError(string.Empty, Resources.Resource.EvaluatorNotFound); } else { model.EvaluatorName = evaluator.FirstName + " " + evaluator.LastName; } if (evaluator != null && Client != null && Client.AgencyId != evaluator.AgencyId) { ModelState.AddModelError(string.Empty, Resources.Resource.AgencyMismatch); } if (User.IsInRole(FixedRoles.DafEvaluator)) { if (model.EvaluatorId != Permissions.User.Id) { if (file == null) { ModelState.AddModelError("FileName", Resources.Resource.FileIsRequired); } if (!model.Disclaimer) { ModelState.AddModelError("Disclaimer", Resources.Resource.DafCreateDisclaimerRequired); } } } if (ModelState.IsValid) { var daf = new Daf() { EvaluatorId = model.EvaluatorId.Value, ClientId = model.ClientId, Disclaimer = model.Disclaimer }; if (file != null) { daf.FileName = file.FileName; } try { using (var tr = new System.Transactions.TransactionScope()) { DafRepository.Add(daf); if (file != null) { SaveFile(daf.Id, file); } tr.Complete(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } if (ModelState.IsValid) { return(RedirectToAction("Details", new { id = daf.Id })); } } return(View(model)); }
private void ShowDateData() { this.Cursor = Cursors.WaitCursor; bool showSeconds = true; Daf dy = DafYomi.GetDafYomi(this._displayingJewishDate); TimeOfDay[] netzshkia = this._dailyZmanim.NetzShkiaAtElevation; TimeOfDay[] netzshkiaMishor = this._dailyZmanim.NetzShkiaMishor; TimeOfDay netz = this._dailyZmanim.NetzAtElevation; TimeOfDay shkia = this._dailyZmanim.ShkiaAtElevation; TimeOfDay netzMishor = this._dailyZmanim.NetzMishor; TimeOfDay shkiaMishor = this._dailyZmanim.ShkiaMishor; TimeOfDay chatzos = this._dailyZmanim.Chatzos; double shaaZmanis = this._dailyZmanim.ShaaZmanis; double shaaZmanis90 = this._dailyZmanim.ShaaZmanisMga; var html = new StringBuilder(); html.AppendFormat("<div class=\"padWidth royalBlue bold\">{0}", this._displayingJewishDate.ToLongDateStringHeb()); html.AppendFormat("<span class=\"sdate\">{0}</span></div>", this._displayingSecularDate.ToString("d", GeneralUtils.SecularDateCultureInfo)); //If the secular day is a day behind as day being displayed is todays date and it is after sunset, //the user may get confused as the secular date for today and tomorrow will be the same. //So we esplain'in it to them... if (this._secularDateAtMidnight.Date != this._displayingSecularDate.Date) { html.Append("<div class=\"padWidth rosyBrown seven italic\">שים לב: תאריך הלועזי מתחיל בשעה 0:00</div>"); } this.DisplayDateDiff(html); html.Append("<br />"); if (this._holidays.Count() > 0) { foreach (SpecialDay h in this._holidays) { html.AppendFormat("<div class=\"padWidth\">{0}", h.NameHebrew); if (h.NameEnglish == "Shabbos Mevarchim") { JewishDate nextMonth = this._displayingJewishDate + 12; html.AppendFormat(" - חודש {0}", JewishCalendar.Utils.GetProperMonthNameHeb(nextMonth.Year, nextMonth.Month)); var molad = Molad.GetMolad(nextMonth.Month, nextMonth.Year); int dim = JewishDateCalculations.DaysInJewishMonth(this._displayingJewishDate.Year, this._displayingJewishDate.Month); int dow = dim - this._displayingJewishDate.Day; if (dim == 30) { dow--; } html.AppendFormat("<div>המולד: {0}</div>", molad.ToStringHeb(this._dailyZmanim.ShkiaAtElevation)); html.AppendFormat("<div>ראש חודש: {0}{1}</div>", JewishCalendar.Utils.JewishDOWNames[dow], (dim == 30 ? ", " + JewishCalendar.Utils.JewishDOWNames[(dow + 1) % 7] : "")); } html.Append("</div>"); if (h.NameEnglish.Contains("Sefiras Ha'omer")) { html.AppendFormat("<div class=\"nine bluoid\">{0}</div>", JewishCalendar.Utils.GetOmerNusach(this._displayingJewishDate.GetDayOfOmer(), Properties.Settings.Default.Nusach)); } if (h.DayType.IsSpecialDayType(SpecialDayTypes.EruvTavshilin)) { html.Append("<div class=\"padWidth crimson bold\">עירוב תבשילין</div>"); } } } html.Append("<table>"); if (shkia != TimeOfDay.NoValue && this._holidays.Any(h => h.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting))) { this.AddLine(html, "הדלקת נרות", (shkia - this._dailyZmanim.Location.CandleLighting).ToString24H(showSeconds), wideDescription: false); html.Append("<tr><td class=\"nobg\" colspan=\"3\"> </td></tr>"); } this.AddLine(html, "פרשת השבוע", string.Join(" ", Sedra.GetSedra(this._displayingJewishDate, this._dailyZmanim.Location.IsInIsrael).Select(i => i.nameHebrew)), wideDescription: false); if (dy != null) { this.AddLine(html, "דף יומי", dy.ToStringHeb(), wideDescription: false); } html.Append("</table><br />"); html.AppendFormat("<div class=\"padBoth lightSteelBlueBG ghostWhite nine bold clear\">זמני היום ב{0}</div>", this._dailyZmanim.Location.NameHebrew); html.Append("<table>"); if (netz == TimeOfDay.NoValue) { this.AddLine(html, "הנץ החמה", "השמש אינו עולה", bold: true, emphasizeValue: true); } else { if (this._displayingJewishDate.Month == 1 && this._displayingJewishDate.Day == 14) { this.AddLine(html, "סו\"ז אכילת חמץ", ((netz - 90) + (int)Math.Floor(shaaZmanis90 * 4D)).ToString24H(showSeconds), bold: true); this.AddLine(html, "סו\"ז שריפת חמץ", ((netz - 90) + (int)Math.Floor(shaaZmanis90 * 5D)).ToString24H(showSeconds), bold: true); html.Append("<br />"); } this.AddLine(html, "עלות השחר - 90", (netzMishor - 90).ToString24H(showSeconds)); this.AddLine(html, "עלות השחר - 72", (netzMishor - 72).ToString24H(showSeconds)); if (netz == netzMishor) { this.AddLine(html, "הנץ החמה", netz.ToString24H(showSeconds), bold: true, emphasizeValue: true); } else { this.AddLine(html, "הנה\"ח <span class=\"reg lightSteelBlue\">...מ " + this._dailyZmanim.Location.Elevation.ToString() + " מטר</span>", netz.ToString24H(showSeconds)); this.AddLine(html, "הנה\"ח <span class=\"reg lightSteelBlue\">...גובה פני הים</span>", netzMishor.ToString24H(showSeconds), bold: true, emphasizeValue: true); } this.AddLine(html, "סוזק\"ש - מג\"א", this._dailyZmanim.GetZman(ZmanType.KShmMga).ToString24H(showSeconds)); this.AddLine(html, "סוזק\"ש - הגר\"א", this._dailyZmanim.GetZman(ZmanType.KshmGra).ToString24H(showSeconds)); this.AddLine(html, "סוז\"ת - מג\"א", this._dailyZmanim.GetZman(ZmanType.TflMga).ToString24H(showSeconds)); this.AddLine(html, "סוז\"ת - הגר\"א", this._dailyZmanim.GetZman(ZmanType.TflGra).ToString24H(showSeconds)); } if (netz != TimeOfDay.NoValue && shkia != TimeOfDay.NoValue) { this.AddLine(html, "חצות היום והלילה", chatzos.ToString24H(showSeconds)); this.AddLine(html, "מנחה גדולה", this._dailyZmanim.GetZman(ZmanType.MinchaG).ToString24H(showSeconds)); this.AddLine(html, "מנחה קטנה", this._dailyZmanim.GetZman(ZmanType.MinchaK).ToString24H(showSeconds)); this.AddLine(html, "פלג המנחה", this._dailyZmanim.GetZman(ZmanType.MinchaPlg).ToString24H(showSeconds)); } if (shkia == TimeOfDay.NoValue) { this.AddLine(html, "שקיעת החמה", "השמש אינו שוקע", bold: true, emphasizeValue: true); } else { if (shkia == shkiaMishor) { this.AddLine(html, "שקיעת החמה", shkia.ToString24H(showSeconds), bold: true, emphasizeValue: true); } else { this.AddLine(html, "שקה\"ח <span class=\"reg lightSteelBlue\">...גובה פני הים</span>", shkiaMishor.ToString24H(showSeconds)); this.AddLine(html, "שקה\"ח <span class=\"reg lightSteelBlue\">...מ " + this._dailyZmanim.Location.Elevation.ToString() + " מטר</span>", shkia.ToString24H(showSeconds), bold: true, emphasizeValue: true); } this.AddLine(html, "צאת הכוכבים 45", (shkia + 45).ToString24H(showSeconds)); this.AddLine(html, "רבינו תם", (shkia + 72).ToString24H(showSeconds)); this.AddLine(html, "72 דקות זמניות", (shkia + (int)(shaaZmanis * 1.2)).ToString24H(showSeconds)); this.AddLine(html, "72 דקות זמניות לחומרה", (shkia + (int)(shaaZmanis90 * 1.2)).ToString24H(showSeconds)); } html.Append("</table>"); this.webBrowser1.DocumentText = Properties.Resources.InfoHTMLHeb .Replace("{{BODY}}", html.ToString()); this.Cursor = Cursors.Default; }