public async Task <ElasticResponse <T> > MapElasticResults(ISearchResponse <T> result, bool updateData = false) { ISearchResponse <DailyRate> convertedResult = (ISearchResponse <DailyRate>)result; Random random = new Random(); int days = 1; IEnumerable <T> records = convertedResult.Hits.Select(x => { var log = new DailyRate { Id = !updateData ? x.Source.Id : random.Next(), CountryId = x.Source.CountryId, StartDate = updateData ? x.Source.StartDate.AddDays(days) : x.Source.StartDate, EndDate = updateData ? x.Source.EndDate.AddDays(days) : x.Source.EndDate, ErrorCount = x.Source.ErrorCount, OrderCount = x.Source.OrderCount, OrderValue = x.Source.OrderValue, ErrorPercentage = Math.Round((float)x.Source.ErrorCount / x.Source.OrderCount * 100, 2) }; return(log); }).Cast <T>().ToList(); return(await Task.Run(() => new ElasticResponse <T> { TotalRecords = result.Total, Records = records } )); }
public string SpaceListToString() { string result = ID.ToString().PadRight(10) + Name.PadRight(27) + MonthNumberToName(OpenFrom).PadRight(10) + MonthNumberToName(OpenTo).PadRight(10) + DailyRate.ToString("C").PadRight(15) + MaxOccupancy.ToString(); return(result); }
public IEnumerable <T> UpdateDate(IEnumerable <T> listOfResultsToBeModified) { var listOfResultsConverted = (IEnumerable <DailyRate>)listOfResultsToBeModified; IEnumerable <T> results = listOfResultsConverted.Select(x => { var log = new DailyRate { Id = x.Id, CountryId = x.CountryId, StartDate = x.StartDate.AddDays(1), EndDate = x.EndDate.AddDays(1), ErrorCount = x.ErrorCount, OrderCount = x.OrderCount, OrderValue = x.OrderValue, ErrorPercentage = Math.Round((float)x.ErrorCount / x.OrderCount * 100, 2) }; return(log); }).Cast <T>().ToList(); var firstResult = results.OfType <DailyRate>().OrderByDescending(x => x.StartDate).FirstOrDefault(); if (firstResult != null && !(firstResult.StartDate.Day.Equals(DateTime.Now.Day - 1) && firstResult.StartDate.Month.Equals(DateTime.Now.Month) && firstResult.StartDate.Year.Equals(DateTime.Now.Year))) { results = UpdateDate(results); } return(results); }
public string SpaceAvailabilityToString(int reservationDuration) { string result = ID.ToString().PadRight(10) + Name.PadRight(27) + DailyRate.ToString("C").PadRight(20) + MaxOccupancy.ToString().PadRight(15) + IsAccessible.ToString().PadRight(15) + (DailyRate * reservationDuration).ToString("C"); return(result); }
public List <string> GetAttributesList() { List <string> attributes = new List <string>(); attributes.Add(rego); attributes.Add(Make); attributes.Add(Model); attributes.Add(Year.ToString()); attributes.Add(VehClass); attributes.Add(Seats.ToString()); attributes.Add(Transmission); attributes.Add(Fuel); if (gps == true) { attributes.Add("gps"); } attributes.Add(SunRoof.ToString()); if (SunRoof == true) { attributes.Add("sunroof"); } attributes.Add(DailyRate.ToString()); attributes.Add(Colour); return(attributes); }
public async Task <ActionResult> Edit([Bind(include: "ID,Charge")] DailyRate dailyRate) { if (ModelState.IsValid) { _repository.UpdateDailyRate(dailyRate); return(RedirectToAction("Index")); } return(View(dailyRate)); }
public static VehicleDto ToDto(this Vehicle vehicle, DailyRate dailyRate) { return(new VehicleDto { VehicleId = vehicle.VehicleId, Make = vehicle.Make, Model = vehicle.Model, DailyRate = dailyRate.Price }); }
public override int GetHashCode() { var hashCode = -385653790; hashCode = hashCode * -1521134295 + Id.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Brand); hashCode = hashCode * -1521134295 + DailyRate.GetHashCode(); return(hashCode); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var dailyRate = new DailyRate((Price)request.DailyRate.Price); _context.Store(dailyRate); await _context.SaveChangesAsync(cancellationToken); return(new Response() { DailyRate = dailyRate.ToDto() }); }
// GET: DailyRates/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new BadRequestResult()); } DailyRate dailyRate = _repository.GetDailyRateByID((int)id); if (dailyRate == null) { return(new NotFoundResult()); } return(View(dailyRate)); }
/** * AddDateAsync * If the Date is not saved to the database, * it shall save it. * Shall return the object from the table with the given date * <param name="date">The date to be saved</param> **/ public async Task <DailyRate> AddDateAsync(DateTime date) { bool isSaved = IsDateSaved(date); if (!isSaved) { var newDate = new DailyRate() { Date = date.Date }; _context.DailyRate.Add(newDate); await SaveChangesAsync(); return(newDate); } return(await _context.DailyRate.FirstOrDefaultAsync(x => x.Date.Date.Equals(date.Date))); }
} // end of previous method - ToString() // --------------------------------------------------------------------- /// <summary> /// This method should return a list of strings which represent each attribute. Values /// should be made to be unique, e.g.numSeats should not be written as ‘4’ but as ‘4- /// Seater’, sunroof should not be written as ‘True’ but as ‘sunroof’ or with no string /// added if there is no sunroof.Vehicle rego, class, make, model, year, transmission /// type, fuel type, daily rate, and colour can all be assumed to not overlap(i.e. if /// the make ‘Mazda’ exists, ‘Mazda’ will not exist in other attributes e.g.there is /// no model named ‘Mazda’. Similarly, if the colour ‘red’ exists, there is no ‘red’ /// make.You do not need to maintain this restriction, only assume it is true.) /// </summary> public List <string> GetAttributeList() { List <string> attributes = new List <string>(); attributes.Add(VehicleRego); attributes.Add(Make); attributes.Add(Model); attributes.Add(Year.ToString()); attributes.Add(VehicleClass.ToString()); attributes.Add(NumSeats + "-Seater"); attributes.Add(TransmissionType.ToString()); attributes.Add(EngineSize + "-Cylinder"); attributes.Add(Turbo.ToString()); attributes.Add(FuelType.ToString()); attributes.Add(GPS.ToString()); attributes.Add(SunRoof.ToString()); attributes.Add(Colour); attributes.Add(DailyRate.ToString()); return(attributes); } // end of previous method - GetAttributeList()
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var dailyRate = new DailyRate((Price)request.Vehicle.DailyRate); var vehicle = new Vehicle( request.Vehicle.Year, request.Vehicle.Make, request.Vehicle.Model, dailyRate.DailyRateId); _context.Store(dailyRate); _context.Store(vehicle); await _context.SaveChangesAsync(cancellationToken); return(new Response() { Vehicle = vehicle.ToDto(dailyRate) }); }
public void Print() { Console.WriteLine($"Room with: {Name}, Adults {Adults}, Children: {Children}"); DailyRate.Print(); Console.WriteLine(); }
private void btnCreate_Click(object sender, EventArgs e) { try { if (txt999.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt999, "Enter Value."); txt999.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtHallMark.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtHallMark, "Enter Value."); txtHallMark.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtBuyBack.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtBuyBack, "Enter Value."); txtBuyBack.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txt22c.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt22c, "Enter Value."); txt22c.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txt23c.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt23c, "Enter Value."); txt23c.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txt18c.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt18c, "Enter Value."); txt18c.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtSilver.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtSilver, "Enter Value."); txtSilver.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else { if (passedId == 0) { var todaysDate = DateTime.Now.Date; _entities = new MicroAccountsEntities1(); var data = _entities.DailyRates.Where(x => x.date == todaysDate).FirstOrDefault(); if (data == null) { _entities = new MicroAccountsEntities1(); DailyRate rates = new DailyRate(); rates.fineGold = Convert.ToDecimal(txt999.Text); rates.hallmark = Convert.ToDecimal(txtHallMark.Text); rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text); rates.twentyTwoC = Convert.ToDecimal(txt22c.Text); rates.twentyThreeC = Convert.ToDecimal(txt23c.Text); rates.eighteenC = Convert.ToDecimal(txt18c.Text); rates.silver = Convert.ToDecimal(txtSilver.Text); rates.date = DateTime.Now.Date; rates.createdDate = DateTime.Now; rates.updatedDate = DateTime.Now; _entities.DailyRates.Add(rates); _entities.SaveChanges(); MessageBox.Show("Record SuccessFully Added!"); clear(); MainDashboard mm = new MainDashboard(userName); mm.Show(); } else { DialogResult myResult; myResult = MessageBox.Show("Are you really wnat to update the Rates?", "Update Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (myResult == DialogResult.OK) { btnCreate.Text = "Update"; data.fineGold = Convert.ToDecimal(txt999.Text); data.hallmark = Convert.ToDecimal(txtHallMark.Text); data.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text); data.twentyTwoC = Convert.ToDecimal(txt22c.Text); data.twentyThreeC = Convert.ToDecimal(txt23c.Text); data.eighteenC = Convert.ToDecimal(txt18c.Text); data.silver = Convert.ToDecimal(txtSilver.Text); data.date = DateTime.Now.Date; data.createdDate = DateTime.Now; _entities.SaveChanges(); MessageBox.Show("Record SuccessFully Updated!"); clear(); MainDashboard mm = new MainDashboard(userName); mm.Show(); } else { MainDashboard mm = new MainDashboard(userName); mm.Show(); this.Close(); } } } else { btnCreate.Text = "Update"; _entities = new MicroAccountsEntities1(); var rates = _entities.DailyRates.Where(x => x.id == passedId).FirstOrDefault(); rates.fineGold = Convert.ToDecimal(txt999.Text); rates.hallmark = Convert.ToDecimal(txtHallMark.Text); rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text); rates.twentyTwoC = Convert.ToDecimal(txt22c.Text); rates.twentyThreeC = Convert.ToDecimal(txt23c.Text); rates.silver = Convert.ToDecimal(txtSilver.Text); rates.eighteenC = Convert.ToDecimal(txt18c.Text); rates.date = DateTime.Now.Date; rates.createdDate = DateTime.Now; _entities.SaveChanges(); MessageBox.Show("Record SuccessFully Updated!"); clear(); } } } catch (Exception c) { } }
public static DailyRateDto ToDto(this DailyRate dailyRate) { return(new DailyRateDto { }); }
public VehicleBuilder(int year = 2004, string make = "Honda", string model = "Pilot", DailyRate dailyRate = null) { dailyRate ??= new DailyRate((Price)1m); _vehicle = new Vehicle(year, make, model, dailyRate.DailyRateId); }
public string ToCSVString() { string csvString = ""; csvString = csvString + Registration + "," + Grade + "," + Make + "," + Model + "," + Year.ToString() + "," + NumSeats.ToString() + "," + Transmission + "," + Fuel + "," + GPS.ToString() + "," + SunRoof.ToString() + "," + DailyRate.ToString() + "," + Colour + ""; return(csvString); }
public void UpdateDailyRate(DailyRate dailyRate) { _context.DailyRates.Update(dailyRate); _context.SaveChanges(); }
public static void Initialise(ParkingAppContext context) { context.Database.EnsureCreated(); if (!context.FlatParkingRates.Any()) { var flatParkingRates = new FlatParkingRate[] { new FlatParkingRate { Description = "Early Bird", EntryTimeStart = TimeSpan.Parse("06:00"), EntryTimeEnd = TimeSpan.Parse("09:00"), ExitTimeStart = TimeSpan.Parse("15:30"), ExitTimeEnd = TimeSpan.Parse("23:30"), EntryDays = 62, Charge = 13.00m }, new FlatParkingRate { Description = "Night Rate", EntryTimeStart = TimeSpan.Parse("18:00"), EntryTimeEnd = TimeSpan.Parse("1.00:00"), ExitTimeStart = TimeSpan.Parse("18:00"), ExitTimeEnd = TimeSpan.Parse("1.06:00"), EntryDays = 62, Charge = 6.50m }, new FlatParkingRate { Description = "Weekend Rate", EntryTimeStart = TimeSpan.Parse("00:00"), EntryTimeEnd = TimeSpan.Parse("2.00:00"), ExitTimeStart = TimeSpan.Parse("00:00"), ExitTimeEnd = TimeSpan.Parse("2.00:00"), EntryDays = 64, Charge = 10.00m }, new FlatParkingRate { Description = "Weekend Rate", EntryTimeStart = TimeSpan.Parse("00:00"), EntryTimeEnd = TimeSpan.Parse("1.00:00"), ExitTimeStart = TimeSpan.Parse("00:00"), ExitTimeEnd = TimeSpan.Parse("1.00:00"), EntryDays = 1, Charge = 10.00m }, }; foreach (var rate in flatParkingRates) { context.FlatParkingRates.Add(rate); } context.SaveChanges(); } if (!context.HourlyRates.Any()) { var hourlyRates = new HourlyRate[] { new HourlyRate { HourLimit = 1, Charge = 5.00m }, new HourlyRate { HourLimit = 2, Charge = 10.00m }, new HourlyRate { HourLimit = 3, Charge = 15.00m }, }; foreach (var rate in hourlyRates) { context.HourlyRates.Add(rate); } context.SaveChanges(); } if (!context.DailyRates.Any()) { var dailyRate = new DailyRate { Charge = 20.00m }; context.DailyRates.Add(dailyRate); context.SaveChanges(); } }
public async Task SaveNewDay(Dictionary <string, double> rates, DateTime date, DailyRate dailyRate) { foreach (var item in rates) { var currency = await AddCurrencyAsync(item.Key); Composite composite = new Composite() { Currency = currency, DailyRate = dailyRate, Rate = item.Value }; _context.Add(composite); } await SaveChangesAsync(); }
private void btnCreate_Click(object sender, EventArgs e) { try { if (txt999.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt999, "Enter Value."); txt999.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtHallMark.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtHallMark, "Enter Value."); txtHallMark.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtBuyBack.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtBuyBack, "Enter Value."); txtBuyBack.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txt22c.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt22c, "Enter Value."); txt22c.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txt23c.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txt23c, "Enter Value."); txt23c.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else if (txtSilver.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtSilver, "Enter Value."); txtSilver.Focus(); panel3.Visible = true; lblError.Text = "Enter Value."; } else { if (passedId == 0) { _entities = new MicroAccountsEntities1(); DailyRate rates = new DailyRate(); rates.fineGold = Convert.ToDecimal(txt999.Text); rates.hallmark = Convert.ToDecimal(txtHallMark.Text); rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text); rates.twentyTwoC = Convert.ToDecimal(txt22c.Text); rates.twentyThreeC = Convert.ToDecimal(txt23c.Text); rates.silver = Convert.ToDecimal(txtSilver.Text); rates.date = DateTime.Now.Date; rates.createdDate = DateTime.Now; _entities.DailyRates.Add(rates); _entities.SaveChanges(); MessageBox.Show("Record SuccessFully Added!"); clear(); } else { btnCreate.Text = "Update"; _entities = new MicroAccountsEntities1(); var rates = _entities.DailyRates.Where(x => x.id == passedId).FirstOrDefault(); rates.fineGold = Convert.ToDecimal(txt999.Text); rates.hallmark = Convert.ToDecimal(txtHallMark.Text); rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text); rates.twentyTwoC = Convert.ToDecimal(txt22c.Text); rates.twentyThreeC = Convert.ToDecimal(txt23c.Text); rates.silver = Convert.ToDecimal(txtSilver.Text); rates.date = DateTime.Now.Date; rates.createdDate = DateTime.Now; _entities.SaveChanges(); MessageBox.Show("Record SuccessFully Updated!"); clear(); } } } catch (Exception c) { } }
public override string ToString() { return(Id.ToString().PadRight(4) + Name.PadRight(25) + IsAccessible.ToString().PadRight(20) + OpenFrom.PadRight(10) + OpenTo.PadRight(10) + DailyRate.ToString("C").PadRight(15) + MaxOccupancy.ToString().PadRight(10)); }
public void CreateNewDailyRate(DailyRate dailyRate) { _context.DailyRates.Add(dailyRate); _context.SaveChanges(); }