/// <summary> /// Sell your car (ICar) through dealership /// </summary> /// <param name="car"> The car to be sold. </param> /// <returns> true - car passed the CarTester testing , /// false - car was rejected by CarTester testing /// </returns> /// public TestingResult SellSecondHandCar(ICar car, double sellingCost) { IServiceState service = Service.GetInstance(); service.InsertCar(car); service.TestCar(); bool isEligible = service.GetResultsEligible(); if (isEligible) { car.Price = sellingCost; _secondHandCars.Add(car); } var result = new TestingResult() { Passed = service.GetResultsEligible(), ResultOfInvestigation = service.GetResultMessage(), }; service.EjectCar(); return(result); }
public IActionResult ServiceNotAvailable([FromServices] IServiceState serviceState) { if (serviceState.AllowCreate) { return(RedirectToActionPermanent(nameof(Index))); } return(View()); }
private Service() { _states = new Dictionary <EServiceState, IServiceState>(); _states.Add(EServiceState.Empty, new EmptyState(this)); _states.Add(EServiceState.CarInService, new CarInServiceState(this)); _states.Add(EServiceState.CarInTest, new CarInTestState(this)); _states.Add(EServiceState.TestCompleted, new TestCompletedState(this)); _state = _states[EServiceState.Empty]; _tester = new CarTester(); }
public IActionResult Create([FromServices] IServiceState serviceState) { if (serviceState.AllowCreate) { ViewData["SchoolTypes"] = db.SchoolTypes.OrderBy(type => type.Id); ViewData["ProblemTypes"] = db.ProblemTypes.OrderBy(type => type.Id); ViewData["LocationTypes"] = db.LocationTypes.OrderBy(type => type.Id); return(View()); } else { return(RedirectToAction(nameof(ServiceNotAvailable))); } }
public static bool TryToConnect(string endpoint, EState state, out IServiceState target) { target = null; try { ChannelFactory <IServiceState> factory = new ChannelFactory <IServiceState>(endpoint); target = factory.CreateChannel(); target.SetState(state); return(true); } catch (Exception ex) { Console.WriteLine(endpoint + " is not connected!"); return(false); } }
public IActionResult Create(string postername, string posterphone, string posteremail, string posterqq, string posterschool, string problemtype, string problemdetail, string location, string bookdate, string captchaText, string captchaToken, [FromServices] IServiceState serviceState) { if (!serviceState.AllowCreate) { return(RedirectToAction(nameof(ServiceNotAvailable))); } string _postername = postername ?? ""; string _posterphone = posterphone ?? ""; string _posteremail = posteremail ?? ""; string _posterqq = posterqq ?? ""; if (!IsCaptchaValidate(captchaText, captchaToken)) { ViewData["CaptchaError"] = true; ViewData["Name"] = _postername; ViewData["Phone"] = _posterphone; ViewData["Email"] = _posteremail; ViewData["QQ"] = _posterqq; ViewData["ProblemDetail"] = problemdetail; ViewData["School"] = posterschool; ViewData["ProblemType"] = problemtype; ViewData["Location"] = location; ViewData["BookDate"] = bookdate; ViewData["SchoolTypes"] = db.SchoolTypes.OrderBy(type => type.Id); ViewData["ProblemTypes"] = db.ProblemTypes.OrderBy(type => type.Id); ViewData["LocationTypes"] = db.LocationTypes.OrderBy(type => type.Id); return(View()); } DateTime _reservationDate; DateTime now = DateTimeHelper.GetBeijingTime(); SchoolType _schoolType = db.SchoolTypes.FirstOrDefault(item => item.Name == posterschool); ProblemType _problemType = db.ProblemTypes.FirstOrDefault(item => item.Name == problemtype); LocationType _locationType = db.LocationTypes.FirstOrDefault(item => item.Name == location); if (_schoolType != null && _problemType != null && _locationType != null && DateTime.TryParse(bookdate, out _reservationDate) == true) { _reservationDate = new DateTime(_reservationDate.Year, _reservationDate.Month, _reservationDate.Day, 23, 59, 59); ReservationDetail detail = new ReservationDetail() { PosterName = _postername, PosterPhone = _posterphone, PosterEmail = _posteremail, PosterQQ = _posterqq, PosterSchoolType = _schoolType, LocationType = _locationType, ProblemType = _problemType, Detail = problemdetail, ActionDate = now, CreateDate = now, ModifiedDate = now, ReservationDate = _reservationDate, State = ReservationState.NewlyCreated, LastUpdatedLanguage = cultureContext.Culture.Language }; EntityEntry <ReservationDetail> entry = db.ReservationDetails.Add(detail); db.SaveChanges(); smsService.SendCreationSuccessAsync(entry.Entity, cultureContext.Culture); smsService.SendReservationCreatedAsync(entry.Entity); TempData["id"] = entry.Entity.Id.ToString(); TempData["phone"] = entry.Entity.GetShortenPhone(); TempData["showhint"] = true; return(RedirectToAction(nameof(Detail))); } else { } return(View()); }
public void SetState(EServiceState state) { _state = _states[state]; }
public ApplicationServiceState(IServiceState serviceState, IMapperState mapperState) { _serviceState = serviceState; _mapperState = mapperState; }