public async Task <IActionResult> AddOwner(OwnerDto ownerDto)
        {
            var ownerToAdd = new Owner();

            _mapper.Map(ownerDto, ownerToAdd);

            var userIdFromClaims = User.Claims.FirstOrDefault().Value;

            if (Int32.TryParse(userIdFromClaims, out int currentUser))
            {
                ownerToAdd.ModifiedBy = currentUser;
            }
            else
            {
                ownerToAdd.ModifiedBy = 0;
            }

            await AddAddress(ownerToAdd, ownerDto);

            _repo.Add <Owner>(ownerToAdd);

            var ownerAddedSuccess = await _repo.Commit();

            if (!ownerAddedSuccess)
            {
                return(StatusCode(500));
            }

            //add cottage owner entitie(s)

            return(CreatedAtRoute("GetOwnerById", new { id = ownerToAdd.Id }, new { id = ownerToAdd.Id }));
        }
示例#2
0
        public async Task <IActionResult> CreatePendingBooking([FromBody] PendingBookingDto pendingBookingDto)
        {
            var pendingBooking = _mapper.Map <PendingBooking>(pendingBookingDto);

            var userIdFromClaims = User.Claims.FirstOrDefault().Value;

            if (Int32.TryParse(userIdFromClaims, out int currentUser))
            {
                pendingBooking.CreatedBy = currentUser;
            }
            else
            {
                pendingBooking.CreatedBy = 0;
            }
            _repo.Add <PendingBooking>(pendingBooking);

            var pbAddSuccess = await _repo.Commit();

            if (!pbAddSuccess)
            {
                return(StatusCode(500));
            }

            var objectToReturn = new { id = pendingBooking.Id };

            return(Ok(objectToReturn));
        }
        public async Task <IActionResult> AddBookingDaysToCalendar(int id, AddBookingDaysDto allocateDaysDto)
        {
            if (!DatesValid(allocateDaysDto.StartDate, allocateDaysDto.EndDate))
            {
                return(BadRequest("Dates not valid"));
            }

            var cottageToUpdate = await _repo.GetCottageWithCalendar(id);

            if (cottageToUpdate == null)
            {
                return(NotFound());
            }

            var datesToAddList = CreateDatesForAddList(allocateDaysDto.StartDate, allocateDaysDto.EndDate).ToList();

            if (DateAlreadyAllocated(datesToAddList, cottageToUpdate.Calendar))
            {
                return(BadRequest("One or more dates in this range have already been allocated"));
            }

            var userIdFromClaims = User.Claims.FirstOrDefault().Value;
            int currentUser;

            if (!Int32.TryParse(userIdFromClaims, out currentUser))
            {
                currentUser = 0;
            }

            var datesToAdd = NewDatesForCottage(datesToAddList, allocateDaysDto, currentUser);

            datesToAdd.ForEach(d => cottageToUpdate.Calendar.Add(d));

            if (await _repo.Commit())
            {
                var cottageWithUpdatedCalendar = _mapper.Map <CottageDto>(cottageToUpdate);
                return(Ok(cottageWithUpdatedCalendar));
            }
            else
            {
                return(StatusCode(500));
            }
        }
示例#4
0
        public async Task <PendingBooking> AddPaymentIntentToPendingBooking(PendingBooking pendingBooking, decimal amtForStripe)
        {
            StripeConfiguration.ApiKey = _config["Stripe:SecretKey"];

            var paymentIntentService = new PaymentIntentService();

            PaymentIntent intent;

            if (string.IsNullOrEmpty(pendingBooking.StripePaymentIntentId))
            {
                var options = new PaymentIntentCreateOptions
                {
                    Amount             = (long)amtForStripe * 100,
                    Currency           = "gbp",
                    PaymentMethodTypes = new List <string> {
                        "card"
                    }
                };

                intent = await paymentIntentService.CreateAsync(options);

                pendingBooking.StripePaymentIntentId = intent.Id;
                pendingBooking.StripeClientSecret    = intent.ClientSecret;
                pendingBooking.StripeAmount          = (int)intent.Amount / 100;
            }
            else
            {
                var options = new PaymentIntentUpdateOptions
                {
                    Amount = (long)amtForStripe * 100
                };

                intent = await paymentIntentService.UpdateAsync(pendingBooking.StripePaymentIntentId, options);

                pendingBooking.StripeAmount = (int)intent.Amount / 100;
            }

            // commit amended pendingBookings entity
            await _repo.Commit();

            return(pendingBooking);
        }
示例#5
0
        public async Task <Holiday> UpdatesForNewBooking(PendingBooking pendingBooking, PaymentIntent paymentIntent)
        {
            var updatedCottageAndCalendar = await UpdateCottageCalendar(pendingBooking);

            var updatedCustomer = await UpdateCustomer(pendingBooking);

            var holiday = CreateHolidayFromPendingBooking(pendingBooking, updatedCottageAndCalendar, updatedCustomer, paymentIntent);

            if (holiday != null)
            {
                pendingBooking.Status = PendingBookingStatus.HolidayCreated;
            }

            await _repo.Commit();

            return(holiday);
        }
        public async Task <IActionResult> RegisterCustomer(RegisterDto registerDto)
        {
            var user = await _userManager.FindByEmailAsync(registerDto.Email);

            if (user != null)
            {
                return(Conflict("There is already an account with this email"));
            }

            var customer = new Customer()
            {
                FirstName = registerDto.FirstName,
                LastName  = registerDto.LastName
            };

            _repo.Add <Customer>(customer);
            var customerAdded = await _repo.Commit();

            if (!customerAdded)
            {
                return(StatusCode(500));
            }

            user = new User()
            {
                Email    = registerDto.Email,
                UserName = registerDto.Email,
                PersonId = customer.Id
            };

            var result = _userManager.CreateAsync(user, registerDto.Password).Result;

            if (result != IdentityResult.Success)
            {
                return(StatusCode(500));
            }

            var newUser = _userManager.FindByEmailAsync(user.Email).Result;

            _userManager.AddToRolesAsync(newUser, new string[] { "Customer" }).Wait();

            return(Ok());
        }