public TarifDTO AddTarif(TarifDTO tarifDTO) { var temp = Mapper.Map<Tarif>(tarifDTO); temp.Name = temp.Name.Trim(); if (temp.DistrictId == -1) temp.DistrictId = null; uOW.TarifRepo.Insert(temp); uOW.Save(); return Mapper.Map<TarifDTO>(temp); }
public TarifDTO UpdateTarif(TarifDTO tarif) { var temp = uOW.TarifRepo.Get(u => u.id == tarif.id).First(); if (temp == null) { return null; } /*if (IsAdministratorById(temp.Id)) { return null; }*/ temp.District = tarif.District; temp.DistrictId = tarif.DistrictId==-1? null : tarif.DistrictId; temp.IsIntercity = tarif.IsIntercity; temp.MinimalPrice = tarif.MinimalPrice; temp.Name = tarif.Name; temp.OneMinuteCost = tarif.OneMinuteCost; temp.StartPrice = tarif.StartPrice; temp.WaitingCost = tarif.WaitingCost; uOW.TarifRepo.SetStateModified(temp); uOW.Save(); return Mapper.Map<TarifDTO>(temp); }
public ActionResult Edit(TarifDTO tarif) { tarifManager.UpdateTarif(tarif); return RedirectToAction("Index"); }
/// <summary> /// Calculates price by list of coordinates coordinatesHistory /// </summary> /// <returns>price</returns> public decimal CalcPrice() { if (coordinatesHistory.Count > 1) { int iterator = 0; CoordinatesDTO prevCoordinates; foreach (CoordinatesDTO coordinates in coordinatesHistory) { if (iterator == 0) { iterator++; continue; } prevCoordinates = coordinatesHistory[iterator - 1]; iterator++; // distance (km) distance = GetDistance(prevCoordinates.Latitude, prevCoordinates.Longitude, coordinates.Latitude, coordinates.Longitude); finalDistance += distance; //timePeriod (min) timePeriod = CountOfMinutes(prevCoordinates.AddedTime, coordinates.AddedTime); speed = distance / (timePeriod / 60); // km/h if (currentTatifId != coordinates.TarifId) { currentTarif = tarifes.FirstOrDefault(tarif => tarif.id == coordinates.TarifId); currentTatifId = coordinates.TarifId; } if (speed > WAITINGCOSTSPEED) { currentPrice += (decimal)(timePeriod * (double)currentTarif.OneMinuteCost); } else { currentPrice += (decimal)(timePeriod * (double)currentTarif.WaitingCost); } } return currentPrice; } else { return currentPrice; } }
public ActionResult Create(TarifDTO tarif) { tarifManager.AddTarif(tarif); return RedirectToAction("Index"); }