public Rental CreateFrom(string[] rentalData) { Movie movie = movieRepository.GetByKey(int.Parse(rentalData[0])); int daysRented = int.Parse(rentalData[1]); var rental = new Rental(movie, daysRented); return rental; }
public Dictionary<string, double> GetMoviesWithPrice(Rental[] rentals) { var movies = new Dictionary<string, double>(); foreach (var rental in rentals) { var priceOfMovie = rental.GetPrice(); movies[rental.Movie.Title] = priceOfMovie; } return movies; }
public ActionResult Edit(Rental.Service.domain.FoodModel model, string[] ImgUrl) { if (ImgUrl != null && ImgUrl.Count() > 0) { foreach (var item in ImgUrl) { model.FoodImageInfo.Add(new Service.domain.FoodImageInfoModel { ImgUrl = item }); } } foodSer.Update(model); return RedirectToAction("Index"); }
public void RegularMovie_ReturnsCorrectStatement() { Customer customer2 = new Customer("Sallie"); Movie movie1 = new Movie("Gone with the Wind", Movie.Regular); Rental rental1 = new Rental(movie1, 3); // 3 day rental customer2.AddRental(rental1); string expected = "Rental Record for Sallie\n" + "\tGone with the Wind\t3.5\n" + "Amount owed is 3.5\n" + "You earned 1 frequent renter points"; string statement = customer2.Statement(); Assert.AreEqual(expected, statement); }
public void NewReleaseMovie_ReturnsCorrectStatement() { Customer customer2 = new Customer("Sallie"); Movie movie1 = new Movie("Star Wars", Movie.NewRelease); Rental rental1 = new Rental(movie1, 3); // 3 day rental customer2.AddRental(rental1); string expected = "Rental Record for Sallie\n" + "\tStar Wars\t9.0\n" + "Amount owed is 9.0\n" + "You earned 2 frequent renter points"; string statement = customer2.Statement(); Assert.AreEqual(expected, statement); }
public void ChildrensMovie_ReturnsCorrectStatement() { Customer customer2 = new Customer("Sallie"); Movie movie1 = new Movie("Madagascar", Movie.Childrens); Rental rental1 = new Rental(movie1, 3); // 3 day rental customer2.AddRental(rental1); string expected = "Rental Record for Sallie\n" + "\tMadagascar\t1.5\n" + "Amount owed is 1.5\n" + "You earned 1 frequent renter points"; string statement = customer2.Statement(); Assert.AreEqual(expected, statement); }
public ActionResult Login(Rental.Service.domain.UserModel user) { var md5Pwd = Utility.DataHelper.MD5(user.UserPwd); user.UserPwd = md5Pwd; bool result = userSer.Login(user); if(result) { Session["rental.user"] = "******"; return RedirectToAction("Index", "Admin", new { lang = "zh-CN" }); } ModelState.AddModelError("error", "用户名或密码错误"); return View(); }
public bool Update(Rental.Service.domain.FoodModel service) { var model = _unitOfWork.FoodRepository.Query().FirstOrDefault(s => s.Id == service.Id); if (model != null && service != null) { model.TitleCN = service.TitleCN; model.TitleTW = service.TitleTW; model.TtitleEN = service.TtitleEN; model.ContentEN = service.ContentEN; model.ContentCN = service.ContentCN; model.ContentTW = service.ContentTW; } return _unitOfWork.Commit() > 0; }
public ActionResult Create(Rental.Service.domain.PreferenceModel model, string[] ImgUrl) { if (ImgUrl != null && ImgUrl.Count() > 0) { foreach (var item in ImgUrl) { model.PreferenImageInfo.Add(new Rental.Service.domain.PreferenceImageInfo { ImgUrl = item }); } } preferneceSer.Save(model); return RedirectToAction("Index"); }
public ActionResult Create(Rental.Service.domain.ServiceModel model, string[] ImgUrl) { if (ImgUrl != null && ImgUrl.Count() > 0) { foreach (var item in ImgUrl) { model.ServiceImageInfo.Add(new Rental.Service.domain.ServiceImageInfoModel { ImgUrl = item }); } model.CreateTime = DateTime.Now; } serviceSer.Save(model); return RedirectToAction("Index"); }
public void Init() { if (IsRunInSession) return; // Create movies m_Cinderella = new Movie("Cinderella", PriceCodes.Childrens); m_StarWars = new Movie("Star Wars", PriceCodes.Regular); m_Gladiator = new Movie("Gladiator", PriceCodes.NewRelease); m_BruceAlmighty = new Movie("Bruce Almighty", PriceCodes.NewRelease); // Create rentals m_Rental1 = new Rental(m_Cinderella, 5); m_Rental2 = new Rental(m_StarWars, 5); m_Rental3 = new Rental(m_Gladiator, 5); m_Rental4 = new Rental(m_BruceAlmighty, 365); // Create customers m_MickeyMouse = new Customer("Mickey Mouse"); m_DonaldDuck = new Customer("Donald Duck"); m_BillClinton = new Customer("Bill Clinton"); m_GeorgeBush = new Customer("George Bush"); IsRunInSession = true; }
public static Model.Model.Service ConvertToEFModel(Rental.Service.domain.ServiceModel service) { var model = new Model.Model.Service(); if(service!=null) { model.Id=service.Id; model.TitleTW=service.TitleTW; model.TitleCN = service.TitleCN; model.TtitleEN=service.TtitleEN; model.ContentTW =service.ContentTW; model.ContentEN = service.ContentEN; model.ContentCN = service.ContentCN; if(service.ServiceImageInfo!=null && service.ServiceImageInfo.Count>0) { model.ServiceImageInfo = service.ServiceImageInfo.Select(s=>new Model.Model.ServiceImageInfo{ ImgUrl= s.ImgUrl }).ToList(); } } return model; }
public void ManyMovies_ReturnsCorrectStatement() { Customer customer1 = new Customer("David"); Movie movie1 = new Movie("Madagascar", Movie.Childrens); Rental rental1 = new Rental(movie1, 6); // 6 day rental Movie movie2 = new Movie("Star Wars", Movie.NewRelease); Rental rental2 = new Rental(movie2, 2); // 2 day rental Movie movie3 = new Movie("Gone with the Wind", Movie.Regular); Rental rental3 = new Rental(movie3, 8); // 8 day rental customer1.AddRental(rental1); customer1.AddRental(rental2); customer1.AddRental(rental3); string expected = "Rental Record for David\n" + "\tMadagascar\t6.0\n" + "\tStar Wars\t6.0\n" + "\tGone with the Wind\t11.0\n" + "Amount owed is 23.0\n" + "You earned 4 frequent renter points"; string statement = customer1.Statement(); Assert.AreEqual(expected, statement); }
public IResult Delete(Rental entity) { _rentalDal.Add(entity); return(new SuccessResult(Messages.RentalDeleted)); }
public override string EachRentalString(Rental rental) { return(rental.Movie.Title + "\t" + rental.Charge + "\n"); }
public ActionResult Post(PostRental postRental) { var rental = new Rental(postRental); Context.Rentals.InsertOneAsync(rental); return RedirectToAction("index"); }
public IResult Delete(Rental rental) { _rentalDal.Add(rental); return(new SuccessResult(Messages.Added)); }
public IResult Update(Rental rental) { _rentalDal.Update(rental); return(new SuccessResult()); }
public IResult Update(Rental rental) { _rentalDal.Update(rental); return(new SuccessResult(Messages.SuccessMessage)); }
public ActionResult AproveRent(Rental rent) { rentalRepository.RentalApproval(rent); return(RedirectToAction("ActionList", "Rental")); }
public bool Save(Rental.Service.domain.ServiceModel service) { var model = Rental.Service.convertor.ServiceModelConvertor.ConvertToEFModel(service); _unitOfWork.ServiceRepository.Insert(model); return _unitOfWork.Commit() > 0; }
private void Option4() { Console.WriteLine("Register return:"); int clientId; while (true) { Console.Clear(); Console.Write("Please provide client_id:"); if (!Int32.TryParse(Console.ReadLine(), out clientId)) { continue; } else { break; } } Console.WriteLine("\nClient:"); Client client = Client.GetAll().Where(obj => obj.Id == clientId).FirstOrDefault(); if (client == null) { Console.WriteLine("Client was not found."); } else { Console.WriteLine("{0,40}{1,30}", "Full Name", "Birthday"); Console.WriteLine("{0,40}{1,30}", CropString($"{client.FirstName} {client.LastName}", 35), client.Birthday); } int copyId; while (true) { Console.Write("\nPlease provide copy_id:"); if (!Int32.TryParse(Console.ReadLine(), out copyId)) { continue; } else { break; } } Copy copy = Copy.GetAll().Where(obj => obj.Id == copyId).FirstOrDefault(); if (copy == null) { Console.WriteLine("Copy was not found."); } else { Rental rental = Rental.GetAll().Where(obj => obj.CopyId == copyId && obj.ClientId == clientId).FirstOrDefault(); if (rental == null) { Console.WriteLine("\nRental was not found."); } else if (rental.DateOfReturn != null) { Console.WriteLine("\nRental is already returned."); } else { rental.Return(); Console.WriteLine("\nCopy was successfully returned."); } } while (true) { Console.Write("\n\nPress ESC to go back..."); if (Console.ReadKey().Key == ConsoleKey.Escape) { return; } } }
public ActionResult ReturnCar(Rental rent) { rentalRepository.Return(rent); carRepository.ReturnCar(rent.CarId); return(RedirectToAction("ReturnList", "Rental")); }
private void Option3() { string errorMsg = null; while (true) { Console.Clear(); Console.WriteLine("Creation of a new rental.(write exit to go back)\n"); if (errorMsg != null) { Console.WriteLine("Error: " + errorMsg); } Console.Write("Please write a client_id:"); String clientId = Console.ReadLine(); if (clientId == "exit") { return; } Console.Write("Please write a copy_id:"); String copyId = Console.ReadLine(); if (copyId == "exit") { return; } try { Copy copy = Copy.GetByID(Int32.Parse(copyId)); if (!copy.Available) { throw new Exception("Copy is not available now."); } Rental rental = new Rental(Int32.Parse(copyId), Int32.Parse(clientId), DateTime.Now); rental.InsertAndSave(); copy.Available = false; copy.Save(); } catch (Exception e) { errorMsg = e.Message; continue; } Console.WriteLine("Success! Rental was created!"); break; } while (true) { Console.Write("\n\nPress ESC to go back..."); if (Console.ReadKey().Key == ConsoleKey.Escape) { return; } } }
private void Option2() { int clientId; while (true) { Console.Clear(); Console.Write("In order to see client's rentals please provide client_id:"); if (!Int32.TryParse(Console.ReadLine(), out clientId)) { continue; } else { break; } } Console.WriteLine("\nClient:"); var client = Client.GetAll().FirstOrDefault(obj => obj.Id == clientId); if (client == null) { Console.WriteLine("Client was not found."); } else { Console.WriteLine("{0,40}{1,30}", "Full Name", "Birthday"); Console.WriteLine("{0,40}{1,30}", CropString($"{client.FirstName} {client.LastName}", 35), client.Birthday); IEnumerable <Rental> rentals = Rental.GetAll().Where(obj => obj.ClientId == clientId); Console.WriteLine("\nRentals:"); Console.WriteLine("{0,10}{1,40}{2,30}{3,30}", "Id", "Movie", "Date Of Rental", "Date Of Return"); var resultTable = from c in Copy.GetAll() join r in rentals on c.Id equals r.CopyId join m in Movie.GetAll() on c.MovieId equals m.Id where r.ClientId == clientId select new { CopyId = r.CopyId, MovieTitle = m.Title, DateOfRental = r.DateOfRental, DateOfReturn = r.DateOfReturn }; Console.WriteLine("Active:"); foreach (var r in resultTable) { if (r.DateOfReturn == null) { Console.WriteLine("{0,10}{1,40}{2,30}{3,30}", r.CopyId, CropString(r.MovieTitle, 35), r.DateOfRental, "Pending..."); } } Console.WriteLine("\nPast rentals:"); foreach (var r in resultTable) { if (r.DateOfReturn <= DateTime.Now) { Console.WriteLine("{0,10}{1,40}{2,30}{3,30}", r.CopyId, CropString(r.MovieTitle, 35), r.DateOfRental, r.DateOfReturn); } } } while (true) { Console.Write("\n\nPress ESC to go back..."); if (Console.ReadKey().Key == ConsoleKey.Escape) { return; } } }
public IResult Add(Rental rental) { _rentalDal.Add(rental); return(new SuccessResult(Message.SuccessfullyRented)); }
public ActionResult Edit(Rental.Service.domain.ServiceModel model) { serviceSer.Update(model); return RedirectToAction("Index"); }
public IResult Add(Rental item) { _rentalDal.Add(item); return(new SuccessResult(Messanges.RentalAdded)); }
public bool Update(Rental.Service.domain.ServiceModel service) { var model = _unitOfWork.ServiceRepository.Query().FirstOrDefault(s => s.Id == service.Id); if (model != null && service != null) { model.TitleCN = service.TitleCN; model.TitleTW = service.TitleTW; model.TtitleEN = service.TtitleEN; model.ContentEN = service.ContentEN; model.ContentCN = service.ContentCN; model.ContentTW = service.ContentTW; if (service.ServiceImageInfo != null && service.ServiceImageInfo.Count > 0) { model.ServiceImageInfo.Clear(); model.ServiceImageInfo = service.ServiceImageInfo.Select(s => new Rental.Model.Model.ServiceImageInfo { ImgUrl = s.ImgUrl }).ToList(); ; } } return _unitOfWork.Commit() > 0; }
public IResult Delete(Rental item) { _rentalDal.Delete(item); return(new SuccessResult(Messanges.RentalDeleted)); }
public IResult Delete(Rental rental) { _rentalDal.Delete(rental); return(new SuccessResult("kiralama işlemi silindi")); }
public IResult Update(Rental item) { _rentalDal.Update(item); return(new SuccessResult(Messanges.RentalModified)); }
public IResult Add(Rental rental) { _rentalDal.Add(rental); return(new SuccessResult(Messages.SuccessMessage)); }
public IResult Add(Rental rental) { _rentalDal.Add(rental); return(new SuccessResult()); }
public IResult Delete(Rental rental) { _rentalDal.Delete(rental); return(new SuccesResult(Messages.ObjectDeleted)); }
public Rental Create(Rental entity) { _context.Rentals.Add(entity); return(entity); }
public Rental RentCarToCustomer(string loginEmail, int carId, DateTime rentalDate, DateTime dateDueBack) { if (rentalDate > DateTime.Now) throw new UnableToRentForDateException(string.Format("Cannot rent for date {0} yet.", rentalDate.ToShortDateString())); var carIsRented = IsCarCurrentlyRented(carId); if (carIsRented) throw new CarCurrentlyRentedException(string.Format("Car {0} is already rented.", carId)); var account = accountRepository.GetByLogin(loginEmail); if (account == null) throw new NotFoundException(string.Format("No account found for login '{0}'.", loginEmail)); var rental = new Rental { AccountId = account.AccountId, CarId = carId, DateRented = rentalDate, DateDue = dateDueBack }; return rentalRepository.Add(rental); }
public async Task <IResult> Delete(Rental customer) { await _rentalDal.DeleteAsync(customer); return(new SuccessResult(Messages.RentalDeleted)); }
public void Add(Rental rental) { context.Rentals.Add(rental); }
public IResult Update(Rental rental) { _rentalDal.Update(rental); return(new SuccessResult("kiralama işlemi güncellendi")); }
public override string SingleRentalString(Rental aRental) { return "\t" + aRental.GetMovie().GetTitle() + "\t" + aRental.GetCharge() + "\n"; }
public void Statement_WhenCustomerHaveSingleRental_Shouldpass() { const string customerName = "John Rambo"; const int daysRented = 3; const double expectedTotalAmount = 9; const int expectedFrequentRenterPoints = 2; var movie = new Movie { PriceCode = TypeOfMovie.NewRelease, Title = "Rembo : XX" }; var customerRentals = new Rental[1]; customerRentals[0] = new Rental(movie, daysRented); var customer = new Customer(customerName, new Rental(movie, daysRented)); var statement = new Statement(customer); Assert.True(CheckStatement(statement, GetMoviesWithPrice(customerRentals), customerName, expectedTotalAmount, expectedFrequentRenterPoints)); Assert.True(CheckStringStatement(statement.GetStatement(new StringStatement()), GetMoviesWithPrice(customerRentals), customerName, expectedTotalAmount, expectedFrequentRenterPoints)); Assert.True(CheckJsonStatement(statement.GetStatement(new JsonStatement()), GetMoviesWithPrice(customerRentals), customerName, expectedTotalAmount, expectedFrequentRenterPoints)); }
public void CreateRental(Rental rental) { context.Rentals.Add(rental); }
public void FrequentRenterPointsForRegularMovieRentedFor4Days() { var rental = new Rental(new Movie("Test", 0), 4); Assert.AreEqual(1, rental.FrequentRenterPoints); }
public ActionResult Post(PostRental postRental) { var rental = new Rental(postRental); _rentalRepository.Insert(rental); return RedirectToAction("Index"); }
public IResult Delete(Rental rental) { _rentalDal.Delete(rental); return(new Result(true, Messages.RentalDeleted)); }
public override string SingleRentalString(Rental aRental) { return "<Rental><MovieName>" + aRental.GetMovie().GetTitle() + "</MovieName><CostToRent>" + aRental.GetCharge() + "</CostToRent></Rental>"; }
public IResult Update(Rental rental) { _rentalDal.Update(rental); return(new Result(true, Messages.RentalUpdated)); }
public static void GetCustomerRental(string customerName, Rental[] rentals) { CustomerName = customerName; Rentals = rentals; }
public IResult Delete(Rental rental) { _rentalDal.Delete(rental); return(new SuccessResult()); }
public void Remove(Rental rental) { context.Rentals.Remove(rental); }
public IResult Update(Rental entity) { _rentalDal.Update(entity); return(new SuccessResult(Messages.Updated)); }
public void FrequentRenterPointsForNewMovie() { var rental = new Rental(new Movie("Test", 1), 1); Assert.AreEqual(1, rental.FrequentRenterPoints); }
public static void CreateMovie() { Rental rental = new Rental(movie, days: days); Assert.AreEqual(rental.CalculateDebt(), price * days); }
public IResult Add(Rental rental) { _rentalDal.Add(rental); return(new Result(true, Messages.AddedRental)); }
public void AddRental(Rental arg) { m_Rentals.Add(arg); }