public async Task <IActionResult> OnPostAsync()
        {
            var allCompanyCodeSetting = await _context.AppSettings.FirstOrDefaultAsync(p => p.Code == Constants.AllCompaniesCodeKey);

            if (allCompanyCodeSetting != null)
            {
                allCompanyCodeSetting.Value = ItemVm[0].Code;
                _context.Attach(allCompanyCodeSetting).State = EntityState.Modified;
            }
            else
            {
                var newAllCompSetting = new AppSetting
                {
                    Code  = Constants.AllCompaniesCodeKey,
                    Value = ItemVm[0].Code
                };
                _context.AppSettings.Add(newAllCompSetting);
            }

            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("Settings saved");
                return(RedirectToPage("./AppSettings"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _toastNotification.AddErrorToastMessage(e.Message);
                return(Page());
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(ItemVm).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BuyMaterialsDocumentExists(ItemVm.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index2"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(TransWarehouseDocSeriesDef).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransWarehouseDocSeriesDefExists(TransWarehouseDocSeriesDef.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task OnPostAsync()
        {
            string BaseUrl    = "https://api.exchangeratesapi.io/latest?symbols=USD,BGN";
            var    httpClient = new HttpClient();

            try
            {
                var uri = new Uri(BaseUrl);

                var response = await httpClient.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();

                    var rateResponse = JsonConvert.DeserializeObject <RateResponse>(jsonContent);
                    if (rateResponse != null)
                    {
                        foreach (var rateItem in rateResponse.Rates)
                        {
                            var currencyCode = rateItem.Key;
                            var cur          = await _context.Currencies.FirstOrDefaultAsync(p => p.Code == currencyCode);

                            if (cur != null)
                            {
                                var currencyId = cur.Id;
                                var rateToAdd  = new ExchangeRate
                                {
                                    CurrencyId  = currencyId,
                                    ClosingDate = rateResponse.Date,
                                    Rate        = (decimal)rateItem.Value
                                };
                                var rate = await RateExist(rateToAdd.CurrencyId, rateToAdd.ClosingDate);

                                if (rate == null)
                                {
                                    await _context.ExchangeRates.AddAsync(rateToAdd);
                                }
                                else
                                {
                                    rate.Rate = rateToAdd.Rate;
                                    _context.Attach(rate).State = EntityState.Modified;
                                }
                            }
                        }
                        await _context.SaveChangesAsync();

                        _toastNotification.AddSuccessToastMessage("Update rates finished");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                //throw;
            }
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.TransWarehouseDocSeriesDefs.Add(TransWarehouseDocSeriesDef);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.ClientProfiles.Add(ClientProfile);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.FinTransCategories.Add(FinTransCategory);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.SellDocTypeDefs.Add(SellDocTypeDef);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }

            _context.Companies.Add(Company);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MeasureUnit = await _context.MeasureUnits.FindAsync(id);

            if (MeasureUnit != null)
            {
                _context.MeasureUnits.Remove(MeasureUnit);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ClientProfile = await _context.ClientProfiles.FindAsync(id);

            if (ClientProfile != null)
            {
                _context.ClientProfiles.Remove(ClientProfile);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            WarehouseTransaction = await _context.WarehouseTransactions.FindAsync(id);

            if (WarehouseTransaction != null)
            {
                _context.WarehouseTransactions.Remove(WarehouseTransaction);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ItemVm = await _context.CrCatWarehouseItems.FindAsync(id);

            if (ItemVm != null)
            {
                _context.CrCatWarehouseItems.Remove(ItemVm);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PaymentMethod = await _context.PaymentMethods.FindAsync(id);

            if (PaymentMethod != null)
            {
                _context.PaymentMethods.Remove(PaymentMethod);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #15
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransTransactorDef = await _context.TransTransactorDefs.FindAsync(id);

            if (TransTransactorDef != null)
            {
                _context.TransTransactorDefs.Remove(TransTransactorDef);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FinTransCategory = await _context.FinTransCategories.FindAsync(id);

            if (FinTransCategory != null)
            {
                _context.FinTransCategories.Remove(FinTransCategory);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                string errorSummary = "";

                var modelStateErrors = this.ModelState.Values.SelectMany(m => m.Errors);
                var listOfErrors     = modelStateErrors.ToList();
                foreach (var listOfError in listOfErrors)
                {
                    errorSummary += listOfError.ErrorMessage;
                }
                _toastNotification.AddErrorToastMessage(errorSummary);
                return(Page());
            }

            _context.FiscalPeriods.Add(FiscalPeriod);
            await _context.SaveChangesAsync();

            _toastNotification.AddSuccessToastMessage("Fiscal Period saved!");
            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            // const string sectionCode = "SYS-BUY-MATERIALS-SCN";
            if (id == null)
            {
                return(NotFound());
            }
            // #region Section Management
            //
            // var section = await _context.Sections.SingleOrDefaultAsync(s => s.SystemName == sectionCode);
            // if (section == null)
            // {
            //
            //
            //     return NotFound(new
            //     {
            //         error = "Could not locate section "
            //     });
            // }
            //
            // #endregion
            BuyDocument = await _context.BuyDocuments.FindAsync(id);

            if (BuyDocument != null)
            {
                _context.BuyDocLines.RemoveRange(_context.BuyDocLines.Where(p => p.BuyDocumentId == id));
                _context.TransactorTransactions.RemoveRange(_context.TransactorTransactions.Where(p => p.SectionId == BuyDocument.SectionId && p.CreatorId == id));
                _context.WarehouseTransactions.RemoveRange(_context.WarehouseTransactions.Where(p => p.SectionId == BuyDocument.SectionId && p.CreatorId == id));

                _context.BuyDocuments.Remove(BuyDocument);

                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #19
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCompbos();
                return(Page());
            }

            var diaryTransactionToAttach = _mapper.Map <FinDiaryTransaction>(FinDiaryTransactionVM);

            //diaryTransactionToAttach.Kind = (int)DiaryTransactionsKindEnum.Expence;
            //diaryTransactionToAttach.RevenueCentreId = 1;

            _context.Attach(diaryTransactionToAttach).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FinDiaryTransactionExists(diaryTransactionToAttach.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(RedirectToPage("./Index"));
        }