Ejemplo n.º 1
0
        /// <summary>
        /// Loads the data in the form
        /// </summary>
        private void CreateOrLoadData()
        {
            // get group
            var userId  = GetUserId();
            var groupId = Convert.ToInt32(Context.Parameters["GroupId"]);
            var group   = GroupService.GetGroup(groupId, userId);

            // get or create the payment
            var paymentId = Context.Parameters["Id"];

            if (paymentId != null)
            {
                // load
                Data       = PaymentService.GetPayment(Convert.ToInt32(paymentId));
                IsEditable = IsDeletable = PaymentService.IsPaymentEditable(userId, Convert.ToInt32(paymentId));
            }
            else
            {
                // create new
                Data = new PaymentData()
                {
                    GroupId     = groupId,
                    CreatedDate = DateTime.Today,
                    Currency    = group.Currency
                };
                IsEditable  = true;
                IsDeletable = false;
            }

            GroupName = group.Name;

            // load payers and debtors
            AllPayers  = PaymentService.GetPayers(groupId, Convert.ToInt32(paymentId));
            AllDebtors = PaymentService.GetDebtors(groupId, Convert.ToInt32(paymentId));
            Recalculate();


            foreach (var row in AllPayers.Where(n => n.Amount > 0))
            {
                AddLoadedUser(row, Payers);
            }
            foreach (var row in AllDebtors.Where(n => n.Amount > 0))
            {
                AddLoadedUser(row, Debtors);
            }


            if (AllPayers.Count > Payers.Count)
            {
                AddRow(Payers);
            }

            if (AllDebtors.Count > Debtors.Count)
            {
                AddRow(Debtors);
            }
        }
Ejemplo n.º 2
0
        public void AddSelectedUser(string name, TransactionRowData row, string context)
        {
            if (context == "payers")
            {
                var user = AllPayers.FirstOrDefault(n => n.Name == name);
                if (user != null)
                {
                    var item = Payers.First(n => n.RowId == row.RowId);
                    item.Name             = user.Name;
                    item.UserId           = user.UserId;
                    item.ImageUrl         = user.ImageUrl;
                    item.Id               = user.Id;
                    item.IsUserboxVisible = true;
                }

                if (AllPayers.Count > Payers.Count)
                {
                    AddRow(Payers);
                }
            }
            else if (context == "debtors")
            {
                var user = AllDebtors.FirstOrDefault(n => n.Name == name);
                if (user != null)
                {
                    var item = Debtors.First(n => n.RowId == row.RowId);
                    item.Name             = user.Name;
                    item.UserId           = user.UserId;
                    item.ImageUrl         = user.ImageUrl;
                    item.Id               = user.Id;
                    item.IsUserboxVisible = true;
                }


                if (AllDebtors.Count > Debtors.Count)
                {
                    AddRow(Debtors);
                }
            }
        }