public void Rent(VideoStoreMemberId memberId, RentalPeriod period) { Apply( new RentedVideoTape( Id, _title.Id, _title.Title, memberId, period.FromDate, period.ToDate)); }
public RentalPeriod MapEFToModel(EF.Models.RentalPeriod data) { var rentalPeriod = new RentalPeriod() { RentalPeriodId = data.RentalPeriodId, Name = data.Name, }; return(rentalPeriod); }
public Response Add(RentalPeriod rentalPeriod) { Response checkadd = CheckToAddOrUpdate(rentalPeriod); if (!checkadd.IsSuccess) { return(checkadd); } Context.RentalPeriod.Add(rentalPeriod); Context.SaveChanges(); return(Response.Succes("Ekleme işlemi başarılı")); }
private Response CheckToAddOrUpdate(RentalPeriod rentalPeriod) { int sameNumberOfRecords = (from b in Context.RentalPeriod where b.Name == rentalPeriod.Name && b.Id != rentalPeriod.Id select b).Count(); if (sameNumberOfRecords > 0) { return(Response.Fail($"{rentalPeriod.Name} kiralama periyodu sistemde zaten kayıtlıdır.")); } return(Response.Success()); }
public Response Add(RentalPeriod rentalPeriod) { var checkResponse = CheckToAddOrUpdate(rentalPeriod); if (!checkResponse.IsSuccess) { return(checkResponse); } Context.RentalPeriod.Add(rentalPeriod); Context.SaveChanges(); return(Response.Success("Kiralama dönemi başarıyla kaydedildi.")); }
public ActionResult Edit(int id, RentalPeriod rentalPeriod) { try { var response = RentalPeriodService.Update(rentalPeriod); ViewBag.Response = response; return(View(rentalPeriod)); } catch { return(View()); } }
public ActionResult Create(RentalPeriod rentalPeriod) { try { var response = RentalPeriodService.Add(rentalPeriod); ViewBag.Response = response; return(View()); } catch { return(View()); } }
public ActionResult Edit(RentalPeriod rent) { try { Response response = rentalPeriodService.Update(rent); ViewBag.Response = response; return(View()); } catch { return(View()); } }
public ActionResult Delete(RentalPeriod rent) { try { Response response = rentalPeriodService.Delete(rent); ViewBag.Response = response; return(RedirectToAction("Index")); } catch { return(RedirectToAction("Index")); } }
public Response Update(RentalPeriod rentalPeriod) { Response checkupdate = CheckToAddOrUpdate(rentalPeriod); if (!checkupdate.IsSuccess) { return(checkupdate); } var updateTo = GetById(rentalPeriod.Id); updateTo.Name = rentalPeriod.Name; Context.SaveChanges(); return(Response.Succes("Güncelleme İşlemi Başarılı")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } RentalPeriod = await _context.RentalPeriods .Include(r => r.Rental).FirstOrDefaultAsync(m => m.ID == id); if (RentalPeriod == null) { return(NotFound()); } return(Page()); }
public Response Update(RentalPeriod rentalPeriod) { var checkResponse = CheckToAddOrUpdate(rentalPeriod); if (!checkResponse.IsSuccess) { return(checkResponse); } var rentalPeriodToUpdate = GetById(rentalPeriod.Id); rentalPeriodToUpdate.Name = rentalPeriod.Name; Context.SaveChanges(); return(Response.Success("Kiralama periyodu başarıyla güncellendi")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } RentalPeriod = await _context.RentalPeriods .Include(r => r.Rental).FirstOrDefaultAsync(m => m.ID == id); if (RentalPeriod == null) { return(NotFound()); } ViewData["RentalID"] = new SelectList(_context.Rentals, "ID", "ID"); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } RentalPeriod = await _context.RentalPeriods.FindAsync(id); if (RentalPeriod != null) { _context.RentalPeriods.Remove(RentalPeriod); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public Response Delete(RentalPeriod rentalPeriod) { Context.RentalPeriod.Remove(rentalPeriod); Context.SaveChanges(); return(Response.Succes("Silme İşlemi Başarılı")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var rentalTimeSpan = Rental.EndAt - Rental.StartAt; var nrRentalPeriods = rentalTimeSpan.Days + 1; var rentalPeriods = new List <RentalPeriod> { }; for (int i = 1; i < nrRentalPeriods; i++) /// loop through full 24hr buckets { var rentalPeriodStart = Rental.StartAt.AddDays(i - 1); var rentalPeriodEnd = Rental.StartAt.AddDays(i).AddSeconds(-1); var rentalPeriodDuration = (decimal)(rentalPeriodEnd - rentalPeriodStart).TotalHours; var pricingCalendarEntries = _context.PricingCalendarEntries.Where(b => b.Date >= rentalPeriodStart.Date && b.Date <= rentalPeriodEnd.Date).ToList(); var rentalPeriodPricingCalendarWindows = new List <RentalPeriodPricingCalendarWindow> { }; var weightedPrice = 0.00m; if (pricingCalendarEntries.Count == 1) { var w = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart, EndAt = rentalPeriodEnd, DurationHours = (decimal)(rentalPeriodEnd - rentalPeriodStart).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries.Find(p => p.Date == rentalPeriodStart.Date).Price }; rentalPeriodPricingCalendarWindows.Add(w); } else { var w1 = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart, EndAt = rentalPeriodStart.Date.AddDays(1).AddSeconds(-1), DurationHours = (decimal)(rentalPeriodStart.Date.AddDays(1).AddSeconds(-1) - rentalPeriodStart).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries.Find(p => p.Date == rentalPeriodStart.Date).Price }; rentalPeriodPricingCalendarWindows.Add(w1); var w2 = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart.Date.AddDays(1), EndAt = rentalPeriodEnd, DurationHours = (decimal)(rentalPeriodEnd - rentalPeriodStart.Date.AddDays(1)).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries.Find(p => p.Date == rentalPeriodEnd.Date).Price }; rentalPeriodPricingCalendarWindows.Add(w2); } foreach (RentalPeriodPricingCalendarWindow window in rentalPeriodPricingCalendarWindows) // Loop over windows within rental period to calculate weighted price { weightedPrice += (window.PricingCalendarEntryPrice * (window.DurationHours / rentalPeriodDuration)); } if (rentalPeriodDuration < Settings.PartialRentalPeriodThresholdInHours) { weightedPrice *= Settings.PartialRentalPeriodPriceFraction; } var p = new RentalPeriod { StartAt = rentalPeriodStart, EndAt = rentalPeriodEnd, DurationHours = rentalPeriodDuration, PartialRentalPeriodThresholdInHours = Settings.PartialRentalPeriodThresholdInHours, PartialRentalPeriodPriceFraction = Settings.PartialRentalPeriodPriceFraction, WeightedPrice = weightedPrice, RentalPeriodPricingCalendarWindows = rentalPeriodPricingCalendarWindows }; rentalPeriods.Add(p); } // check if there's a bucket < 24hrs left if (rentalTimeSpan.Hours != 0 || rentalTimeSpan.Minutes != 0) { var rentalPeriodStart = Rental.StartAt.AddDays(nrRentalPeriods - 1); var rentalPeriodEnd = Rental.StartAt.AddDays(nrRentalPeriods - 1).AddHours(rentalTimeSpan.Hours).AddMinutes(rentalTimeSpan.Minutes).AddSeconds(-1); var rentalPeriodDuration = (decimal)(rentalPeriodEnd - rentalPeriodStart).TotalHours; var rentalPeriodPricingCalendarWindows = new List <RentalPeriodPricingCalendarWindow> { }; var pricingCalendarEntries = _context.PricingCalendarEntries.Where(b => b.Date >= rentalPeriodStart.Date && b.Date <= rentalPeriodEnd.Date).ToList(); var weightedPrice = 0.00m; if (pricingCalendarEntries.Count == 1) { var w = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart, EndAt = rentalPeriodEnd, DurationHours = (decimal)(rentalPeriodEnd - rentalPeriodStart).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries[rentalPeriodPricingCalendarWindows.Count].Price }; rentalPeriodPricingCalendarWindows.Add(w); } else { var w1 = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart, EndAt = rentalPeriodStart.Date.AddDays(1).AddSeconds(-1), DurationHours = (decimal)(rentalPeriodStart.Date.AddDays(1).AddSeconds(-1) - rentalPeriodStart).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries.Find(p => p.Date == rentalPeriodStart.Date).Price }; rentalPeriodPricingCalendarWindows.Add(w1); var w2 = new RentalPeriodPricingCalendarWindow { StartAt = rentalPeriodStart.Date.AddDays(1), EndAt = rentalPeriodEnd, DurationHours = (decimal)(rentalPeriodEnd - rentalPeriodStart.Date.AddDays(1)).TotalHours, PricingCalendarEntryPrice = pricingCalendarEntries.Find(p => p.Date == rentalPeriodEnd.Date).Price }; rentalPeriodPricingCalendarWindows.Add(w2); } var nrOfWindows = rentalPeriodPricingCalendarWindows.Count; foreach (RentalPeriodPricingCalendarWindow window in rentalPeriodPricingCalendarWindows) // Loop over windows within rental period to calculate weighted price { weightedPrice += (window.PricingCalendarEntryPrice * (window.DurationHours / rentalPeriodDuration)); } if (rentalPeriodDuration < Settings.PartialRentalPeriodThresholdInHours) { weightedPrice *= Settings.PartialRentalPeriodPriceFraction; } var p = new RentalPeriod { StartAt = rentalPeriodStart, EndAt = rentalPeriodEnd, DurationHours = rentalPeriodDuration, PartialRentalPeriodThresholdInHours = Settings.PartialRentalPeriodThresholdInHours, PartialRentalPeriodPriceFraction = Settings.PartialRentalPeriodPriceFraction, WeightedPrice = weightedPrice, RentalPeriodPricingCalendarWindows = rentalPeriodPricingCalendarWindows }; rentalPeriods.Add(p); } var basePrice = 0.00m; foreach (RentalPeriod rp in rentalPeriods) { basePrice += rp.WeightedPrice; } basePrice = Math.Round(basePrice * 20) / 20; Rental.BasePrice = basePrice; Rental.RentalPeriods = rentalPeriods; _context.Rentals.Add(Rental); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }