public FeedFineModel MapToFeedModelWithPayment(Fine fine, User issuer, User receiver, Payment payment)
        {
            FeedFineModel fineModel = new FeedFineModel {
                Id = fine.Id,
                IssuerId = fine.IssuerId,
                Reason = fine.Reason,
                SeconderId = fine.SeconderId,
                Pending = fine.Pending,
                AwardedDate = fine.AwardedDate,
                IssuerDisplayName = issuer.DisplayName,
                ReceiverDisplayName = receiver.DisplayName,
                ReceiverId = receiver.Id,
                ModifiedDate = fine.ModifiedDate,
                UserImage = receiver.Image,
                Platform = fine.Platform.GetDescription()
            };

            if(payment != null)
            {
                fineModel.PaidDate = payment.PaidDate;
                fineModel.PayerId = payment.PayerId;
                fineModel.PaymentImage = payment.PaymentImage.ImageBytes.ToString();
            }

            return fineModel;
        }
        public FeedFineModel MapPaymentToFeedModel(Payment payment, User issuer, User receiver, int totalPaid)
        {
            string paymentImage = payment.PaymentImage != null
                                  && payment.PaymentImage.ImageBytes != null
                                  && payment.PaymentImage.MimeType != null
                                  ? new StringBuilder("data:").Append(payment.PaymentImage.MimeType)
                                                     .Append(";base64,")
                                                     .Append(System.Convert.ToBase64String(payment.PaymentImage.ImageBytes))
                                                     .ToString()
                                  : null;

            return new FeedFineModel {
                Id = payment.Id,
                IssuerDisplayName = issuer.DisplayName,
                ReceiverDisplayName = receiver.DisplayName,
                PaidDate = payment.PaidDate,
                ModifiedDate = payment.PaidDate,
                PayerId = payment.PayerId,
                PaymentImage = paymentImage,
                AwardedDate = payment.PaidDate,
                UserImage = receiver.Image,
                TotalPaid = totalPaid,
                ReceiverId = receiver.Id,
                LikedBy = payment.LikedBy,
                DislikedBy = payment.DislikedBy,
                IssuerId = issuer.Id,
                Platform = payment.Platform.GetDescription()
            };
        }
        public PayFineResult PayFines(PaymentModel paymentModel)
        {
            PayFineResult payFineResult = this.PerformInitialValidation(paymentModel);

            if (paymentModel == null)
            {
                return payFineResult;
            }

            var user = this.userRepository.Find(new UserSpecification().WithId(paymentModel.RecipientId));
            var payer = this.userRepository.Find(new UserSpecification().WithId(paymentModel.PayerId));

            Payment payment = new Payment(paymentModel.PayerId, paymentModel.Image, "image/png", null);
            payment.Platform = PlatformType.WebFrontEnd;

            var validation = user.PayFines(payment, paymentModel.TotalFinesPaid);
            payFineResult = new PayFineResult(validation);

            if (validation.HasErrors)
            {
                return payFineResult;
            }

            payment = this.paymentRepository.Save(payment);

            this.userRepository.Save(user);

            payFineResult.FeedFineModel = this.fineMapper.MapPaymentToFeedModel(
                payment,
                payer,
                user,
                paymentModel.TotalFinesPaid
                );

            return payFineResult;
        }
        public ValidationResult PayFines(Guid userId, Guid payerId, int number, byte[] image, string mimeType, string fileName)
        {
            var user = this.userRepository.Get(userId);

            Payment payment = new Payment(payerId, image, mimeType, fileName);
            payment.Platform = PlatformType.Slack;

            var result = user.PayFines(payment, number);

            if (result.HasErrors) return result;

            this.paymentRepository.Save(payment);

            this.userRepository.Save(user);

            return result;
        }
Example #5
0
        public ValidationResult PayFines(Payment payment, int number)
        {
            var validationResult = new ValidationResult();

            validationResult.Append(this.CanPayFines(number));

            if(payment.PayerId == this.Id)
            {
                validationResult.AddMessage(Severity.Error, "You cannot pay a fine for yourself!");
            }

            if(validationResult.HasErrors) return validationResult;

            var orderedFines = this.Fines.Where(x => x.Outstanding).OrderBy(x => x.AwardedDate).ToList();

            bool hasPending = orderedFines.All(x => x.Pending);

            if (hasPending)
            {
                return validationResult.AddMessage(Severity.Error, "Payable fines need to be seconded first");
            }

            int limit = number;

            if(orderedFines.Count < number)
            {
                limit = orderedFines.Count;
            }

            for(int i = 0; i < limit; i++)
            {
                orderedFines[i].Pay(payment.Id);
            }

            return validationResult;
        }
 public FineModel MapToModel(Fine fine, Payment payment)
 {
     return new FineModel
            {
                IssuerId = fine.IssuerId,
                Reason = fine.Reason,
                PaymentImageBytes = payment != null ? this.MapPaymentImage(payment.PaymentImage) : null,
                SeconderId = fine.SeconderId,
                Pending = fine.Pending,
                AwardedDate = fine.AwardedDate
            };
 }
 public FineWithUserModel MapToModelWithUser(Fine fine, UserModel shallowUserModel, Payment payment)
 {
     return new FineWithUserModel
     {
         IssuerId = fine.IssuerId,
         Reason = fine.Reason,
         PaymentImageBytes = payment != null ? this.MapPaymentImage(payment.PaymentImage) : null,
         SeconderId = fine.SeconderId,
         Pending = fine.Pending,
         AwardedDate = fine.AwardedDate,
         User = shallowUserModel
     };
 }