Beispiel #1
0
        public void CreateOneWalletOperation(int personId, int walletId, int operationCategoryId, decimal balance, string description, DateTime?date)
        {
            CheckArgument.CheckForNull(description, nameof(description));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet wallet = this.UnitOfWork.WalletRepository.GetById(walletId)
                            ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            OperationCategory operationCategory = this.UnitOfWork.OperationCategoryRepository.GetById(operationCategoryId)
                                                  ?? throw new InvalidForeignKeyException(typeof(OperationCategory).Name);

            PersonWallet personWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(personId, walletId)
                                        ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            wallet.Balance = balanceCalculator.CountNewWalletBalance(wallet.Balance, balance, operationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(wallet);

            OperationInfo operationInfo = new OperationInfo()
            {
                Balance = balance, Description = description, Date = date ?? DateTime.Now
            };

            this.UnitOfWork.OperationInfoRepository.Add(operationInfo);

            Operation operation = new Operation()
            {
                OperationCategoryID = operationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = personWallet.ID
            };

            this.GetRepository().Add(operation);
            this.UnitOfWork.SaveChanges();
        }
        public ActionResult Edit([Bind(Include = "MeterID,MeterNo,Meter_Status,BillName,Brand,MeterOwner,Ward,Street,Arrears,Meter_Account_No")] WaterMeter waterMeter, string payout)
        {
            if (ModelState.IsValid)
            {
                string billStatus;
                //Get building owner number
                PersonTable payer = db.PersonTables.Where(v => v.PersonID.Equals(waterMeter.MeterOwner)).First();

                TempData["CheckOutID"] = "ws_CO_DMZ_52859272_19072018112557828";

                //Register Payment
                Payment newPayment = new Payment {
                    PaymentMade = decimal.Parse(payout), PermitType = 5, PaymentDate = DateTime.Now, PersonID = waterMeter.MeterOwner
                };
                db.Payments.Add(newPayment);

                //Update Wallet
                PersonWallet currentWallet = db.PersonWallets.Where(v => v.PersonTable.PersonID.Equals(waterMeter.MeterOwner)).First();
                currentWallet.CurrentAmount = currentWallet.CurrentAmount - decimal.Parse(payout);
                currentWallet.LastUpdate    = DateTime.Now;

                //Update Building data
                waterMeter.Arrears = waterMeter.Arrears - decimal.Parse(payout);
                if (waterMeter.Arrears <= 0)
                {
                    billStatus = "Paid";
                }
                else
                {
                    billStatus = "Unpaid";
                }


                //Update GIS
                Result final = GetWithParams(usename, pasword, waterMeter.Arrears.ToString(), payout, billStatus, waterMeter.MeterNo.ToString());

                if (final.resultCode.Equals("Result Code: 0000"))
                {
                    //Update DB
                    db.Entry(waterMeter).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("MeterPaymentConfirmation", "Intermediate"));
                }
                else
                {
                    return(RedirectToAction("Edit"));
                }



                /*db.Entry(waterMeter).State = EntityState.Modified;
                 * db.SaveChanges();
                 * return RedirectToAction("Index");*/
            }
            ViewBag.MeterOwner = new SelectList(db.PersonTables, "PersonID", "Person_Name", waterMeter.MeterOwner);
            return(View(waterMeter));
        }
Beispiel #3
0
        private void GiveAchievement(AccountGroupPerson accountGroupPerson, Achievement achievement, DateTime awardedOn)
        {
            PersonWallet wallet = accountGroupPerson.Person.Wallets.Single(x => x.AccountGroupId == accountGroupPerson.AccountGroupId);

            wallet.Value += achievement.Value;
            AwardedAchievement award = new AwardedAchievement()
            {
                Achievement   = achievement,
                AchievementId = achievement.Id,
                AwardDate     = awardedOn,
            };

            Context.Add(award);
            Context.SaveChanges();
        }
Beispiel #4
0
        public void CreateWalletByPersonId(int personId, string name, WalletType walletType, decimal balance = 0)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet wallet = new Wallet {
                Name = name, Type = walletType, Balance = balance
            };

            this.GetRepository().Add(wallet);

            PersonWallet personWallet = new PersonWallet {
                WalletID = wallet.ID, PersonID = personId, AccessModifier = AccessModifier.Manage
            };

            this.UnitOfWork.PersonWalletRepository.Add(personWallet);
            this.UnitOfWork.SaveChanges();
        }
Beispiel #5
0
        public void AddUserToWallet(int id, int personId, int familyId, AccessModifier accessModifier)
        {
            Wallet wallet = this.GetRepository().GetById(id)
                            ?? throw new InvalidPrimaryKeyException(typeof(Wallet).Name);

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            if (wallet.FamilyID == null)
            {
                wallet.FamilyID = familyId;
            }
            else if (!this.UnitOfWork.PersonFamilyRepository.IsPersonInFamily(personId, familyId))
            {
                throw new InvalidForeignKeyException(nameof(familyId));
            }

            PersonWallet personWallet = new PersonWallet {
                WalletID = id, PersonID = personId, AccessModifier = accessModifier
            };

            this.UnitOfWork.PersonWalletRepository.Add(personWallet);
            this.UnitOfWork.SaveChanges();
        }
