示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,MidInit,Suffix,Birthdate,PrimaryPhone,EmailAddress")] AdultMember adultMember)
        {
            if (id != adultMember.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(adultMember);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdultMemberExists(adultMember.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(adultMember));
        }
示例#2
0
        public IActionResult Update(long id, [FromBody] AdultMember member)
        {
            if (member == null || member.Id != id)
            {
                return(BadRequest());
            }

            var uMember = _context.AdultMember.FirstOrDefault(t => t.Id == id);

            if (uMember == null)
            {
                return(NotFound());
            }

            uMember.FirstName    = member.FirstName;
            uMember.MidInit      = member.MidInit;
            uMember.LastName     = member.LastName;
            uMember.Suffix       = member.Suffix;
            uMember.Birthdate    = member.Birthdate;
            uMember.InActive     = member.InActive;
            uMember.InActiveDate = member.InActiveDate;

            _context.AdultMember.Update(uMember);
            _context.SaveChanges();
            return(new NoContentResult());
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,MidInit,Suffix,Birthdate,PrimaryPhone,EmailAddress")] AdultMember adultMember)
        {
            if (ModelState.IsValid)
            {
                _context.Add(adultMember);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(adultMember));
        }
示例#4
0
        public IActionResult Create([FromBody] AdultMember member)
        {
            if (member == null)
            {
                return(BadRequest());
            }

            _context.AdultMember.Add(member);
            _context.SaveChanges();

            return(CreatedAtRoute("GetAdultMember", new { id = member.Id }, member));
        }
示例#5
0
文件: Service.cs 项目: Emtey/BootCamp
 public void AddAdultMember(ref AdultMember member)
 {
     try
     {
         DBInteraction db = new DBInteraction();
         db.AddMember(member);
     }
     catch (LibraryException ex)
     {
         throw new SoapException(ex.Message, ExceptionCodes.AddAdultFailed);
     }
 }
示例#6
0
 /// <summary>
 /// Add an adult member to the DB
 /// </summary>
 /// <param name="member">Adult Member</param>
 public void AddMember(AdultMember member)
 {
     try
     {
         myAccess.AddMember(member);
     }
     catch (LibraryException ex)
     {
         if (ex.LibraryErrorCode == ErrorCode.AddAdultFailed)
         {
             throw new LibraryException(ErrorCode.AddAdultFailed);
         }
         if (ex.LibraryErrorCode == ErrorCode.GenericException)
         {
             throw new LibraryException(ErrorCode.GenericException);
         }
     }
 }
示例#7
0
        /// <summary>
        /// Retrieves a member
        /// </summary>
        /// <param name="isbn">ISBN</param>
        /// <param name="copyNum">Copy Number</param>
        /// <returns>Member object</returns>
        public Member GetMember(Int32 isbn, Int16 copyNum)
        {
            try
            {
                //create Connection object
                using (SqlConnection cn = DBConnect())
                {
                    //create command object
                    using (SqlCommand cmd = cn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "usp_GetMemberByIsbnCopyNum";

                        //load the parameter list
                        cmd.Parameters.Add("@ISBN", SqlDbType.Int).Value         = isbn;
                        cmd.Parameters.Add("@CopyNum", SqlDbType.SmallInt).Value = copyNum;


                        //open connection
                        cn.Open();
                        //execute command
                        SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

                        if (reader.Read())
                        {
                            //check the birth_date field, if its null, then we have an adult.
                            if (reader.IsDBNull(10))
                            {
                                AdultMember member = new AdultMember();
                                member.MemberID  = (Int16)reader["member_no"];
                                member.LastName  = (string)reader["lastname"];
                                member.FirstName = (string)reader["firstname"];
                                if (!reader.IsDBNull(3))
                                {
                                    member.MiddleInitial = (string)reader["middleinitial"];
                                }
                                member.Street  = (string)reader["street"];
                                member.City    = (string)reader["city"];
                                member.State   = (string)reader["state"];
                                member.ZipCode = (string)reader["zip"];
                                if (!reader.IsDBNull(8))
                                {
                                    member.PhoneNumber = (string)reader["phone_no"];
                                }
                                member.ExpirationDate = (DateTime)reader["expr_date"];
                                return(member);
                            }
                            else
                            {
                                JuvenileMember member = new JuvenileMember();
                                member.MemberID  = (Int16)reader["member_no"];
                                member.LastName  = (string)reader["lastname"];
                                member.FirstName = (string)reader["firstname"];
                                if (!reader.IsDBNull(3))
                                {
                                    member.MiddleInitial = (string)reader["middleinitial"];
                                }
                                member.Street  = (string)reader["street"];
                                member.City    = (string)reader["city"];
                                member.State   = (string)reader["state"];
                                member.ZipCode = (string)reader["zip"];
                                if (!reader.IsDBNull(8))
                                {
                                    member.PhoneNumber = (string)reader["phone_no"];
                                }
                                member.ExpirationDate = (DateTime)reader["expr_date"];
                                member.BirthDate      = (DateTime)reader["birth_date"];
                                member.AdultMemberID  = (Int16)reader["adult_member_no"];
                                return(member);
                            }
                        }
                        else
                        {
                            throw new LibraryException(ErrorCode.NoSuchMember, "Member not found");
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new LibraryException(ErrorCode.GenericException, "Error:  Contact Technical Support.", ex);
            }
        }
示例#8
0
        /// <summary>
        /// Adds an adult member
        /// </summary>
        /// <param name="member">Member object</param>
        public void AddMember(AdultMember member)
        {
            try
            {
                //create Connection object
                using (SqlConnection cn = DBConnect())
                {
                    //create command object
                    using (SqlCommand cmd = cn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "usp_AddAdultMember";

                        //add all the fields as parameters to pass into our AddAdultMember
                        cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 15).Value  = member.LastName;
                        cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 15).Value = member.FirstName;
                        if (member.MiddleInitial != null)
                        {
                            cmd.Parameters.Add("@MiddleInitial", SqlDbType.Char, 1).Value = member.MiddleInitial;
                        }
                        else
                        {
                            cmd.Parameters.Add("@MiddleInitial", SqlDbType.Char, 1).Value = DBNull.Value;
                        }
                        cmd.Parameters.Add("@Street", SqlDbType.VarChar, 15).Value = member.Street;
                        cmd.Parameters.Add("@City", SqlDbType.VarChar, 15).Value   = member.City;
                        cmd.Parameters.Add("@State", SqlDbType.Char, 2).Value      = member.State;
                        cmd.Parameters.Add("@Zip", SqlDbType.Char, 10).Value       = member.ZipCode;
                        if (member.PhoneNumber != null)
                        {
                            cmd.Parameters.Add("@PhoneNo", SqlDbType.Char, 13).Value = member.PhoneNumber;
                        }
                        else
                        {
                            cmd.Parameters.Add("@PhoneNo", SqlDbType.Char, 13).Value = DBNull.Value;
                        }
                        //cmd.Parameters.Add("@ExpDte", SqlDbType.DateTime).Value = member.ExpirationDate;
                        cmd.Parameters.Add("@ExpDte", SqlDbType.DateTime).Direction   = ParameterDirection.Output;
                        cmd.Parameters.Add("@memberID", SqlDbType.SmallInt).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@errorCode", SqlDbType.Int).Direction     = ParameterDirection.Output;

                        //open connection
                        cn.Open();
                        //Execute command
                        cmd.ExecuteNonQuery();
                        //get the memberID of the newly added member
                        member.MemberID       = (Int16)cmd.Parameters["@memberID"].Value;
                        member.ExpirationDate = (DateTime)cmd.Parameters["@ExpDte"].Value;
                        int errorCode = (int)cmd.Parameters["@errorCode"].Value;
                        if (errorCode != 0)
                        {
                            throw new LibraryException(ErrorCode.AddAdultFailed, "Error: Add Adult Failed.");
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new LibraryException(ErrorCode.GenericException, "Error:  Contact Technical Support.", ex);
            }
        }