コード例 #1
0
        static public void Registration(string _FirstName, string _LastName, string _PhoneNumber, string _PostalCode, string _City, string _Street, string _HouseNr, string _ApartmentNr)
        {
            try
            {
                using (var context = new LibraryModel())
                {
                    var card = new Card
                    {
                        First_Name      = _FirstName,
                        Last_Name       = _LastName,
                        Phone_Number    = _PhoneNumber,
                        City            = _City,
                        Postal_Code     = _PostalCode,
                        Street          = _Street,
                        House_Number    = _HouseNr,
                        Apartment_Nuber = _ApartmentNr,
                        State           = 1
                    };

                    var fieldsList = UIChecker.RegisterFieldsDictionary(_FirstName, _LastName, _PhoneNumber, _PostalCode, _City, _Street, _HouseNr);
                    if (UIChecker.CheckForEmptyFields(fieldsList))
                    {
                        ErrorMessageBoxEvent(null, new CustomEventArgs {
                            MessageText = UIChecker.GetEmptyFieldsName(fieldsList)
                        });
                        return;
                    }
                    context.Card.Add(card);
                    context.SaveChanges();
                    InfoMessageBoxEvent(null, new CustomEventArgs {
                        MessageText = $"Registration Successful\nNew ID: {card.ID}", Caption = "Success"
                    });
                }
            }
            catch (Exception)
            {
                ErrorMessageBoxEvent(null, new CustomEventArgs {
                    MessageText = "Unknown error occurred", Caption = "ERROR"
                });
            }
        }
コード例 #2
0
        static public void Return(int ID)
        {
            using (var context = new LibraryModel())
            {
                var rented = (from rent in context.Rent
                              where rent.ID == ID
                              select rent).FirstOrDefault();
                if (rented.Return != null)
                {
                    return;
                }
                var state = rented.Copy.Book_State;
                rented.Return = new Return()
                {
                    State_After_Return = state, State_Pre_Return = state, Return_Date = DateTime.Now
                };


                context.SaveChanges();
            }
        }