public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransactorType = await _context.TransactorTypes.FirstOrDefaultAsync(m => m.Id == id);

            if (TransactorType == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransactorType = await _context.TransactorTypes.FindAsync(id);

            if (TransactorType != null)
            {
                _context.TransactorTypes.Remove(TransactorType);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #3
0
        private void FillDataTable(string path, TransactorType transactorType)
        {
            if (path == null)
            {
                throw new NullReferenceException(ErrorMessage.PathCannotBeNull);
            }
            else if (!File.Exists(path))
            {
                throw new InvalidOperationException(ErrorMessage.FileDoesntExist);
            }

            IEnumerable <Transactor> transactors = XmlProcess.DeserializeXmlWithTransactorType(path, transactorType);

            foreach (Transactor transactor in transactors)
            {
                this.table.Rows.Add(
                    transactor.No,
                    transactor.Name,
                    transactor.Since,
                    transactor.DueDate,
                    $"{transactor.Amount:f2} {transactor.CurrencyAbbreviation}");
            }
        }
Exemple #4
0
        public static IEnumerable <Transactor> DeserializeXmlWithTransactorType(string path, TransactorType transactorType)
        {
            if (path == null)
            {
                throw new NullReferenceException(ErrorMessage.PathCannotBeNull);
            }
            if (!File.Exists(path))
            {
                throw new InvalidOperationException(ErrorMessage.FileDoesntExist);
            }

            string        xmlText       = File.ReadAllText(path);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(TransactorDTO[]),
                                                            new XmlRootAttribute(XmlRoot));

            TransactorDTO[] transactorDTOs = (TransactorDTO[])xmlSerializer.Deserialize(new StringReader(xmlText));

            // PROPERTIES ARE BEING MATCHED AUTOMATICALLY WHEN THERE IS A CONSTRUCTOR WITH THE PARAMENTERS SAME AS IN THE DTO
            // This is how AutoMapper maps the properties of the DTO on the actual class.
            Transactor[] transactors = Mapper.Map <Transactor[]>(transactorDTOs)
                                       .Where(t => t.TransactorType.ToLower() == transactorType.ToString().ToLower())
                                       .ToArray();

            return(transactors);
        }