public IDataResult <BookingDto> Add(Entity.Dtos.BookingDto bookingDto) { using (var _connection = new SqlConnection(_databaseContext.ConnectionString)) { _connection.Open(); using (var cmd = _connection.CreateCommand()) { SpInsertBookingParameters(bookingDto, cmd); SqlDataReader dataReader = cmd.ExecuteReader(); dataReader.Read(); var booking = new BookingDto() { Amount = decimal.Parse(dataReader["Amount"].ToString()), BookingDate = DateTime.Parse(dataReader["BookingDate"].ToString()), BookingEndDate = DateTime.Parse(dataReader["BookingEndDate"].ToString()), BookingTime = short.Parse(dataReader["BookingTime"].ToString()), CarId = int.Parse(dataReader["CarId"].ToString()), CustomerId = int.Parse(dataReader["CustomerId"].ToString()), Id = int.Parse(dataReader["Id"].ToString()), CustomerName = dataReader["FullName"].ToString() }; return(new SuccessDataResult <BookingDto>(booking, "Rezervasyon başarıyla kaydedildi.")); } } }
protected void SpInsertBookingParameters(Entity.Dtos.BookingDto bookingDto, SqlCommand cmd) { cmd.CommandText = "spInsertBooking"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CustomerId", bookingDto.CustomerId); cmd.Parameters.AddWithValue("@CarId", bookingDto.CarId); cmd.Parameters.AddWithValue("@BookingDate", bookingDto.BookingDate); cmd.Parameters.AddWithValue("@BookingEndDate", bookingDto.BookingEndDate); }
public IDataResult <BookingDto> Create(Entity.Dtos.BookingDto bookingDto) { var validator = new BookingValidator(); var validateResult = validator.Validate(bookingDto); if (!validateResult.IsValid) { var validationErrors = ValidationHelper.GetErrors(validateResult.Errors); return(new ErrorDataResult <BookingDto>("Rezervasyon ekleme işlemi başarısız oldu.", validationErrors)); } return(_bookingDal.Add(bookingDto)); }