Esempio n. 1
0
        /// <summary>
        /// Add the new borrower entry in Database
        /// </summary>
        /// <param name="fname"></param>
        /// <param name="lname"></param>
        /// <param name="address"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public int AddNewBorrwoer(string fname, string lname, string address, string phone, string city, string state)
        {
            tblBORROWER newBorrowerEntry;
            int         cardNumber;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    newBorrowerEntry         = new tblBORROWER();
                    newBorrowerEntry.Fname   = fname.Trim();
                    newBorrowerEntry.Lname   = lname.Trim();
                    newBorrowerEntry.Phone   = phone.Trim();
                    newBorrowerEntry.Address = address.Trim();
                    newBorrowerEntry.State   = state.Trim();
                    newBorrowerEntry.City    = city.Trim();
                    entity.AddTotblBORROWERs(newBorrowerEntry);
                    entity.SaveChanges();

                    cardNumber = (from newBorrower in entity.tblBORROWERs
                                  where newBorrower.Fname == fname.Trim() &&
                                  newBorrower.Lname == lname.Trim() && newBorrower.Address == address
                                  select newBorrower.Card_no).FirstOrDefault();
                }
                return(cardNumber);
            }
            catch (Exception e)
            {
                cardNumber = -1;
                return(cardNumber);
                // Exception In Entity
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update Borrower Information
        /// </summary>
        /// <param name="fname">First Name</param>
        /// <param name="lname">Last Name</param>
        /// <param name="address">Address</param>
        /// <param name="phone">Phone</param>
        /// <param name="newAddress">New Address</param>
        /// <param name="newPhone">New Phone</param>
        /// <returns></returns>
        public bool UpdateBorrower(string fname, string lname, string address, string phone, string newAddress, string newPhone)
        {
            bool        result = true;
            tblBORROWER borrowerInfo;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    borrowerInfo = new tblBORROWER();
                    borrowerInfo = (from borrower in entity.tblBORROWERs where borrower.Fname == fname.Trim() &&
                                    borrower.Lname == lname.Trim() && borrower.Address == address.Trim() select borrower).FirstOrDefault();
                    borrowerInfo.Address = newAddress.Trim();
                    borrowerInfo.Phone   = newPhone.Trim();
                    entity.SaveChanges();
                    result = true;
                }
            }
            catch (Exception e)
            {
                result = false;
                return(result);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Check whether borrower with same entry exists in DB
        /// </summary>
        /// <param name="fname"></param>
        /// <param name="lname"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        public bool IsDuplicateBorrower(string fname, string lname, string address)
        {
            tblBORROWER br;
            bool        result = false;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    br = new tblBORROWER();
                    br = (from borrower in entity.tblBORROWERs
                          where borrower.Fname.ToLower() == fname.ToLower() && borrower.Lname.ToLower() == lname.ToLower() &&
                          borrower.Address.ToLower() == address.ToLower()
                          select borrower).FirstOrDefault();
                    //If borrower Exists in DB
                    if (br != null)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                result = false;
                return(result);
            }
        }