public async Task <IActionResult> Edit(Guid id, [Bind("ID,Name,UserID,PatternSMSID,Balance,PaymentType")] Wallet wallet)
        {
            if (id != wallet.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(wallet);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WalletExists(wallet.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PatternSMSDropDownList();
            return(View(wallet));
        }
        public async Task <IActionResult> EditPatternSMS(Guid id, [Bind("Id,Value")] PatternSMS patternSMS)
        {
            if (id != patternSMS.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patternSMS);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatternSMSExists(patternSMS.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(PatternSMS)));
            }
            return(View(patternSMS));
        }
Example #3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("ID,Name,Color,Icon")] OperationType operationType)
        {
            if (id != operationType.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(operationType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OperationTypeExists(operationType.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(operationType));
        }
Example #4
0
        public async Task <IActionResult> Edit(Guid id, [Bind("ID,INN,Name,Address,OperationTypeID")] Account account)
        {
            // Account preAcc = _context.Accounts.Where(a => a.ID == id).First();

            if (id != account.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);

                    IEnumerable <Accounting> accountings = _context.Accountings.Where(a => a.AccountId == id);
                    foreach (Accounting accounting in accountings)
                    {
                        if (accounting.OperationTypeID != account.OperationTypeID)
                        {
                            accounting.OperationTypeID = account.OperationTypeID;
                            _context.Update(accounting);
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OperationTypeID"] = new SelectList(_context.OperationType, "ID", "Name", account.OperationTypeID);
            return(View(account));
        }
Example #5
0
        public async Task <IActionResult> AddReciept([Bind("ID,WalletID,FN,FD,FP")] Accounting accounting)
        {
            if (ModelState.IsValid)
            {
                _context.Add(accounting);


                if (accounting.FD != null && accounting.FN != null && accounting.FP != null)
                {
                    NalogData data = new NalogData();
                    string    json = await data.GetReceiptAsinch(accounting.FD, accounting.FN, accounting.FP);

                    accounting.RecieptJSON = json;
                    Receipt rec = ReceiptToClass.FromJson(json).Document.Receipt;
                    IQueryable <Account> accQuery = (from a in _context.Accounts
                                                     where a.INN == Convert.ToInt64(rec.UserInn)
                                                     select a);
                    if (accQuery.Count() > 0)
                    {
                        accounting.Account         = accQuery.First();
                        accounting.OperationTypeID = accQuery.First().OperationTypeID;
                    }
                    else
                    {
                        Account lAcc = new Account()
                        {
                            ID              = new Guid(),
                            INN             = Convert.ToInt64(rec.UserInn),
                            Name            = rec.User,
                            Address         = rec.RetailPlaceAddress,
                            OperationTypeID = _context.OperationType.Where(o => o.Name == "default").Select(o => o.ID).First()
                        };
                        _context.Update(lAcc);
                        accounting.Account         = lAcc;
                        accounting.OperationTypeID = _context.OperationType.Where(o => o.Name == "default").Select(o => o.ID).First();
                    }

                    accounting.Summ = rec.TotalSum / 100;
                    accounting.DateTimeOperation = rec.DateTime.DateTime;
                    accounting.AccountingType    = AccountingTypes.Expense;
                    accounting.Currency          = Currencyes.rub;
                }

                if (accounting.Summ != null && accounting.Summ.Value > 0)
                {
                    decimal sum    = accounting.Summ.Value;
                    Wallet  wallet = (from w in _context.Wallets
                                      where w.ID == accounting.WalletID &&
                                      w.UserID == _userManager.GetUserId(User)
                                      select w).First();
                    if (accounting.AccountingType == 0)
                    {
                        wallet.Balance = wallet.Balance + sum;
                    }
                    else
                    {
                        wallet.Balance = wallet.Balance - sum;
                    }
                    _context.Update(wallet);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(accounting));
        }