public void AddSalesDetails(SalesDetailsViewModel entity) { var data = new tbl_SalesDetails { SalesDetailsId = entity.salesDetailsId, SalesTypeId = entity.salesTypeId, ProductId = entity.productId, StockId = entity.stockId, CustomerId = entity.customerId, Quantity = entity.quantity, SalesPrice = entity.salesPrice, AmountRecieved = entity.amountRecieved, SuppliedBy = entity.suppliedBy, SalesDate = entity.salesDate, PaymentId = entity.paymentId, BatchNo = reference.ConfirmReferenceNo((int)ReferenceTypesEnum.Invoice, 1), BranchId = entity.branchId }; context.tbl_SalesDetails.Add(data); //context.SaveChanges(); var pay = new PaymentViewModel { batchNo = data.BatchNo, recievedAmount = data.AmountRecieved, actualAmount = data.tbl_Payment.ActualAmount, paymentDate = data.SalesDate, paymentModeId = data.tbl_Payment.PaymentModeId, paymentMode = data.tbl_Payment.tbl_PaymentMode.PaymentMode, transactionStatus = data.tbl_Payment.tbl_TransactionStatus.TransactionStatus, transactionStatusId = data.tbl_Payment.TransactionStatusId, createdBy = data.tbl_Payment.CreatedBy, createdOn = data.tbl_Payment.CreatedOn, }; payment.AddPayments(pay); //return entity; }
public IHttpActionResult CreateJourney([FromBody] JourneyForCreationDto JourneyFromBody, int userId, int carId) { try { if (JourneyFromBody == null) { return(BadRequest()); } var car = _carRepository.GetCarForUser(userId, carId, false); if (car == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var routes = Mapper.Map <IEnumerable <PassengerRoute> >(JourneyFromBody.Routes); if (!_passengerRouteRepository.UsersExistForRoutes(routes)) { return(BadRequest()); } if (_passengerRouteService.SameUserForRoutes(routes)) { return(BadRequest()); } _passengerRouteRepository.SetUsersForRoutes(routes); var journey = Mapper.Map <Journey>(JourneyFromBody); journey.PassengerRoutes.AddRange(routes); _journeyService.GiveTotalPrices(journey, (double)JourneyFromBody.PriceForLiter, car.FuelConsumption100km); var payments = _paymentService.GeneratePayments(journey, userId); _userService.EditUsersPaymentStatistics(payments, userId); //notification service albo repozytorium wysle notyfikacje _journeyRepository.AddJourneyForUserAndCar(userId, carId, journey); _paymentRepository.AddPayments(payments); if (!_appRepository.Commit()) { return(InternalServerError()); } var journeyToReturn = Mapper.Map <JourneyDto>(journey); return(CreatedAtRoute("GetJourneyForUserAndCar", new { userId = userId, id = journey.Id, passengerRoutes = true, carId = carId }, journeyToReturn)); } catch (Exception e) { return(InternalServerError()); } }