public async Task <IActionResult> CreatePaymentForFlat(int flatId, [FromBody] PaymentDTO paymentDTO, [FromHeader] List <int> userIds)
        {
            Payment payment = _mapper.Map <PaymentDTO, Payment>(paymentDTO);

            await _paymentsRepository.Add(payment);

            List <Payment> payments = await GetAllPaymentsFromFlatId(flatId);

            Flat flat = await _flatRepository.Get(flatId);

            payments.Add(payment);

            flat.Payments = payments;

            await _flatRepository.Update(flat);

            foreach (int userId in userIds)
            {
                User user = await _userRepository.Get(userId);

                UserPayment userPayment = new UserPayment {
                    Payment = payment, User = user, PaymentId = payment.Id, UserId = user.Id
                };

                user.UserPayments.Add(userPayment);

                await _userRepository.Update(user);
            }

            return(Ok(paymentDTO));
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateChoreForFlat([FromBody] ChoreDTO choreDTO)
        {
            ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity;

            int userID = Int16.Parse(identity.FindFirst(ClaimTypes.NameIdentifier).Value);
            var usr    = await _userRepository.Get(userID);

            int?flatId   = usr.FlatId;
            var assignee = await _userRepository.Get(choreDTO.Assignee);

            if (assignee == null)
            {
                return(BadRequest());
            }

            Chore chore = _mapper.Map <ChoreDTO, Chore>(choreDTO);

            chore.AssignedUser = assignee;

            await _choresRepository.Add(chore);

            List <Chore> chores = await GetAllChoresFromFlatId(flatId);

            Flat flat = await _flatRepository.Get(flatId.Value);

            chores.Add(chore);
            flat.Chores = chores;
            await _flatRepository.Update(flat);

            return(Ok());
        }
Esempio n. 3
0
        public async Task <IActionResult> CreatePaymentForFlat([FromBody] PaymentDTO paymentDTO, [FromHeader] List <int> userIds)
        {
            ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity;

            int userID = Int16.Parse(identity.FindFirst(ClaimTypes.NameIdentifier).Value);

            var usr = await _userRepository.Get(userID);

            int?flatId = usr.FlatId;

            Payment payment = _mapper.Map <PaymentDTO, Payment>(paymentDTO);

            await _paymentsRepository.Add(payment);

            List <Payment> payments = await GetAllPaymentsFromFlatId(flatId);

            Flat flat = await _flatRepository.Get(flatId.Value);

            payments.Add(payment);

            flat.Payments = payments;

            await _flatRepository.Update(flat);

            foreach (int userId in userIds)
            {
                User user = await _userRepository.Get(userId);

                UserPayment userPayment = new UserPayment {
                    Payment = payment, User = user, PaymentId = payment.Id, UserId = user.Id
                };

                user.UserPayments.Add(userPayment);

                await _userRepository.Update(user);
            }

            return(Ok(paymentDTO));
        }