public override RequestResponse AddUpdate(SubscriptionV entity) { Validate(entity); if (responseObj.ErrorMessages.Count <= 0) { switch (entity.DaysCount) { case 1: entity.PayAmount = 80; break; case 3: entity.PayAmount = 220; break; case 7: entity.PayAmount = 470; break; case 30: entity.PayAmount = 1350; break; default: entity.PayAmount = 0; break; } if (entity.PromoCodeId > 0 && entity.DaysCount != 30) { decimal promoDiscount = 0; using (PromoCodeRepository promoRepo = new PromoCodeRepository()) { PromoCode promoModel = promoRepo.GetById(entity.PromoCodeId.Value); if (promoModel != null) { promoDiscount = promoModel.Percentage; } } entity.PayAmount = entity.PayAmount - ((entity.PayAmount * promoDiscount) / 100); } if (entity.Id > 0) { Attach(entity); } else { Add(entity); } Save(); responseObj.ReturnedObject = new { id = entity.Id, amount = entity.PayAmount }; responseObj.Messages.Add("succss", OperationLP.SuccessMsg); } return(responseObj); }
public RequestResponse TripRegister(VehicaleReservationModel data) { Trips tripModel = new Trips() { VehicleId = int.Parse(data.vehicleId), RiderId = data.riderId }; switch (data.reservationEnum) { case TripType.Start: // check if v QR found using (VehicleRepository vRepo = new VehicleRepository()) { if (!vRepo.IsAvilableByBarcode(data.qrStr, int.Parse(data.vehicleId))) { responseObj.ErrorMessages.Add("nodata", "QR is wrong"); return(responseObj); } } //if (!data.tripId.HasValue) //{ // responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData); //} //else //{ //tripModel = GetById(data.tripId.Value); tripModel.CreatedDate = DateTime.Now; tripModel.StartTime = DateTime.Now; tripModel.TempRequest = false; responseObj = AddUpdate(tripModel); using (VehicleStatusRepository vsRepo = new VehicleStatusRepository()) { vsRepo.UpdateInRide(int.Parse(data.vehicleId)); } //} break; case TripType.End: if (!data.tripId.HasValue) { responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData); } else { tripModel = GetById(data.tripId.Value); tripModel.EndTime = DateTime.Now; tripModel.IsDone = true; TimeSpan span = DateTime.Parse(tripModel.EndTime.ToString()) - DateTime.Parse(tripModel.StartTime.ToString()); double totalMinutes = span.TotalMinutes; double totalHours = span.TotalHours; double totalSecounds = span.TotalSeconds; //tripModel.Duration = string.Format("{0}:{1}:{2}", totalHours, totalMinutes, totalSecounds); tripModel.Duration = Math.Round(totalMinutes, 2).ToString(); double unloackAmount = double.Parse(System.Configuration.ConfigurationManager.AppSettings["unlockAmount"].ToString()); double minuteAmount = double.Parse(System.Configuration.ConfigurationManager.AppSettings["minuteAmount"].ToString()); decimal totalAmount = Math.Round(decimal.Parse((unloackAmount + (totalMinutes * minuteAmount)).ToString()), 2); tripModel.Amount = totalAmount; if (data.PromoCodeId > 0) { decimal promoDiscount = 0; using (PromoCodeRepository promoRepo = new PromoCodeRepository()) { PromoCode promoModel = promoRepo.GetById(data.PromoCodeId); if (promoModel != null) { promoDiscount = promoModel.Percentage; } } tripModel.NetAmount = totalAmount - ((totalAmount * promoDiscount) / 100); } else { tripModel.NetAmount = totalAmount; } responseObj = AddUpdate(tripModel); using (VehicleStatusRepository vsRepo = new VehicleStatusRepository()) { vsRepo.UpdateInRide(int.Parse(data.vehicleId), false, data.needPrepare); } } break; case TripType.TempRequest: tripModel.CreatedDate = DateTime.Now; tripModel.TempRequest = true; responseObj = AddUpdate(tripModel); break; case TripType.Cancel: if (!data.tripId.HasValue) { responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData); } else { tripModel = GetById(data.tripId.Value); tripModel.IsDone = false; tripModel.IsCancel = true; responseObj = AddUpdate(tripModel); } break; default: break; } return(responseObj); }