public string CalculateAmount(CheckInInput model) { var amount = 0; var country = _countryRepository.GetCountry().FirstOrDefault(p => p.Id == model.CountryId); var specialDays = _specialDayRepository.GetSpecialDays().Where(p => p.CountryId == model.CountryId).ToList(); for (var date = model.BookCheckIn; model.BookReceived.CompareTo(date) > 0; date = date.AddDays(1.0)) { var findingSpecialDays = specialDays.Where(p => p.SpecialDate.Month == date.Month && p.SpecialDate.Day == date.Day).ToList(); if (findingSpecialDays.Any() || date.DayOfWeek.ToString() == country.OffDay1 || date.DayOfWeek.ToString() == country.OffDay2) { continue; } amount += 5; } return("Your Penalty Amount:" + amount + country.CurrencyCode); }
public string CheckIn([FromBody] CheckInInput input) { //getting the vehicle object according to its input Vehicle vehicle = VehicleFactory.GetVehicle(input.VehicleType, input.LicensePlateID, int.Parse(input.Width) , int.Parse(input.Height), int.Parse(input.Length)); bool rankIsValid = Enum.TryParse(input.TicketType, out TicketRank rank); //validate the rank and vehicle type if (vehicle == null || !rankIsValid) { return(ReturnBadRequest("Invalid Input")); } Driver driver = new Driver(input.Name, input.Phone); CheckInResult ticketInfo = garage.CheckIn(vehicle, rank, driver); return(System.Text.Json.JsonSerializer.Serialize(ticketInfo)); }
public ActionResult Index(CheckInInput model) { var values = ViewData.ModelState.Values; var errorMessage = _validationService.CheckModelHasErrorMessage(values); if (string.IsNullOrEmpty(errorMessage)) { var result = CalculateAmount(model); ViewBag.result = result; } else { ViewData["Error"] = errorMessage; } var countries = _countryRepository.GetCountry(); ViewBag.countryDropDownItems = ReturnCountriesASelectListItems(countries); return(View()); }
public async Task <CheckInOutput> Execute(CheckInInput input) { if (input.IsExisiting) { return(await this.ExecuteAddToExisiting(input)); } else { switch (input.PricingOption) { case PriceOption.CreateNew: return(await this.ExecuteNewPrice(input)); case PriceOption.UseExisting: return(await this.ExecuteExistingPrice(input)); case PriceOption.NoPrice: return(await this.ExecuteNoPrice(input)); default: return(new CheckInOutput(null, false, "Internal Error: Not a Valid Price Option" + Environment.NewLine + "Please Contact Administrator")); } } }
public async Task <CheckInOutput> ExecuteNewPrice(CheckInInput input) { var part = await this._partRepository.GetEntityAsync(e => e.Id == input.PartId); if (part != null) { input.PartInstance.PartId = input.PartId; input.PartInstance.Price = input.Price; input.PartInstance.UpdatePrice(); var instanceEntity = await this._partInstanceRepository.AddAsync(input.PartInstance); if (instanceEntity != null) { PartPrice partPrice = new PartPrice(part, instanceEntity.Price); PriceLog priceLog = new PriceLog(instanceEntity, instanceEntity.Price); await this._partPriceRepository.AddAsync(partPrice); await this._priceLogRepository.AddAsync(priceLog); Transaction transaction = new Transaction(); transaction.SetupCheckIn(instanceEntity, InventoryAction.INCOMING, instanceEntity.LocationId, input.TimeStamp); transaction.SessionId = this._userService.CurrentSessionId.Value; var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == instanceEntity.StockTypeId); if (stockType != null) { if (!stockType.IsDefault) { if (stockType != null) { if (instanceEntity.IsBubbler) { stockType.Quantity += (int)instanceEntity.BubblerParameter.Weight; } else { stockType.Quantity += instanceEntity.Quantity; } await this._categoryRepository.UpdateAsync(stockType); } } else { IndividualAlert alert = new IndividualAlert(); alert.PartInstance = instanceEntity; instanceEntity.IndividualAlert = alert; this._context.Add(alert); } } else { await this._unitOfWork.Undo(); return(new CheckInOutput(null, false, "Error: Could not adjust stock, Please contact administrator")); } var tranEntity = await this._transactionRepository.AddAsync(transaction); var count = await this._unitOfWork.Save(); if (count > 0) { return(new CheckInOutput(instanceEntity, true, "Part Checked In!")); } else { await this._unitOfWork.Undo(); return(new CheckInOutput(null, false, "Error: Check in Failed")); } } else { await this._unitOfWork.Undo(); return(new CheckInOutput(null, false, "Error: Could Not Create Part Instance")); } } else { await this._unitOfWork.Undo(); return(new CheckInOutput(null, false, "Error: Part Not Found")); } }
private async Task <CheckInOutput> ExecuteAddToExisiting(CheckInInput input) { var partInstance = await this._partInstanceRepository.GetEntityAsync(e => e.Id == input.PartInstance.Id); if (partInstance != null) { partInstance.UpdateQuantity(input.Quantity.Value); Transaction transaction = new Transaction(partInstance, InventoryAction.INCOMING, 0, 0, partInstance.CurrentLocation, input.TimeStamp); transaction.Quantity = input.Quantity.Value; transaction.UnitCost = partInstance.UnitCost; transaction.TotalCost = transaction.UnitCost * transaction.Quantity; transaction.SessionId = this._userService.CurrentSessionId.Value; var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockType.Id); if (stockType != null) { if (!stockType.IsDefault) { if (stockType != null) { if (partInstance.IsBubbler) { stockType.Quantity += (int)partInstance.BubblerParameter.Weight; } else { stockType.Quantity += input.Quantity.Value; } await this._categoryRepository.UpdateAsync(stockType); } } else { IndividualAlert alert = new IndividualAlert(); alert.PartInstance = partInstance; partInstance.IndividualAlert = alert; this._context.Add(alert); } } else { await this._unitOfWork.Undo(); return(new CheckInOutput(null, false, "Error: Could not adjust stock, Please contact administrator")); } var instance = await this._partInstanceRepository.UpdateAsync(partInstance); var trans = await this._transactionRepository.AddAsync(transaction); StringBuilder builder = new StringBuilder(); if (instance != null && trans != null) { var val = await this._unitOfWork.Save(); builder.AppendFormat("Success: {0} added to {1}", instance.Name, trans.Quantity); return(new CheckInOutput(instance, true, builder.ToString())); } else { await this._unitOfWork.Undo(); builder.AppendFormat("Error: Check In Failed, Please Contact Admin").AppendLine(); return(new CheckInOutput(instance, false, builder.ToString())); } } else { return(new CheckInOutput(null, false, "Error: Part Instance not found")); } }
public async Task <CheckInOutput> ExecuteStandard(CheckInInput input) { return(await Task.Run(() => new CheckInOutput(null, false, "Error: Not Implemented Yet"))); }