private YachtTours GenerateYachtTourFromCreateModel(YachtTourCreateModel model) { var cityRespone = _locationRequestService.GetCityNameById(model.CityFid); var countryRespone = _locationRequestService.GetCountryNameById(model.CountryFid); var locationRespone = _locationRequestService.GetLocationNameById(model.CountryFid); var tour = new YachtTours(); //tour.InjectFrom(model); //tour.TourDurationValue = model.TourDurationValue; tour = _mapper.Map <YachtTourCreateModel, YachtTours>(model, tour); //tour.TourDurationUnitResKey = (tour.TourDurationUnitTypeFid > 0) ? "TourDurationUnitResKey" : string.Empty; tour.City = cityRespone.ResponseData ?? string.Empty; tour.Country = countryRespone.ResponseData ?? string.Empty; tour.LocationName = locationRespone.ResponseData ?? string.Empty; var userId = UserContextHelper.UserId; var now = DateTime.Now.Date; tour.UniqueId = UniqueIDHelper.GenarateRandomString(12); tour.Deleted = false; tour.IsActive = false; tour.CreatedDate = now; tour.LastModifiedDate = now; tour.CreatedBy = userId; tour.LastModifiedBy = userId; tour.UniqueId = UniqueIDHelper.GenarateRandomString(12); return(tour); }
public IActionResult CreateYachtTours(YachtTourCreateModel model) { var user = User; var baseresponse = _yachtToursServices.Create(model); if (baseresponse.IsSuccessStatusCode) { return(Ok(baseresponse)); } return(BadRequest()); }
public BaseResponse <string> Create(YachtTourCreateModel model) { using (var transaction = _db.Database.BeginTransaction()) { try { var tour = GenerateYachtTourFromCreateModel(model); if (tour == null) { return(BaseResponse <string> .BadRequest()); } _db.YachtTours.Add(tour); _db.SaveChanges(); var counter = new YachtTourCounters(); counter.YachtTourId = tour.Id; counter.YachtTourUniqueId = UniqueIDHelper.GenarateRandomString(12); counter.TotalViews = 1000; counter.TotalBookings = 100; counter.TotalSuccessBookings = 1000; counter.TotalReviews = 10000; counter.TotalRecommendeds = 100; counter.TotalNotRecommendeds = 1; _db.YachtTourCounters.Add(counter); _db.SaveChanges(); transaction.Commit(); return(BaseResponse <string> .Success(Terminator.Encrypt(tour.Id.ToString()))); } catch (Exception ex) { transaction.Rollback(); return(BaseResponse <string> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } } }