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

            BookCopy = await _context.BookCopies.FirstOrDefaultAsync(m => m.Id == id);

            if (BookCopy is null)
            {
                return(NotFound());
            }

            var tempStates = BookStates.GetBookStates().Where(s => !_context.BookCopies.Any(x => x.BookId == BookCopy.BookId && x.State == s) || s == BookCopy.State).ToList();

            foreach (var item in tempStates)
            {
                AvailableStates.Add(new SelectListItem {
                    Value = item, Text = item
                });
            }

            return(Page());
        }
Example #2
0
        protected override Exemplar InitEntryByReader(System.Data.SQLite.SQLiteDataReader reader)
        {
            Exemplar exemplar = new Exemplar();

            ulong id = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("id")));

            string   loanPeriodAsString = reader.GetString(reader.GetOrdinal("loanPeriod"));
            DateTime loanPeriod         = new DateTime();

            if (loanPeriodAsString != null || loanPeriodAsString != "")
            {
                loanPeriod = DateTime.Parse(loanPeriodAsString);
            }

            string     stateString = reader.GetString(reader.GetOrdinal("state"));
            BookStates state       = (BookStates)Enum.Parse(typeof(BookStates), stateString, true);

            string signatur   = reader.GetString(reader.GetOrdinal("signatur"));
            ulong  customerId = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("customerID")));
            ulong  bookId     = System.Convert.ToUInt64(reader.GetInt32(reader.GetOrdinal("bookID")));

            exemplar.ExemplarId = id;
            exemplar.LoanPeriod = loanPeriod;
            exemplar.State      = state;
            exemplar.Signatur   = signatur;
            exemplar.BookId     = bookId;

            return(exemplar);
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!_context.Books.Any(x => x.Id == BookCopy.BookId))
            {
                return(Page());
            }

            var copy = _context.BookCopies.FirstOrDefault(x => x.Id == BookCopy.Id);

            if (copy is null)
            {
                return(NotFound());
            }

            if (!BookStates.StateExist(BookCopy.State))
            {
                return(Page());
            }

            copy.State    = BookCopy.State;
            copy.Quantity = BookCopy.Quantity;

            try
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("Edit", new { id = BookCopy.BookId }));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }
        }
Example #4
0
 private void Awake()
 {
     currentstate = BookStates.Button;
 }
Example #5
0
 public static string GetState(BookStates bookState)
 {
     return(States[(int)bookState]);
 }