Пример #1
0
        /// <summary>
        /// Method to edit an existing item from the database.
        /// </summary>
        /// <param name="item">Role</param>
        /// <exception cref="ArgumentException">Thrown if the edit item doesn't exist in the database using the key.</exception>
        public void Edit(Role item)
        {
            Role roleToUpdate = db.Roles.
                                Where(a => a.Id == item.Id).FirstOrDefault();

            if (null == roleToUpdate)
            {
                throw new ArgumentException("Role with ID " + item.Id +
                                            " and role " + item.Name + "is unknown to the database, " +
                                            "Edit operations is unavailable.", "Comment");
            }
            else
            {
                db.Entry(roleToUpdate).CurrentValues.SetValues(item);
            }
            db.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Method to edit an existing item from the database.
        /// </summary>
        /// <param name="item">PostReply</param>
        /// <exception cref="ArgumentException">Thrown if the edit item doesn't exist in the database using the key.</exception>
        public void Edit(PostReply item)
        {
            PostReply postReplyToUpdate = db.PostReplies.
                                          Where(a => a.Id == item.Id).FirstOrDefault();

            if (null == postReplyToUpdate)
            {
                throw new ArgumentException("PostReply with ID " + item.Id +
                                            " and author " + item.Author.Username + "is unknown to the database, " +
                                            "Edit operations is unavailable.", "Comment");
            }
            else
            {
                db.Entry(postReplyToUpdate).CurrentValues.SetValues(item);
            }
            db.SaveChanges();
        }
Пример #3
0
        /// <summary>
        /// Method to edit an existing item from the database.
        /// </summary>
        /// <param name="item">Tag</param>
        /// <exception cref="ArgumentException">Thrown if the edit item doesn't exist in the database using the key.</exception>
        public void Edit(Tag item)
        {
            Tag tagToUpdate = db.Tags.
                              Where(a => a.Id == item.Id).FirstOrDefault();

            if (null == tagToUpdate)
            {
                throw new ArgumentException("Tag with ID " + item.Id +
                                            " and tag " + item.Text + "is unknown to the database, " +
                                            "Edit operations is unavailable.", "Tag");
            }
            else
            {
                db.Entry(tagToUpdate).CurrentValues.SetValues(item);
            }
            db.SaveChanges();
        }
Пример #4
0
        /// <summary>
        /// Method to edit an existing item from the database.
        /// </summary>
        /// <param name="item">User</param>
        /// <exception cref="ArgumentException">Thrown if the edit item doesn't exist in the database using the key.</exception>
        public void Edit(User item)
        {
            User userToUpdate = db.Users.
                                Where(a => a.Id == item.Id).FirstOrDefault();

            if (null == userToUpdate)
            {
                throw new ArgumentException("User with ID " + item.Id +
                                            " and name " + item.Username + "is unknown to the database, " +
                                            "Edit operations is unavailable.", "Comment");
            }
            else
            {
                db.Entry(userToUpdate).CurrentValues.SetValues(item);
            }
            db.SaveChanges();
        }