Beispiel #6
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                //Identify IDNumber from Users table
                AspNetUser currentUser = db.AspNetUsers.Where(v => v.Email.Equals(model.Email)).First();
                string     IDNo        = currentUser.IDNumber;

                //Add user to Persons table
                int building = db.PersonTables.Where(v => v.IDNumber.Equals(IDNo)).Count();
                if (building < 1)
                {
                    var newPerson = new PersonTable {
                        Deleted = false, IDNumber = IDNo, PhoneNumber = currentUser.PhoneNumber
                    };
                    var newWallet = new PersonWallet {
                        CurrentAmount = 10000, Email = null, LastUpdate = DateTime.Now, PersonTable = newPerson
                    };
                    db.PersonTables.Add(newPerson);
                    db.PersonWallets.Add(newWallet);
                    db.SaveChanges();
                }
                else
                {
                    PersonTable pt       = db.PersonTables.Where(v => v.IDNumber.Equals(currentUser.IDNumber)).First();
                    long        idPerson = pt.PersonID;
                    int         walenje  = db.PersonWallets.Where(v => v.PersonID == idPerson).ToList().Count();
                    if (walenje < 1)
                    {
                        var newWallet = new PersonWallet {
                            CurrentAmount = 10000, Email = null, LastUpdate = DateTime.Now, PersonTable = pt
                        };
                        db.PersonWallets.Add(newWallet);
                        db.SaveChanges();
                    }
                }

                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Beispiel #7
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, PhoneNumber = model.Phonenumber, IDNumber = model.IDNumber
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //Add user to Persons table
                    int building = db.PersonTables.Where(v => v.IDNumber.Equals(model.IDNumber)).Count();
                    if (building < 1)
                    {
                        var newPerson = new PersonTable {
                            Deleted = false, IDNumber = model.IDNumber, PhoneNumber = model.Phonenumber
                        };
                        var newWallet = new PersonWallet {
                            CurrentAmount = 10000, Email = null, LastUpdate = DateTime.Now, PersonTable = newPerson
                        };
                        db.PersonTables.Add(newPerson);
                        db.PersonWallets.Add(newWallet);
                        db.SaveChanges();
                    }
                    else
                    {
                        PersonTable pt = db.PersonTables.Where(v => v.IDNumber.Equals(model.IDNumber)).First();
                        pt.PhoneNumber = model.Phonenumber;
                        long idPerson = pt.PersonID;
                        int  walenje  = db.PersonWallets.Where(v => v.PersonID == idPerson).Count();
                        if (walenje < 1)
                        {
                            var newWallet = new PersonWallet {
                                CurrentAmount = 10000, Email = null, LastUpdate = DateTime.Now, PersonTable = pt
                            };
                            db.PersonWallets.Add(newWallet);
                            db.SaveChanges();
                        }
                        else
                        {
                            //Just save your own changes
                            db.SaveChanges();
                        }
                    }


                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #8
0
        public void CreateTransaction(int fromPersonId, int fromWalletId, int toPersonId, int toWalletId, decimal balance, string description, DateTime?date)
        {
            CheckArgument.CheckForNull(description, nameof(description));

            Person fromPerson = this.UnitOfWork.PersonRepository.GetById(fromPersonId)
                                ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Person toPerson = this.UnitOfWork.PersonRepository.GetById(toPersonId)
                              ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Wallet fromWallet = this.UnitOfWork.WalletRepository.GetById(fromWalletId)
                                ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            Wallet toWallet = this.UnitOfWork.WalletRepository.GetById(toWalletId)
                              ?? throw new InvalidForeignKeyException(typeof(Wallet).Name);

            PersonWallet fromPersonWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(fromPersonId, fromWalletId)
                                            ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            PersonWallet toPersonWallet = this.UnitOfWork.PersonWalletRepository.GetPersonWalletByPersonAndWallet(toPersonId, toWalletId)
                                          ?? throw new InvalidPropertyException(typeof(PersonWallet).Name);

            OperationCategory fromOperationCategory = this.UnitOfWork.OperationCategoryRepository.GetOperationCategoryByTypeAndName(OperationType.Spending, typeof(Transaction).Name);

            if (fromOperationCategory == null)
            {
                fromOperationCategory = new OperationCategory()
                {
                    Type = OperationType.Spending, Name = typeof(Transaction).Name
                };
                this.UnitOfWork.OperationCategoryRepository.Add(fromOperationCategory);
            }

            OperationCategory toOperationCategory = this.UnitOfWork.OperationCategoryRepository.GetOperationCategoryByTypeAndName(OperationType.Earning, typeof(Transaction).Name);

            if (toOperationCategory == null)
            {
                toOperationCategory = new OperationCategory()
                {
                    Type = OperationType.Earning, Name = typeof(Transaction).Name
                };
                this.UnitOfWork.OperationCategoryRepository.Add(toOperationCategory);
            }

            fromWallet.Balance = balanceCalculator.CountNewWalletBalance(fromWallet.Balance, balance, fromOperationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(fromWallet);

            toWallet.Balance = balanceCalculator.CountNewWalletBalance(toWallet.Balance, balance, toOperationCategory.Type);
            this.UnitOfWork.WalletRepository.Update(toWallet);

            OperationInfo operationInfo = new OperationInfo()
            {
                Balance = balance, Description = description, Date = date ?? DateTime.Now
            };

            this.UnitOfWork.OperationInfoRepository.Add(operationInfo);

            Transaction transaction = new Transaction();

            this.UnitOfWork.TransactionRepository.Add(transaction);

            Operation fromOperation = new Operation()
            {
                OperationCategoryID = fromOperationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = fromPersonWallet.ID, TransactionID = transaction.ID
            };

            this.GetRepository().Add(fromOperation);

            Operation toOperation = new Operation()
            {
                OperationCategoryID = toOperationCategory.ID, OperationInfoID = operationInfo.ID, PersonWalletID = toPersonWallet.ID, TransactionID = transaction.ID
            };

            this.GetRepository().Add(toOperation);
            this.UnitOfWork.SaveChanges();
        }